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 bisect
import heapq
import sys
from types import GeneratorType
from functools import cmp_to_key
from collections import defaultdict, Counter, deque
import math
from functools import lru_cache
from heapq import nlargest
from functools import reduce
import random
from itertools import combinations
from itertools import accumulate
from operator import xor, add
from operator import mul
from typing import List

inf = float("inf")
PLATFORM = "CF"
if PLATFORM == "LUOGU":
    import numpy as np

    sys.setrecursionlimit(1000000)


class FastIO:
    def __init__(self):
        return

    @staticmethod
    def _read():
        return sys.stdin.readline().strip()

    def read_int(self):
        return int(self._read())

    def read_float(self):
        return float(self._read())

    def read_ints(self):
        return map(int, self._read().split())

    def read_floats(self):
        return map(float, self._read().split())

    def read_ints_minus_one(self):
        return map(lambda x: int(x) - 1, self._read().split())

    def read_list_ints(self):
        return list(map(int, self._read().split()))

    def read_list_floats(self):
        return list(map(float, self._read().split()))

    def read_list_ints_minus_one(self):
        return list(map(lambda x: int(x) - 1, self._read().split()))

    def read_str(self):
        return self._read()

    def read_list_strs(self):
        return self._read().split()

    def read_list_str(self):
        return list(self._read())

    @staticmethod
    def st(x):
        return sys.stdout.write(str(x) + '\n')

    @staticmethod
    def lst(x):
        return sys.stdout.write(" ".join(str(w) for w in x) + '\n')

    @staticmethod
    def round_5(f):
        res = int(f)
        if f - res >= 0.5:
            res += 1
        return res

    @staticmethod
    def max(a, b):
        return a if a > b else b

    @staticmethod
    def min(a, b):
        return a if a < b else b

    @staticmethod
    def bootstrap(f, queue=[]):
        def wrappedfunc(*args, **kwargs):
            if queue:
                return f(*args, **kwargs)
            else:
                to = f(*args, **kwargs)
                while True:
                    if isinstance(to, GeneratorType):
                        queue.append(to)
                        to = next(to)
                    else:
                        queue.pop()
                        if not queue:
                            break
                        to = queue[-1].send(to)
                return to

        return wrappedfunc

    def ask(self, lst):
        self.lst(lst)
        sys.stdout.flush()
        res = self.read_int()
        return res


import random
import math


def dist(p1, p2):
    """
    计算两点之间的距离
    """
    return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)


def closest_pair(points):
    """
    平面最近点对算法
    """
    # 随机打乱输入点集
    random.shuffle(points)

    # 初始化最近点对的距离和点
    best_distance = float('inf')
    best_pair = None

    # 维护前缀点集的答案
    grid_size = int(math.sqrt(len(points)))
    grid = [[] for _ in range(grid_size)]
    for i, p in enumerate(points):
        for j in range(max(0, p[0] - 2), min(grid_size, p[0] + 3)):
            for k in range(max(0, p[1] - 2), min(grid_size, p[1] + 3)):
                for neighbor in grid[j * grid_size + k]:
                    if p != neighbor:
                        d = dist(p, neighbor)
                        if d < best_distance:
                            best_distance = d
                            best_pair = (p, neighbor)
        grid[p[0] * grid_size + p[1]].append(p)

        # 如果更新了答案，则重构网格图
        if i > 0 and i % 100 == 0:
            grid_size = int(math.sqrt(len(points[:i + 1]))) + 1
            grid = [[] for _ in range(grid_size)]
            for j in range(i + 1):
                p = points[j]
                grid[p[0] * grid_size + p[1]].append(p)

    return best_pair


class Solution:
    def __init__(self):
        return

    @staticmethod
    def main(ac=FastIO()):
        def dis(p1, p2):
            return (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1])

        def check(p):
            return p[0] // s, p[1] // s

        n = ac.read_int()
        nums = ac.read_list_ints()
        n = int(n)
        nums = list(accumulate(nums, add))
        nums = [[i, nums[i]] for i in range(n)]
        random.shuffle(nums)
        s = dis(nums[0], nums[1])
        if s == 0:
            ac.st(0)
            return
        dct = defaultdict(list)
        dct[check(nums[0])].append(0)
        dct[check(nums[1])].append(1)
        for i in range(2, n):
            a, b = check(nums[i])
            res = s
            for x in [-1, 0, 1]:
                for y in [-1, 0, 1]:
                    cur = (x+a, y+b)
                    for j in dct[cur]:
                        now = dis(nums[i], nums[j])
                        res = ac.min(now, res)
            if res == 0:
                ac.st(0)
                return
            if res < s:
                s = res
                dct = defaultdict(list)
                for x in range(i+1):
                    dct[check(nums[x])].append(x)
            else:
                dct[check(nums[i])].append(i)
        ans = s
        ac.st(ans)
        return


Solution().main()