Problems > Equilibrium Index

Equilibrium Index

Difficulty: 1200 2000 ms 128 MB

prefix-sums

Find the smallest index i whose left part sum equals its right part sum (element i excluded from both). Print the 1-based index, or −1.

Input: the first line has N; the second line has N integers.

Output: the smallest equilibrium index (1-based), or −1.

Constraints:

  • 1 ≤ N ≤ 105
  • −104 ≤ ai ≤ 104

Sample Tests

Input 1
5
1 3 5 2 2
Output 1
3
Input 2
1
9
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.