Processing math: 100%
Minimum distance - MarisaOJ: Marisa Online Judge

Minimum distance

Time limit: 1000 ms
Memory limit: 256 MB

There are $n$ houses equidistantly placed on a circle. House $1$ is between house $n$ and house $2$, house $2$ is between house $1$ and house $3$ and so on. The distance between house $i$ and $j$ is $dis(i, j) = min(|i - j|, n - |i - j|)$.

There are $A_i$ friends living in house $i$. Every day you want to visit each friend once, so choose your house wisely to minimize your daily travel distance.

Mathematically speaking, choose your house $x$ so that: $$\sum_{i = 1}^{n}dis(i, x) \times A_i$$ is minimum.

Input

  • The first line contains an integer $n$.
  • The second line contains $n$ integers $A_i$.

Output

  • Prine 1 integers is the minimum distance.

Constraints

  • $1 \le n \le 10^5$.
  • $0 \le A_i \le 10^5$.

Example

Input:

3
1 0 2

Output:

1