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.

bhatabhi554 | 317 |

hardikJain5 | 306 |

CodeBuddy | 293 |

Akkki111 | 233 |

clone | 230 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

mazumderrohit8 | 1176 |

RemoveTLE | 1144 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4605 |

Quandray | 4444 |

Login to report an issue on this page.