Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be the one qualified, he tells Iahub the following task.

You're given an (1-based) array *a* with *n* elements. Let's define function *f*(*i*, *j*) (1 ≤ *i*, *j* ≤ *n*) as (*i* - *j*)<sup class="upper-index">2</sup> + *g*(*i*, *j*)<sup class="upper-index">2</sup>. Function g is calculated by the following pseudo-code:

Find a value *min*<sub class="lower-index">*i* ≠ *j*</sub>  *f*(*i*, *j*).

Probably by now Iahub already figured out the solution to this problem. Can you?
The first line of input contains a single integer *n* (2 ≤ *n* ≤ 100000). Next line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] ( - 10<sup class="upper-index">4</sup> ≤ *a*[*i*] ≤ 10<sup class="upper-index">4</sup>).
import sys
n = int(input())
A = [int(x) for x in sys.stdin.buffer.read().split()]

cumsum = [0]
for a in A:
    cumsum.append(a + cumsum[-1])

import math

def main(besta, i, limer, limer2, cumsumi):
    for j in range(i+1, min(n,i - 1 + limer)+1):
        if cumsum[j] < limer2 and (j-i)**2 + (cumsum[j] - cumsumi)**2 < besta:
            besta = (j-i)**2 + (cumsum[j] - cumsumi)**2
    return besta

besta = 10100**2
for i in range(1,n):
    limer = 1 + int(math.sqrt(besta))
    limer2 = limer + cumsum[i]
    besta = main(besta, i, limer, limer2, cumsum[i])
print besta