Given an array A of positive integers, find the smallest non-negative integer (i.e. greater than or equal to zero) that can be placed between any two elements of the array such that the sum of elements in the subarray occurring before it, is equal to the sum of elements occurring in the subarray after it, with the newly placed integer included in either of the two subarrays.

**Input:**

The first line of input is an integer T, denoting the number of test cases. For each test case, there are two subsequent lines of input. First line consists of an integer N, size of the integer array. Second line consists of N space separated integers of array A.

**Output:**

For each test case there is only one line of input comprising of three space separated integers. First, the new number that can be inserted. Second, the position (starting from 2 to N-1 , because new number can only be inserted between any two existing elements) where it should be inserted. Third, the subarray in which it is included (1 or 2) to get equal sums. If the smallest integer to be inserted has more than one possible position in the array to get equal sums, print the smallest position out of all possibilities. In case equal sums are obtained without adding any new element, the value of new element will be zero, followed by the position number, and is always included in the first subarray.

**Note: **Position of first element of array should be considered as 1.

**Constraints:**

1<=T<=100

2<=N<=100

0<=A[i]<=50, where i is an integer such that 0<=i

**Example:**

**Input:**

3

6

3 2 1 5 7 8

5

9 5 1 2 0

4

3 2 2 3

**Output:**

4 5 1

1 2 2

0 3 1

**Explanation:**

In the first test case, the smallest possible number that we can insert is 4, at position 5 (i.e. between 5 and 7) as part of first subarray so that the sum of the two subarrays becomes equal as, 3+2+1+5+4=15 and 7+8=15.

Similarly in the second test case, the smallest possible number that we can insert is 1, at position 2 (i.e. between 9 and 5) as part of second subarray in order to get an equal sum of 9.

In the third test case, equal sum of 5 is obtained by adding first two elements and last two elements as separate subarrays without inserting any extra number. Hence, the output is zero (least possible non-negative integer), followed by 3, the position number and as part of first subarray.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Vagesh Verma | 166 |

vamsikrishna55 | 162 |

UrGuru | 150 |

abducodes | 145 |

adithya_99 | 119 |

abducodes | 701 |

harshtyagi36 | 326 |

sandipbhaumik | 291 |

Akhil varma | 267 |

arpit_anshuman | 262 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.