from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
x = li()

ave = sum(x) //n

ans1=0
for i in range(n):
    ans1 += (x[i]-ave) ** 2
ans2=0
for i in range(n):
    ans2 += (x[i]-(ave+1)) ** 2
print(min(ans1,ans2)) from sys import exit import math math ii = lambda : int(input()) ii lambda : int(input()) int(input()) int input() input mi = lambda : map(int,input().split()) mi lambda : map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split li = lambda : list(map(int,input().split())) li lambda : list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split n = ii() n ii() ii x = li() x li() li ave = sum(x) //n ave sum(x) //n sum(x) sum x n ans1=0 ans1 0 for i in range(n):
    ans1 += (x[i]-ave) ** 2 i range(n) range n ans1 += (x[i]-ave) ** 2 ans1 (x[i]-ave) ** 2 x[i]-ave x[i] x i ave 2 ans2=0 ans2 0 for i in range(n):
    ans2 += (x[i]-(ave+1)) ** 2 i range(n) range n ans2 += (x[i]-(ave+1)) ** 2 ans2 (x[i]-(ave+1)) ** 2 x[i]-(ave+1) x[i] x i ave+1 ave 1 2 print(min(ans1,ans2)) print min(ans1,ans2) min ans1 ans2 mi = lambda : map(int,input().split()) lambda : map(int,input().split()) mi li = lambda : list(map(int,input().split())) lambda : list(map(int,input().split())) li x = li() li() x ave = sum(x) //n sum(x) //n ave ans1=0 0 ans1 ii = lambda : int(input()) lambda : int(input()) ii n = ii() ii() n ans2 += (x[i]-(ave+1)) ** 2 (x[i]-(ave+1)) ** 2 ans2 ans1 += (x[i]-ave) ** 2 (x[i]-ave) ** 2 ans1 ans2=0 0 ans2
from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
x = li()

ave = sum(x) //n

ans1=0
for i in range(n):
    ans1 += (x[i]-ave) ** 2
ans2=0
for i in range(n):
    ans2 += (x[i]-(ave+1)) ** 2
print(min(ans1,ans2))