CodeEff/ECCO huggingface dataset:
# Original solution
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"


def solve():
    N = int(eval(input()))
    A = list(sorted(list(map(int, input().split())), reverse=True))

    alice, bob = 0, 0
    for i, a in enumerate(A):
        if i % 2 == 0:
            alice += a
        else:
            bob += a

    return alice - bob


def main():
    print((solve()))


if __name__ == '__main__':
    main()

# Optimized solution
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    N = int(eval(input()))
    A = list(sorted(list(map(int, input().split())), reverse=True))
    a, b = 0, 0
    for i in range(N):
        if i % 2 == 0:
            a += A[i]
        else:
            b += A[i]
    print((a - b))
    

if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

def quicksort(array):
    if len(array) < 2:
        return(array)
    else:
        pivot = array[0]
        less = [i for i in array[1:] if i <= pivot]
        greater = [i for i in array[1:] if i > pivot]

        return quicksort(greater) + [pivot] + quicksort(less)


sorted_a = quicksort(a)
alice = []
bob = []
for i in range(len(sorted_a)):
    if i % 2 == 0:
        alice.append(sorted_a[i])
    else:
        bob.append(sorted_a[i])
print((sum(alice) - sum(bob)))


# Optimized solution
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = na()
a = sorted(a, reverse=True)
ai = [i for i in range(0,n,2)]
bi = [i for i in range(1,n,2)]
alice = 0
bob = 0
for i in ai:
    alice += a[i]
for i in bi:
    bob += a[i]
print((alice-bob))
# Original solution
N = int(eval(input()))
aList = list(map(int, input().split()))
aList.sort(reverse = True)
aPoint = 0
bPoint = 0
if N % 2 == 0:
    for i in range(N//2):
        aPoint += aList[2*i]
        bPoint += aList[2*i + 1]
else:
    for i in range(N//2):
        aPoint += aList[2*i]
        bPoint += aList[2*i + 1]
    aPoint += aList[N-1]
print((aPoint - bPoint))

# Optimized solution
N = int(eval(input()))
aList = list(map(int, input().split()))
aList.sort(reverse = True)
point = [0, 0]
for i in range(N):
    point[i%2] += aList[i]
print((point[0] - point[1]))
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
ali=0
bob=0
a.sort(reverse=True)
for i in range(len(a)):
    if i%2==0:
        ali+=a[i]
    else:
        bob+=a[i]
print((ali-bob))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
a.sort(reverse=True)
alice=sum(a[::2]) 

bob=sum(a[1::2])
print((alice-bob))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
Alice = Bob = 0

for i in range(N):

    if i%2==0:
        Alice+=A[i]
    else:
        Bob+=A[i]

print((Alice-Bob))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
Alice = sum(A[0::2])
Bob = sum(A[1::2])

print((Alice-Bob))
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
alice = 0
bob = 0
a.sort()
a.reverse()
for i in range(len(a)):
    if i%2 == 0:
        alice += a[i]
    else:
        bob += a[i]

print((alice-bob))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

alice = 0
bob = 0

for i in range(1,len(a)+1):
    if i % 2 != 0:
        alice += a.pop(a.index(max(a)))
    else:
        bob += a.pop(a.index(max(a)))

print((alice - bob))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

Alice = []
Bob = []

while 0 < len(a):
    Alice.append(a.pop(a.index(max(a))))
    if 0 < len(a):
        Bob.append(a.pop(a.index(max(a))))

print((sum(Alice) - sum(Bob)))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

a.sort(reverse=True)
print((sum(a[0::2])-sum(a[1::2])))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
Alice = 0
Bob = 0
ans = 0
while len(a) != 0:
    Alice += max(a)
    a.remove(max(a))
    if a:
        Bob += max(a)
        a.remove(max(a))
ans = Alice - Bob
print(ans)


# Optimized solution
n = int(eval(input()))
a = sorted(list(map(int, input().split())), reverse=True)
print((sum(a[::2]) - sum(a[1::2])))
# Original solution
N=int(eval(input()))
A=sorted(list(map(int,input().split())))
if N%2==0:
  a=0
  for i in range(int(N/2)):
    a+=A[2*i+1]-A[2*i]
else:
  a=A[0]
  for i in range(int(N/2)):
    a+=A[-(2*i+1)]-A[-(2*i+2)]
print(a)

# Optimized solution
N=eval(input())
c=sorted(list(map(int,input().split())))[::-1]
n=0
for i in c[0::2]:
  n+=i
for i in c[1::2]:
  n-=i
print(n)
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))

