Cutting the Tape

No attempts yetTime limit1sMemory limit128 MB

Problem

Someone found a long tape at home and wrote a row of integers on it. Now they want to cut the tape at a single point, splitting it into two pieces, so that the difference between the sum of the numbers on one piece and the sum on the other piece is as close to 00 as possible. Each piece must contain at least one number. Find the minimum possible absolute value of that difference.

Input

The first line contains the count of numbers on the tape, nn (2n1062 \le n \le 10^6). The second line contains the nn integers aia_i (103ai103-10^3 \le a_i \le 10^3) written on the tape, in order.

Output

Print, on a single line, the minimum absolute value of the difference between the sums of the two pieces.

Hint

For example, if the sequence is 1,2,3,4,5,61, 2, 3, 4, 5, 6, cutting after the fourth number splits it into 1,2,3,41, 2, 3, 4 and 5,65, 6, and the absolute value of the difference of the two sums is (1+2+3+4)(5+6)=1|(1 + 2 + 3 + 4) - (5 + 6)| = 1.