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>).
class Point:
	def __init__(self, x, y): self.x, self.y = x, y

def distance(point1, point2):
	return (point1.x - point2.x) ** 2 + (point1.y - point2.y) ** 2

def mergeByY(arr1, arr2):
	ptr1, ptr2 = 0, 0
	lst = []

	while ptr1 < len(arr1) or ptr2 < len(arr2):
		if ptr1 < len(arr1) and (ptr2 == len(arr2) or (arr1[ptr1].y, arr1[ptr1].x) < (arr2[ptr2].y, arr2[ptr2].x)):
			lst.append(arr1[ptr1])
			ptr1 = ptr1 + 1
		else:
			lst.append(arr2[ptr2])
			ptr2 = ptr2 + 1

	return lst

def minimumDistance(arr, start, end):
	if start == end: return float("inf"), [arr[start]]

	mid = (start + end) // 2
	minLeft, arrLeft = minimumDistance(arr, start, mid)
	minRight, arrRight = minimumDistance(arr, mid + 1, end)

	arrMerged = mergeByY(arrLeft, arrRight)

	minimal = min(minLeft, minRight)
	min_between = float("inf")

	close_proximity = []

	for p in arrMerged:
		if p.x >= arr[mid].x - minimal and p.x <= arr[mid].x + minimal:
			close_proximity.append(p)

	ptr1, ptr2 = 0, 0
	while ptr1 < len(close_proximity):
		while ptr2+1 < len(close_proximity) and close_proximity[ptr2+1].y - close_proximity[ptr1].y <= minimal: ptr2 += 1

		for i in range(ptr1, ptr2+1): # one can prove that there will be at most 6 points in each rectangular grid
			for j in range(i+1, ptr2+1):
				min_between = min(min_between, distance(close_proximity[i], close_proximity[j]))

		ptr1 = ptr1 + 1
	
	return min(minimal, min_between), arrMerged

def minFunc(arr):
	prefix_sum = [arr[0]]
	for i in range(1, len(arr)): prefix_sum.append(prefix_sum[-1] + arr[i])

	points = [Point(i, prefix_sum[i]) for i in range(len(arr))]
	minimal, points_byY = minimumDistance(arr=points, start=0, end=len(arr)-1)
	return minimal


n = int(input())
a = list(map(int, input().split()))

print(minFunc(a))