alice = 0
bob = 0
for i in range(n):
    if (i+1)%2 == 1:
        alice += max(A)
    else:
        bob += max(A)
    A.remove(max(A))
    
print((alice - bob))

# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))

A.sort(reverse=True)

alice = 0
bob = 0
for i,a in enumerate(A):
    if (i+1)%2 == 1:
        alice += a
    else:
        bob += a

print((alice - bob))
# Original solution
n = int(eval(input()))
card_list = list(map(int,input().split(" ")))

card_list_ex = sorted(card_list, reverse=True)


alice,bob = 0,0
for i,j in enumerate(card_list_ex):
    if i % 2 == 0:
        alice += j
    else:
        bob += j
res = alice - bob
print(res)

# Optimized solution
# coding: utf-8
# Your code here!

num = int(eval(input()))
s = sorted(list(map(int,input().split())) ,reverse=True)
#print(s)

alice,bob = 0,0
for i,j in enumerate(s):
    if i % 2 == 0:
        alice += j
    else:
        bob += j
        
print((alice - bob))
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
a.sort(reverse=True)
print((sum(a[::2])-sum(a[1::2])))

# Optimized solution
n,*a=list(map(int,open(0).read().split()))
a.sort()
print((sum(a[-1::-2])-sum(a[-2::-2])))
# Original solution
n = int(eval(input()))
c = list(map(int, input().split()))
c.sort(reverse=True)
a = sum([v for i, v in enumerate(c) if i % 2 == 0 ])
b = sum([v for i, v in enumerate(c) if i % 2 == 1 ])
print((a - b))

# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = sum(A[::2]) - sum(A[1::2])
print(ans)
# Original solution
n = int(eval(input()))
alist = list(map(int, input().split()))
alist.sort(reverse=True)
p1 = []
p2 = []
for i in range(n):
    if i%2 == 0:
        p1.append(alist.pop(0))
    else:
        p2.append(alist.pop(0))

print((sum(p1)-sum(p2)))

# Optimized solution
N = int(eval(input()))
A = sorted(list(map(int, input().split())), reverse=True)
A_cards = []
B_cards = []
flag = 'A'
for card in A:
    if flag == 'A':
        flag = 'B'
        A_cards.append(card)
    elif flag == 'B':
        flag = 'A'
        B_cards.append(card)
print((sum(A_cards) - sum(B_cards)))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse = True)
alice = bob = 0
for i in range(N):
    if i%2 == 0:
        alice += A.pop(0)
    else:
        bob += A.pop(0)
    
print((alice - bob))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse = True)
alice = bob = 0
for i in range(N):
    if i%2 == 0:
        alice += A[i]
    else:
        bob += A[i]
    
print((alice - bob))
# Original solution
N = int(eval(input()))
A = sorted(list(map(int,input().split())), reverse = True)

alice = 0
bob = 0
for i in range(N):
  if(i%2 == 0):
    alice += A[i]
  else:
    bob += A[i]
print((alice-bob))

# Optimized solution
N = int(eval(input()))
A = sorted(list(map(int,input().split())), reverse = True)
alice, bob = 0, 0
for i in range(N):
  if(i%2 == 0):
    alice += A[i]
  else:
    bob += A[i]
print((alice - bob))
# Original solution
n=int(eval(input()))
a=sorted(list(map(int,input().split())),reverse=True)
alice=sum(a[::2])
bob=sum(a[1::2])
print((alice-bob))

# Optimized solution
n=int(eval(input()))
a=sorted(list(map(int,input().split())),reverse=True)
print((sum(a[::2])-sum(a[1::2])))
# Original solution
n=int(eval(input()))
s=list(map(int,input().split()))
s.sort(reverse=True)
a=[int(i) for i in s[::2]]
b=[int(j) for j in s[1::2]]
print((sum(a)-sum(b)))

