#K93062. Find the Pivot Index

    ID: 38336 Type: Default 1000ms 256MiB

Find the Pivot Index

Find the Pivot Index

Given an array of integers, find the pivot index where the sum of the numbers to the left of the index is equal to the sum of the numbers to the right of the index. If no such index exists, return -1. In case multiple pivot indexes exist, return the smallest index.

The pivot index is defined mathematically as the index i satisfying:

\(\sum_{j=0}^{i-1} a_j = \sum_{j=i+1}^{n-1} a_j\)

For an empty array, output -1. Note that for a single-element array, the pivot index is 0.

inputFormat

The input is read from stdin and consists of two lines:

  1. The first line contains an integer N representing the number of elements in the array.
  2. The second line contains N space-separated integers representing the elements of the array.

outputFormat

Output a single integer to stdout which is the pivot index of the array. If no pivot index exists, output -1.

## sample
6
1 7 3 6 5 6
3