Suki's Balanced Bench
Suki has found a long garden bench with n treats lying along it in a row, numbered 1 to n from left to right. Each treat has a value a_i; some are tasty (positive), some are the vegetables she'd rather not eat (negative), and some are crumbs worth 0. Suki wants to hop up and sit on one of the treats so that everything to her left is worth exactly as much as everything to her right. The treat she sits on counts for neither side, and a side with no treats on it is worth 0.
Find the leftmost position where Suki can sit: the smallest i such that a_1 + … + a_(i−1) = a_(i+1) + … + a_n.
Input
The first line contains n (1 ≤ n ≤ 2·10^5), the number of treats.
The second line contains n integers a_1, a_2, …, a_n (−10^9 ≤ a_i ≤ 10^9), the values of the treats from left to right.
Output
Print the smallest position i (1 ≤ i ≤ n) where the two sides are worth the same, or -1 if there is no such position.
Notes
In the first example, sitting on treat 4 leaves 4 − 2 + 5 = 7 on her left and 3 + 0 + 4 = 7 on her right.
In the second example, sitting on treat 1 leaves nothing (worth 0) on her left and 4 + 0 − 4 + 0 = 0 on her right. Treat 5 would also work, but 1 is further left.
In the third example each side is worth 2·10^9, which does not fit in a 32-bit integer. Sums can reach 2·10^14 in absolute value, so use 64-bit integers.
In the fourth example no position works.