n = int(input())
x = sorted(list(map(int, input().split())), reverse = True)
x_2 = list(map(lambda x:x ** 2, x))
ichi = sum(x)
jijou = sum(x_2)
re = 10 ** 100


#def ji(p, x):
#    ans = p * (p - 2 * x)
#    return ans

for p in range(1, x[0] + 1):
    second = n * (p ** 2)
    third = -2 * p * ichi
    summ = jijou + second + third

    if re > summ:
        re = summ

print(re)

#for i in range(x[i]): n = int(input()) n int(input()) int input() input x = sorted(list(map(int, input().split())), reverse = True) x sorted(list(map(int, input().split())), reverse = True) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split reverse = True reverse True x_2 = list(map(lambda x:x ** 2, x)) x_2 list(map(lambda x:x ** 2, x)) list map(lambda x:x ** 2, x) map lambda x:x ** 2 x ** 2 x 2 x x ichi = sum(x) ichi sum(x) sum x jijou = sum(x_2) jijou sum(x_2) sum x_2 re = 10 ** 100 re 10 ** 100 10 100 for p in range(1, x[0] + 1):
    second = n * (p ** 2)
    third = -2 * p * ichi
    summ = jijou + second + third

    if re > summ:
        re = summ p range(1, x[0] + 1) range 1 x[0] + 1 x[0] x 0 1 second = n * (p ** 2) second n * (p ** 2) n p ** 2 p 2 third = -2 * p * ichi third -2 * p * ichi -2 * p -2 p ichi summ = jijou + second + third summ jijou + second + third jijou + second jijou second third if re > summ:
        re = summ re > summ re summ re = summ re summ print(re) print re second = n * (p ** 2) n * (p ** 2) second n = int(input()) int(input()) n x = sorted(list(map(int, input().split())), reverse = True) sorted(list(map(int, input().split())), reverse = True) x ichi = sum(x) sum(x) ichi re = 10 ** 100 10 ** 100 re x_2 = list(map(lambda x:x ** 2, x)) list(map(lambda x:x ** 2, x)) x_2 re = summ summ re jijou = sum(x_2) sum(x_2) jijou third = -2 * p * ichi -2 * p * ichi third summ = jijou + second + third jijou + second + third summ
n = int(input())
x = sorted(list(map(int, input().split())), reverse = True)
x_2 = list(map(lambda x:x ** 2, x))
ichi = sum(x)
jijou = sum(x_2)
re = 10 ** 100


#def ji(p, x):
#    ans = p * (p - 2 * x)
#    return ans

for p in range(1, x[0] + 1):
    second = n * (p ** 2)
    third = -2 * p * ichi
    summ = jijou + second + third

    if re > summ:
        re = summ

print(re)

#for i in range(x[i]):
