def getDis(X,p):
    res = 0
    for x in X:
        res += (x-p)**2
    return res

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

p = sum(X)//n

for i in range(n):
    d = getDis(X,p)
    if d>getDis(X,p+1):
        p+=1
    elif d>getDis(X,p-1):
        p-=1
    else:
        break

print(d) def getDis(X,p):
    res = 0
    for x in X:
        res += (x-p)**2
    return res getDis res = 0 res 0 for x in X:
        res += (x-p)**2
     x X res += (x-p)**2 res (x-p)**2 x-p x p 2 return res res X X p p n = int(input()) n int(input()) int input() input X = list(map(int,input().split())) X list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split p = sum(X)//n p sum(X)//n sum(X) sum X n for i in range(n):
    d = getDis(X,p)
    if d>getDis(X,p+1):
        p+=1
    elif d>getDis(X,p-1):
        p-=1
    else:
        break i range(n) range n d = getDis(X,p) d getDis(X,p) getDis X p if d>getDis(X,p+1):
        p+=1
    elif d>getDis(X,p-1):
        p-=1
    else:
        break d>getDis(X,p+1) d getDis(X,p+1) getDis X p+1 p 1 p+=1 p 1 elif d>getDis(X,p-1):
        p-=1
     d>getDis(X,p-1) d getDis(X,p-1) getDis X p-1 p 1 p-=1 p 1 break print(d) print d p = sum(X)//n sum(X)//n p n = int(input()) int(input()) n def getDis(X,p):
    res = 0
    for x in X:
        res += (x-p)**2
    return res def getDis(X,p):
    res = 0
    for x in X:
        res += (x-p)**2
    return res getDis d = getDis(X,p) getDis(X,p) d p+=1 1 p X = list(map(int,input().split())) list(map(int,input().split())) X p-=1 1 p
def getDis(X,p):
    res = 0
    for x in X:
        res += (x-p)**2
    return res

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

p = sum(X)//n

for i in range(n):
    d = getDis(X,p)
    if d>getDis(X,p+1):
        p+=1
    elif d>getDis(X,p-1):
        p-=1
    else:
        break

print(d)