# Optimized solution
n=int(eval(input()))
a=sorted(list(map(int,input().split())))
print((sum(a[-1::-2])-sum(a[-2::-2])))
# Original solution
N = int(eval(input()))
a = list(map(int,input().split()))
a.sort()
a.reverse()
Alice = []
Bob = []
if N % 2 == 0:
    for i in range(N//2):
        Alice.append(a[i*2])
        Bob.append(a[i*2+1])
    print((sum(Alice) - sum(Bob)))
elif N % 2 == 1 and N != 1:
    for i in range((N-1)//2):
        Alice.append(a[i*2])
        Bob.append(a[i*2+1])
    Alice.append(a[-1])
    print((sum(Alice) - sum(Bob)))
elif N == 1:
    print((a[0]))

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.sort(reverse = True)
Alice = []
Bob = []
while len(A) != 0:
        Alice.append(A[0])
        A = A[1:]
        if len(A) != 0:
                Bob.append(A[0])
                A = A[1:]

print((sum(Alice)-sum(Bob)))
# Original solution
n = eval(input())
cards = list(map(int, input().split()))
sorted_cards = sorted(cards, reverse=True)
alice, bob = [], []
for index, card in enumerate(sorted_cards):
    if index % 2 == 0:
        alice.append(card)
    else:
        bob.append(card)
print((sum(alice) - sum(bob)))

# Optimized solution
n = eval(input())
sorted_cards = sorted(list(map(int, input().split())), reverse=True)
print((sum(sorted_cards[::2]) - sum(sorted_cards[1::2])))
# Original solution
n = int(eval(input()))
a_list = list(map(int, input().split()))
a_list = sorted(a_list, reverse=True)

alice_point = 0
bob_point = 0
for i in range(n):
    if i % 2 == 0:
        alice_point += a_list[i]
    else:
        bob_point += a_list[i]

print((alice_point - bob_point))

# Optimized solution
n = int(eval(input()))
a_list = sorted(map(int, input().split()), reverse=True)

alice_score = sum(a_list[0::2])
bob_score = sum(a_list[1::2])

print((alice_score - bob_score))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

a.sort(reverse=True)

ans = sum(a[0::2]) - sum(a[1::2])

print(ans)


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

a.sort()
a.reverse()
print((sum(a[::2]) - sum(a[1::2])))
# Original solution
N=eval(input())
a=input().split()
N=int(N)
for i in range(N):
    a[i]=int(a[i])

point_a=0
point_b=0

#全てのカードがなくなるまで（＝すべての変数値が0になったらカード無）
#一番目に大きい数値をアリスに
#二番目に大きい数値をボブに
while max(a)>0:
    #一番目に大きい数値をアリスに
    point_a+=max(a)
    #この数値をゼロに戻す
    a[a.index(max(a))]=0
    #二番目に大きい数値（この時点で一番大きい数値）をボブに
    point_b+=max(a)
    #この数値をゼロに戻す
    a[a.index(max(a))]=0

#答え
print((point_a-point_b))

# Optimized solution
N=eval(input())
a=input().split()
N=int(N)
for i in range(N):
    a[i]=int(a[i])

#処理
a=sorted(a,reverse=True)

score_a=0
score_b=0

for i in range(N):
    if i%2==0:
        score_a+=a[i]
    else:
        score_b+=a[i]

print((score_a-score_b))
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
a = sorted(a)[::-1]
Alice = 0
Bob = 0
for i in range(N):
  if i % 2 == 0:
    Alice += a[i]
  else:
    Bob += a[i]
print((Alice - Bob))

# Optimized solution
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
print((sum(A[-1::-2])-sum(A[-2::-2])))
# Original solution
n = int(eval(input()))
A = sorted([int(i) for i in input().split()], reverse = True)
print((sum(A[::2]) - sum(A[1::2])))

# Optimized solution
n = int(eval(input()))
A = [int(i) for i in input().split()]
A.sort(reverse = True)
x = A[::2]
print((sum(x) - (sum(A) - sum(x))))
# Original solution
alice=0
bob=0
n=int(eval(input()))
a=list(map(int,input().split()))
def delete():
    del a[a.index(Max)]
while n>=1:
    Max=max(a)
    alice=alice+Max
    n=n-1
    delete()
    if n>=1:
        Max=max(a)
        bob=bob+Max
        n=n-1
        delete()
else:
    print((alice-bob))



# Optimized solution
n = eval(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
print((sum(a[::2]) - sum(a[1::2])))
# Original solution
import itertools
u=[1,2,3,4,5,6,7,8,9]
a=0
n=list(map(int,input().split()))
for x in itertools.permutations(u):
    f=0
    for i in range(9):
        if n[i]!=-1 and n[i]!=x[i]:f=1
    if f:continue
    if x[0]+x[2]+x[5]-x[8]+(x[1]+x[4]-x[7])*10+(x[3]-x[6])*100==0:a+=1
print(a)

# Optimized solution
def f(n,x):
    for i in range(9):
        if n[i] != -1 and n[i] != x[i]: return 1
import itertools
u=[1,2,3,4,5,6,7,8,9]
a=0
n=list(map(int,input().split()))
for x in itertools.permutations(u):
    if f(n,x):continue
    if x[0]+x[2]+x[5]-x[8]+(x[1]+x[4]-x[7])*10+(x[3]-x[6])*100==0:a+=1
print(a)
# Original solution
n = int(eval(input()))
x = list(map(int, input().split()))

f = 10**100

for p in range(min(x), max(x) + 1):
    l = [(x[i] - p)**2 for i in range(n)]
    f1 = sum(l)
    f = min(f, f1)

print(f)

# Optimized solution
n = int(eval(input()))
x = list(map(int, input().split()))

x_mean = sum(x)/n
p1 = int(x_mean)
p2 = p1 + 1

if abs(x_mean - p1) > abs(x_mean - p2):
    p = p2
else:
    p = p1

ans = 0
for i in range(n):
    ans += (x[i]-p)**2
print(ans)
# Original solution
N = int(eval(input()))
X = list(map(int, input().split()))
tairyoku = [0]*100

for i in range(100):
    t=0
    for j in range(N):
        t += (X[j]-i)**2
        tairyoku[i]=t

print((min(tairyoku)))

# Optimized solution
N = int(eval(input()))
X = list(map(int,input().split()))
power = [0 for i in range(100)]

for i in range(100):
    for j in range(N):
        power[i] += (X[j]-i)**2

print((min(power)))
# Original solution
n = int(eval(input()))
x = list(map(int,input().split()))
S = sum(x)
Ave = sum(x) // n
m = 10**6
score = 0

for p in range(Ave,Ave+1001): 
    for i in range(n):
        score += (x[i]-p)**2
    if score < m:
        m = score
        score = 0
print(m)

# Optimized solution
#恐らく平均値に最も近い整数が答えになるかと思われる
n = int(eval(input()))
x = list(map(int,input().split()))
Ave = sum(x) / n
point = 0


for i in range(n):
    point += (x[i]-round(Ave))**2 
print(point)
# Original solution
N, *X = list(map(int, open(0).read().split()))

m = sum(X) // N
v1 = sum((v - m) ** 2 for v in X)
v2 = sum((v - m - 1) ** 2 for v in X)
print((min(v1, v2)))


# Optimized solution

N = int(eval(input()))
X = list(map(int, input().split()))

cand = sum(X) // N
ans0 = sum((v - cand) ** 2 for v in X)
ans1 = sum((v - cand - 1) ** 2 for v in X)
print((min(ans0, ans1)))
# Original solution
n = int(eval(input()))
x = list(map(int, input().split()))
ans = 10 ** 9
for p in range(0, 101):
    cnt = 0
    for i in x:
        cnt += (i-p)**2
    ans = min(ans, cnt)
print(ans)

# Optimized solution
n = int(eval(input()))
x = list(map(int, input().split()))
ans1 = 0
ans2 = 0
xa = sum(x) // n
for i in x:
    ans1 += (abs(i-xa))**2

for i in x:
    ans2 += (abs(i-xa-1))**2

print((min(ans1, ans2)))
# Original solution
def main():
  from statistics import mean
  from math import floor,ceil

  n = int(eval(input()))
  x = list(map(int, input().split()))
  x_mean = mean(x) 
  if x_mean == 0.5:
      greater_than_x = len([i for i in x if i > x_mean])
      if greater_than_x * 2 >= n:
          x_mean = ceil(x_mean)
      else:
          x_mean = floor(x_mean)
  elif x_mean % 1 > 0.5:
      x_mean = ceil(x_mean)
  else:
      x_mean = floor(x_mean)
  x2 = [(num - x_mean)**2 for num in x]
  print((sum(x2)))

main()

# Optimized solution
import sys
read = sys.stdin.read
def main():
    n, *x = list(map(int, read().split()))
    r = float('inf')
    for i1 in range(1, 101):
        rt = 0
        for xe in x:
            rt += (xe - i1)**2
        r = min(r, rt)
    print(r)

if __name__ == '__main__':
    main()
# Original solution
# C - Rally
def main():
    N, *X = list(map(int, open(0).read().split()))
    left, right = min(X), max(X)
    ans = min(sum([(x - p) ** 2 for x in X]) for p in range(left, right + 1))
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
# C - Rally
def main():
    N, *X = list(map(int, open(0).read().split()))
    calc = lambda x, p: (x - p) ** 2
    P = sum(X) // N
    ans = min(sum(calc(x, p) for x in X) for p in range(P - 2, P + 2))
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
import math
from statistics import mean, median,variance,stdev
N = int(eval(input()))
X = list(map(int,input().split()))
a = sum(X)
ave = round(a/N)
b = 0
for i in range(N):
    b +=(X[i]-ave)**2
print(b)

# Optimized solution
N = int(eval(input()))
X = list(map(int,input().split()))
ans = 10**8
c = int()
for i in range(1,100):
    c = 0
    for j in range(len(X)):
        c += (X[j]-i)**2
    if c < ans:
        ans = c
print(ans)
# Original solution
import sys
readline = sys.stdin.readline
N = int(readline())
X = list(map(int, readline().split()))
X.sort()

INF = 10**9+7
ans = INF
for p in range(0, 102):
    res = 0
    for x in X:
        res += (p-x)**2
    ans = min(ans, res)
print(ans)


# Optimized solution
n = int(eval(input()))
(*x,) = list(map(int, input().split()))
a = round(sum(x) / n)
print((sum(((i - a) ** 2) for i in x)))
# Original solution
n=int(eval(input()))
l=list(map(int,input().split()))
import statistics as st
m=round(st.mean(l))
print((sum((m-i)**2 for i in l)))

# Optimized solution
n=int(eval(input()))
l=list(map(int,input().split()))
m=round(sum(l)/n)
print((sum((m-i)**2 for i in l)))
# Original solution
N=int(eval(input()))
X=list(map(int,input().split()))
ans = 100000000
for j in range(1,100):
  res = 0
  for i in range(N):
    res += (X[i]-j)**2
  ans=min(ans,res)
print(ans)


# Optimized solution
N=int(eval(input()))
X=sorted(list(map(int,input().split())))

ans = 100000000

for p in range(1,100): #Pの位置
  sum = 0
  for x in X: #Xの要素を１つずつ取得
    sum += (x - p)**2
  ans = min(sum, ans)

print(ans)
# Original solution
n = int(eval(input()))
li = list(map(int,input().split()))
lia = []
for i in range(1,100):
    a = 0
    for j in range(n):
        a += (abs(li[j]-i))**2
    lia.append(a)
print((min(lia)))

# Optimized solution
n = int(eval(input()))
li = list(map(int,input().split()))
o1 = (sum(li))//n
o2 = o1 + 1
li1 = []
li2 = []
for i in range(n):
    li1.append((int(li[i]-o1))**2)
for j in range(n):
    li2.append((int(li[j]-o2))**2)
if sum(li1) >= sum(li2):
    print((sum(li2)))
else:
    print((sum(li1)))
# Original solution
a = int(eval(input()))
b = list(map(int, input().split()))
p = min(b)
saveans = 0
ans = 0
for x in b:
    ans += (x - p) ** 2

while p <= max(b):
    saveans = 0
    for x in b:
        saveans += (x - p) ** 2
    if saveans < ans:
        ans = saveans
    p += 1

print(ans)


# Optimized solution
a = int(eval(input()))
b = list(map(int, input().split()))
p = int(sum(b) / len(b))
ans1 = ans2 = 0
for x in b:
    ans1 += (x - p) ** 2
    ans2 += (x - 1 - p) ** 2
if ans1 > ans2:
    print(ans2)
else:
    print(ans1)
# Original solution
eval(input())
x = sorted([int(i) for i in input().split()])
cost = sum([xi**2 for xi in x])
for p in range(x[0], x[-1] + 1):
    c = 0
    for xi in x:
        c += (xi - p)**2
    cost = min(c, cost)
print(cost)

# Optimized solution
n = int(eval(input()))
x = [int(i) for i in input().split()]
p = round(sum(x) / n)
print((sum((i - p)**2 for i in x)))
# Original solution
# -*- coding: utf-8 -*-


def main():
    n = int(eval(input()))
    x = list(map(int, input().split()))
    ans = float('inf')

    for p in range(-100, 201):
        summed = 0

        for xi in x:
            summed += (xi - p) ** 2

        ans = min(ans, summed)

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
# -*- coding: utf-8 -*-


def main():
    n = int(eval(input()))
    x = list(map(int, input().split()))
    ans = float('inf')

    # KeyInsight:
    # xの座標の最小値から最大値までを探索すればよい
    # See: https://img.atcoder.jp/abc156/editorial.pdf
    left = min(x)
    right = max(x)

    for p in range(left, right + 1):
        summed = 0

        for xi in x:
            summed += (xi - p) ** 2

        ans = min(ans, summed)

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
x = list(map(int, input().split()))
ans = float('inf')
for i in range(101):
    now = 0
    for j in range(n):
        now += (x[j] - i) ** 2
    ans = min(ans, now)
print(ans)


# Optimized solution
n = int(eval(input()))
x = list(map(int, input().split()))
avg = sum(x) / n
if avg % 1 >= 0.5:
    avg += 1
avg = int(avg)
ans = 0
for xi in x:
    ans += (xi - avg) ** 2
print(ans)
# Original solution
N=int(eval(input()))
X=[int(i) for i in input().split(" ")]
sp=lambda P:sum([(Xi-P)**2 for Xi in X])
print((min([sp(p) for p in range(0,102)])))


# Optimized solution
N=int(eval(input()))
if N==1:
    print((0))
else:
    X=[int(x) for x in input().split(" ")]
    cons=lambda P:sum([(x-P)**2 for x in X])
    print((min([cons(P) for P in range(0,102)])))
# Original solution
'''
n = int(input())
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [int(input()) for i in range n]
p = [list(map(int, input().split()))]

a = input()
a, b = input().split()
a = [input() for i in range n]
'''
n = int(eval(input()))
x = list(map(int, input().split()))


import math
p0 = math.floor(sum(x)/len(x))
# 123
cost = 0
for i in x:
    cost += abs(p0-i)**2

new = 10**9
while cost < new:
    p0 += 1
    new_cost = 0
    for i in x:
        new_cost += abs(p0-i)**2
    new = new_cost
print(new)


# Optimized solution

n = int(eval(input()))
x = list(map(int, input().split()))
cost = 10**9
for i in range(1,100):
    now = 0
    for j in x:
        now += (i-j)**2
    if cost > now:
        cost = now
print(cost)
# Original solution
n = int(eval(input()))
x = list(map(int,input().split()))
a = min(x)
b = max(x) + 1
ans = 10 ** 8
for p in range(a,b):
    m = 0
    for i in range(n):
        m += (x[i] - p) ** 2
    ans = min(ans,m)
print(ans)

# Optimized solution
n = int(eval(input()))
x = list(map(int,input().split()))
ans = 10 ** 12
for i in range(1,101):
    p = 0
    for j in x:
        p += (j - i) ** 2
    ans = min(ans,p)
print(ans)
# Original solution

N = int(eval(input()))
x_list = list(map(int, input().split()))
maxValue = max(x_list)
minValue = 1000000
for i in range(1,100):
    ans = 0
    for j in range(N):
        ans += ( x_list[j] - i ) **2

    if(ans < minValue):
        minValue = ans

print(minValue)

# Optimized solution

N = int(eval(input()))

x_list = list(map(int, input().split())) 

p = round( sum(x_list) / N )
ans = 0

for i in range(N):
    # ans += round( (x_list[i] - p) ** 2 )
    ans +=  (x_list[i] - p) ** 2 

print(ans)
# Original solution
import sys
l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip()
nums = list(map(int, l.split()))
nums = sorted(nums)
start = nums[0]
end = nums[-1] + 1
mi = float("INF")
def compute_dist(p):
  dist = 0
  for n in nums:
    dist += (n-p) ** 2
  return dist
for i in range(start, end):
  d = compute_dist(i)
  if d < mi:
    mi = d
print(mi)

# Optimized solution
import sys
l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip()
nums = list(map(int, l.split()))
a = sum(nums) / len(nums)
a1 = int(a)
a2 = int(a) + 1
def count(p):
    d = 0
    for n in nums:
        d += (n-p)**2
    return d
print((min(count(a1), count(a2))))