# Little Chef and Sums Codechef Solution

Little Chef and Sums Codechef Solution: Our little chef is fond of doing additions/sums in his free time. Today, he has an arrayÂ AÂ consisting ofÂ NÂ positive integers and he will compute prefix and suffix sums over this array.

He first defines two functionsÂ prefixSum(i)Â andÂ suffixSum(i)Â for the array as follows. The functionÂ prefixSum(i)Â denotes the sum of firstÂ iÂ numbers of the array. Similarly, he definesÂ suffixSum(i)Â as the sum of lastÂ N â€“ i + 1Â numbers of the array.

Little Chef is interested in finding the minimum indexÂ iÂ for which the valueÂ prefixSum(i) + suffixSum(i)Â is the minimum. In other words, first you should minimize the value ofÂ prefixSum(i) + suffixSum(i), and then find the least indexÂ iÂ for which this value is attained.

Since, he is very busy preparing the dishes for the guests, can you help him solve this problem?

### Input

The first line of the input contains an integerÂ TÂ denoting the number of test cases.

The first line of each test case contains a single integerÂ NÂ denoting the number of integers in the arrayÂ A.

The second line containsÂ NÂ space-separated integersÂ A1,Â A2, â€¦,Â ANÂ denoting the arrayÂ A.

### Output

For each test case, output a single line containing the answer.

### Constraints

• 1Â â‰¤Â TÂ â‰¤Â 10
• 1Â â‰¤Â N, A[i]Â â‰¤Â 105

• Subtask #1 : (20 points)Â 1 â‰¤ N â‰¤ 100
• Subtask #2 : (80 points)Â Original constraints

```2
3
1 2 3
4
2 1 3 1
```

```1
2
```

### Explanation

Example case 1.Â Letâ€™s calculate prefixSum(i) + suffixSum(i) for all indexesÂ iÂ in the sample case.

```prefixSum(1) + suffixSum(1) = 1 + 6 = 7
prefixSum(2) + suffixSum(2) = 3 + 5 = 8
prefixSum(3) + suffixSum(3) = 6 + 3 = 9
```

The minimum value of the function is 7, which is attained at index 1, so the answer would be 1.

Example case 2.Â Letâ€™s calculate prefixSum(i) + suffixSum(i) for all indexesÂ iÂ in the sample case.

```prefixSum(1) + suffixSum(1) = 2 + 7 = 9
prefixSum(2) + suffixSum(2) = 3 + 5 = 8
prefixSum(3) + suffixSum(3) = 6 + 4 = 10
prefixSum(4) + suffixSum(4) = 7 + 1 = 8
```

The minimum value of the function is 8, which is achieved for indices 2 and 4. The minimum of these two indices 2, 4 is index 2. Hence, the answer will be 2.

## Little Chef and Sums â€“ CodeChef Solution in JAVA

```import java.util.Scanner;
class Little_Chef_and_Sums {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
while (t-- > 0) {
int n = input.nextInt();
int arr[] = new int[n];
int min = Integer.MAX_VALUE;
int index = -1;
for (int i = 0; i < n; i++) {
arr[i] = input.nextInt();
if (arr[i] < min) {
min = arr[i];
index = i;
}
}
System.out.println(index + 1);
}
input.close();
}
}
```

## Little Chef and Sums â€“ CodeChef Solution in CPP

```#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#include<algorithm>
using namespace std;
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
ll arr[n];
for(ll i=1;i<=n;i++)
cin>>arr[i];
ll prevsum[n];
ll aftersum[n];
ll prefsum=0,sufsum=0;
for(ll i=1;i<=n;i++)
{
prefsum+=arr[i];
sufsum+=arr[n-i+1];
prevsum[i]=prefsum;
aftersum[i]=sufsum;
}
//Indexing is one for now
ll minof=INTMAX_MAX,minindex=0;
for(ll i=1;i<=n;i++)
{
if(prevsum[i]+aftersum[n-i+1]<minof)
{  minof=prevsum[i]+aftersum[n-i+1];
minindex=i;
}
}
cout<<minindex<<endl;
}
return 0;
}```

## Little Chef and Sums -CodeChef Solution in Python

```from sys import stdin
def main():