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
sys.setrecursionlimit(1000000)

class splitData():
    def __init__(self, position, value):
        self.position = position
        self.value = value

def classifyData(individual_1, individual_2):
    return min(individual_1, individual_2)
 
def computeFitness(individual_i, individual_j):
    return (individual_i.position - individual_j.position)**2 + (individual_i.value - individual_j.value)**2
 
def bruteForce(features, left, right):
    min_distance = max_int
    for i in range(left, right):
        for j in range(i+1, right):
            min_distance = classifyData(min_distance,
                                        computeFitness(features[i], features[j]))
    return min_distance
 
def selectIndividual(features, left, right, mid, min_distance):
    selected_population = []
    for i in range(left, right):
        if (features[i].position - features[mid].position) ** 2 <= min_distance:
            selected_population.append(features[i])
    return selected_population
 
def enhanceData(features, left, right, mid, min_distance):
    selected_population = selectIndividual(features, left, right, mid, min_distance)
 
    l = len(selected_population)
    result = max_int
    for i in range(l):
        for j in range(i+1, l):
            #optimizeLoop
            if (selected_population[i].value - selected_population[j].value) ** 2 >= min_distance:
                break
 
            distance = computeFitness(selected_population[i], 
                                      selected_population[j])
            result = classifyData(result, distance)
    return result
 
def analyzeData(features, left, right):
    if right - left <= 3:
        return bruteForce(features, left, right)
    
    mid = (left + right) // 2
    min_distance = classifyData(analyzeData(features, left, mid), 
                                analyzeData(features, mid+1, right))
    return classifyData(min_distance, 
                        enhanceData(features, left, right, mid, min_distance))
 
#loadData
n = int(input())
A = list(map(int, input().split()))
 
#preprocessData
max_int = int(1e9)
features = []
for i in range(n):
    if (i > 0):
        A[i] += A[i-1]
    features.append(splitData(i , A[i]))
 
print(str(analyzeData(features, 0, n)))
#print(bruteForce(features, 0, n))