Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/massiv-teng-yigindili-bolinish

Split into equal sums

Easy 1000 ms 64 MB 33%
Share

An array of $n$ integers is given. Find the smallest $k$ ($1 \le k \lt n$) such that the sum of the first $k$ elements is equal to the sum of the remaining elements. If there is no such $k$, print $-1$.

The array split into two parts; the sums of both parts are equal

Input

The first line contains a positive integer $n$.
The second line contains $n$ integers — the elements of the array.

Output

One integer — $k$ or $-1$.

Note

$1 \le n \le 1001$
the elements are from $-10^{6}$ to $10^{6}$

Examples

Input #1
6
4 1 5 3 2 5
Output #1
3
Input #2
3
1 2 4
Output #2
-1

Sign in to submit a solution

Signing up is free and takes a minute.