Harryxun/stf_run huggingface dataset:
N = int(input())
a = list(map(int, input().split()))
A = []
B = []

while len(a) > 0:
	A.append(max(a))
	a.remove(max(a))
	B.append(max(a))
	a.remove(max(a))

print(sum(A) - sum(B))

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
A = []
B = []

if len(a) % 2 == 1:
	A.append(min(a))
	a.remove(min(a))

while len(a) > 0:
	A.append(max(a))
	a.remove(max(a))
	B.append(max(a))
	a.remove(max(a))

print(sum(A) - sum(B))
from math import gcd

N = int(input())
A = list(map(int, input().split()))

g_all = A[0]
for a in A[1:]:
    g_all = gcd(g_all, a)

if g_all > 1:
    print('not coprime')
    quit()

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table


appeared = [False] * (10**6 + 1)
primes = sieve(10**3)
for a in A:
    if a == 1:
        continue
    for p in primes:
        if a % p == 0:
            if appeared[p]:
                print('setwise coprime')
                quit()
            appeared[p] = True
            while a % p == 0:
                a //= p
    
    if a != 1:
        if appeared[a]:
            print('setwise coprime')
            quit()
        
        appeared[a] = True

print('pairwise coprime')

### FIXED CODE ###

from math import gcd

N = int(input())
A = list(map(int, input().split()))

g_all = A[0]
for a in A[1:]:
    g_all = gcd(g_all, a)

if g_all > 1:
    print('not coprime')
    quit()

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table


appeared = [False] * (10**6 + 1)
primes = sieve(10**3)[1]
for a in A:
    if a == 1:
        continue
    for p in primes:
        if a % p == 0:
            if appeared[p]:
                print('setwise coprime')
                quit()
            appeared[p] = True
            while a % p == 0:
                a //= p
    
    if a != 1:
        if appeared[a]:
            print('setwise coprime')
            quit()
        
        appeared[a] = True

print('pairwise coprime')
D,N=map(int, input().split())
ans=0
if D==0:
  ans=N
elif D==1:
  ans=100*N
elif D==2:
  ans=10000*N
if N==100 ans D==2:
  ans+=ans
  #N=100の時は100で割り切れてしまうから、N=101にする
print(ans)


### FIXED CODE ###

D,N=map(int, input().split())
x=100**D
ans=x*N
if N==100:
  ans+=x
  #N=100の時は100で割り切れてしまうから、N=101にする
print(ans)
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
BC = [tuple(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    temp = [A == BC[i][0]] * BC[i][1]
    A = A + temp
    print(A.sum())


### FIXED CODE ###

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
BC = [tuple(map(int, input().split())) for _ in range(Q)]
total = sum(A)

A_dict = {}
for a in A:
    if a in A_dict:
        A_dict[a] += 1
    else:
        A_dict[a] = 1

for i in range(Q):
    b = BC[i][0]
    c = BC[i][1]

    if b in A_dict:
        total += (c - b) * A_dict[b]
        print(total)
        
        if c in A_dict:
            A_dict[c] += A_dict[b]
        else:
            A_dict[c] = A_dict[b]
        A_dict[b] = 0
    
    else:
        print(total)
A,B =[int(i) for i in input().split()]
num += 0
for i in range(A,B+1):
    n = i
    s=[]
    while(n>0):
        s.append(str(n%10))
        n //= 10

    s_rev = ''.join(s[::-1])
    s = ''.join(s)
    if(s == s_rev):
        num += 1
print(num)


### FIXED CODE ###

A,B =[int(i) for i in input().split()]
num = 0
for i in range(A,B+1):
    n = i
    s=[]
    while(n>0):
        s.append(str(n%10))
        n //= 10

    s_rev = ''.join(s[::-1])
    s = ''.join(s)
    if(s == s_rev):
        num += 1
print(num)
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    N,K=MI()
    a=LI()#下位の連続するn枚が不要なはず
    a.sort()
    for i in range(N):#K以上ならば必要
        if a[i]>=K:
            a=a[:i]
    N=len(a)
                    
                    
    #x番目の数が必要かどうかの判定 
    #必要なものだけで構成された集合をもとに考えれば良いわけではない，不必要な分も考えなければならない             
    def ch(x):
        
        #使い回す，i番目まででjが作れるか
        dp=[False]*K
        dp[0]=True
        for i in range(N):
            if i==x:
                continue
            else:
                for j in range(K-1,a[i]-1,-1):
                    dp[j]|=dp[j-a[i]]
                
                        
        #K未満K-a[x]以上が作れれば良い    
        for j in range(K-a[x],K):
            if  dp[j]:
                return True
        return False
            
    
                        
    ng=-1
    ok=N
    while abs(ok-ng)>1:
        med=(ok+ng)//2
        
        if ch(med):
            ok=med
        else:
            ng=med
            
    print(ng+1)
    
    
   
    
            
    
    
    

main()


### FIXED CODE ###

def main():
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    
    N,K=MI()
    a=LI()#下位の連続するn枚が不要なはず
    a.sort()
    for i in range(N):#K以上ならば必要
        if a[i]>=K:
            a=a[:i]
            break
    N=len(a)
                    
                    
    #x番目の数が必要かどうかの判定 
    #必要なものだけで構成された集合をもとに考えれば良いわけではない，不必要な分も考えなければならない             
    def ch(x):
        
        #使い回す，i番目まででjが作れるか
        dp=[0]*K
        dp[0]=1
        for i in range(N):
            if i==x:
                continue
            else:
                for j in range(K-1,a[i]-1,-1):
                    dp[j]|=dp[j-a[i]]
                
                        
        #K未満K-a[x]以上が作れれば良い    
        for j in range(K-a[x],K):
            if  dp[j]:
                return True
        return False
            
    
                        
    ng=-1
    ok=N
    while abs(ok-ng)>1:
        med=(ok+ng)//2
        
        if ch(med):
            ok=med
        else:
            ng=med
            
    print(ng+1)
    
    
 
    

main()
#!/usr/bin/python

# AtCoder Beginner Contest 076
# C - Dubious Document 2

from sys import stdin

def match(S, pos, T):
  for i in range(len(T)):
    if S[pos + i] != '?' and S[pos + i] != T[i]:
      return False
  return True

def solve(S, T):
  minS = '~' * len(S)
  for pos in range(len(S) - len(T) + 1):
    # S[pos : pos + len(T)] matches T ?
    if match(S, pos, T):
      S_ = S[:pos] + T + S[pos + len(T):]       # replace the mid part with T
      S_ = [c if c != '?' else 'a' for c in S_] # replace '?' with 'a'
      if minS > S_: minS = S_
  return ''.join(minS) if minS[0] != '~' else 'UNRESTORABLE'

S = stdin.readline().strip()
T = stdin.readline().strip()
print(solve(S, T))

### FIXED CODE ###

#!/usr/bin/python

# AtCoder Beginner Contest 076
# C - Dubious Document 2

from sys import stdin

def match(S, pos, T):
  for i in range(len(T)):
    if S[pos + i] != '?' and S[pos + i] != T[i]:
      return False
  return True

def solve(S, T):
  minS = '~' * len(S)
  for pos in range(len(S) - len(T) + 1):
    # S[pos : pos + len(T)] matches T ?
    if match(S, pos, T):
      S_ = S[:pos] + T + S[pos + len(T):]       # replace the mid part with T
      S_ = [c if c != '?' else 'a' for c in S_] # replace '?' with 'a'
      if minS > S_: minS = S_
  return ''.join(minS) if minS[0] != '~' else 'UNRESTORABLE'

S = stdin.readline().strip()
T = stdin.readline().strip()
print(solve(S, T))
a,b=map(int,input().split())
#n,k=map(int,input().split())
#H=list(map(int,input().split()))
print(max(a-2*b),0)

### FIXED CODE ###

#n=int(input())
a,b=map(int,input().split())
#n,k=map(int,input().split())
#H=list(map(int,input().split()))
c=a-2*b
print(max(c,0))
from collections import deque

def solve():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    INF = 10 ** 9
    d = [[INF] * W for i in range(H)]
    d[0][0] = 1 if A[0][0] == '#' else 0

    def bfs():
        prepare = 1 if A[0][0] == '#' else 0
        q = deque([(0, 0, prepare)])
        while q:
            w, h, c = q.popleft()
            for a, b in [(1,0), (0,1)]:
                w_n, h_n = w+a, h+b
                if w_n >= W or h_n >= H: continue
                k = 1 if A[w_n][h_n] == '#' else 0
                if c+k >= d[h_n][w_n]: continue
                d[h_n][w_n] = c+k
                q.append((w_n, h_n, c+k))
    bfs()
    return d[H-1][W-1]

print(solve())

### FIXED CODE ###

from collections import deque

def solve():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    INF = 10 ** 9
    d = [[INF] * W for i in range(H)]
    d[0][0] = 1 if A[0][0] == '#' else 0

    prepare = 1 if A[0][0] == '#' else 0
    q = deque([(prepare, 0, 0)])
    while q:
        c, x, y = q.popleft()
        for a, b in [(1,0), (0,1)]:
            nx, ny = x+a, y+b
            if nx >= W or ny >= H: continue
            k = 1 if A[y][x] != A[ny][nx] else 0
            if c+k >= d[ny][nx]: continue
            d[ny][nx] = c+k
            q.append((c+k, nx, ny))

    return (d[H-1][W-1]+1)//2

print(solve())
import math

def main():
    N, D = list(map(int, input().split()))
    ans = 0
    for i in range(0,N):
        A, B = list(map(int, input().split()))
        if dist <= D:
            ans +=1
    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

import math

def main():
    N, D = list(map(int, input().split()))
    ans = 0
    for i in range(0,N):
        A, B = list(map(int, input().split()))
        dist = math.sqrt(A**2 + B**2)
        if dist <= D:
            ans +=1
    print(ans)


if __name__ == '__main__':
    main()
from numba import njit


@njit
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [10**10] * (N+1)
    dp[0] = 0

    for i in range(1, N):
        for j in range(min(i, K)):
            dp[i] = min(dp[i], dp[i-j-1]+abs(h[i]-h[i-j-1]))

    print(dp[N-1])


if __name__ == "__main__":
    main()


### FIXED CODE ###

from numba import njit


@njit
def main(N, K, h):
    dp = [10**10] * (N+1)
    dp[0] = 0

    for i in range(1, N):
        for j in range(min(i, K)):
            dp[i] = min(dp[i], dp[i-j-1]+abs(h[i]-h[i-j-1]))

    return dp[N-1]


if __name__ == "__main__":
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    print(main(N, K, h))
import re

N, Q = list(map(int, input().split()))
S = input()
T = [list(map(int, input().split())) for _ in range(Q)]

S = re.sub('[^AC]+', 'X', S)
print(S)

for i in range(Q):
  l, r = T[i][0], T[i][1]
  s = S[l-1:r]
  count = 0
  if r-l == 0:
    count = 0
  else:
    for j in range(r-l):
      if s[j] == 'A' and s[j+1] == 'C':
        count += 1
  print(count)

### FIXED CODE ###

N, Q = list(map(int, input().split()))
S = input()
T = [list(map(int, input().split())) for _ in range(Q)]

total_list = []
total = 0
try:
  for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
      total += 1
    total_list.append(total)

  for i in range(Q):
    l, r = T[i][0], T[i][1]
    if l != 1:
      print(total_list[r-2]-total_list[l-2])
    else:
      print(total_list[r-2])
except IndexError:
  print(0)
A,B,C,K = map(int,input().split())
N = [A,B,C]
N2 = N[:]
for i in range(K):
    N2[0] = N[1] + N[2]
    N2[1] = N[0] + N[2]
    N2[2] = N[0] + N[1]
    N = N2.copy
print(N2)
ans = N2[0] - N2[1]
if abs(ans) > 10**18:
    print('Unfair')
else:
    print(ans)

### FIXED CODE ###

a,b,c,k = map(int, input().split())
cheak = 10**18
ans = a-b
def calc(a,b,c,k):
    if a == b:
        return 0
    elif ans < 0:
        if k % 2 == 1:
            return -ans
        else:
            return ans
    else:
        if k % 2 == 1:
            return -ans
        else:
            return ans
ans_n = calc(a,b,c,k)
if ans_n > cheak:
    print("Unfair")
else:
    print(ans_n)
N, X, T = map(int, input().split())
if int(N) % int(X) != 0 :
	print( ( int(N) // int(X) + 1) * int(T) )
if int(N) % int(X) == 0 :
	print( (int(N) / int(X) * int(T) )


### FIXED CODE ###

N, X, T = map(int, input().split())
if int(N) % int(X) != 0 :
	print( ( int(N) // int(X) + 1) * int(T) )
if int(N) % int(X) == 0 :
	print( (int(N) // int(X) ) * int(T) )
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))
b=copy.deepcopy(a)





def akey(a):
    return a[0],a[1]
def bkey(a):
    return a[1],a[0]
list.sort(a,key=akey,reverse=True)
list.sort(b,key=bkey,reverse=True)

def remove(a, data,tag):
    if tag:
        tag=0
    else:
        tag=1
    n = len(a)
    first = 0
    last = n - 1

    while first <= last:
        mid = int(first + ((last - first) / 2))

        if a[mid][tag] < data[tag]:
            last = mid - 1
        elif a[mid][tag] > data[tag]:
            first = mid + 1
        else:
            del a[mid]
            return

def func(a,b):
    pa,pb=0,0
    tag=True
    while len(a)!=0:
        if a[0]==b[0]:
            tmp=a[0]
        else:
            v1=a[0][0]-b[0][1]
            v2=b[0][0]-b[1][1]
            if v1>v2:
                tmp=a[0]
            else:
                tmp=b[0]
        if tag:
            pa+=tmp[0]
        else:
            pb+=tmp[1]

        remove(a,tmp,tag)
        remove(b,tmp,not tag)
        tag=not tag
        a,b=b,a

    return pa-pb
    
print(func(a,b)) 







### FIXED CODE ###

import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))

def akey(a):
    return a[0]+a[1]
list.sort(a,key=akey,reverse=True)


def func(a):
    pa,pb=0,0
    tag=True
    for idx in range(0,len(a)):
        if tag:
            pa+=a[idx][0]
        else:
            pb+=a[idx][1]
        tag=not tag
    return pa-pb
    
print(func(a))
X, Y, Z, K = map(int, input().split())
A = sorted([int(x) for x in input().split()], reverse=True)[:K]
B = sorted([int(x) for x in input().split()], reverse=True)[:K]
C = sorted([int(x) for x in input().split()], reverse=True)[:K]

bi_comb = []
for i in range(X):
    for j in range(Y):
        if (i+1)*(j+1) > K:
            break
        bi_comb.append(A[i] + B[j])
bi_comb.sort(reverse=True)
# bi_comb = bi_comb[:K]
tri_comb = []
for k in range(K):
    for l in range(Z):
        tri_comb.append(bi_comb[k] + C[l])
tri_comb.sort(reverse=True)

print(*tri_comb[:K], sep="\n")

### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
A = sorted([int(x) for x in input().split()], reverse=True)
B = sorted([int(x) for x in input().split()], reverse=True)
C = sorted([int(x) for x in input().split()], reverse=True)

bi_comb = []
for i in range(min(X, K)):
    for j in range(min(Y, K)):
        if (i+1)*(j+1) > K:
            break
        bi_comb.append(A[i] + B[j])
bi_comb.sort(reverse=True)

tri_comb = []
for k in range(min(len(bi_comb), K)):
    for l in range(min(Z, K)):
        if (k+1)*(l+1) > K:
            break
        tri_comb.append(bi_comb[k] + C[l])
tri_comb.sort(reverse=True)

print(*tri_comb[:K], sep="\n")
haiku = int(input())
x = haiku.split(' ')
num_5 = 0
num_7 = 0

for v in x:
	if x[v] == 5:
		num_5 ++
	elif x[v] == 7:
		num_7 ++

if num_5 == 2 and num_7 == 1
	print('YES')
else
	print('NO')

### FIXED CODE ###

haiku = input()
x = haiku.split()
num_5 = 0
num_7 = 0

for v in x:
    v = int(v)
    if v == 5:
        num_5 += 1
    elif v == 7:
        num_7 += 1

if num_5 == 2 and num_7 == 1:
    print('YES')
else:
    print('NO')
nk = input().split()
s = input().split()
s[int(nk[1])-1] = s[int(nk[1])-1].lower()


### FIXED CODE ###

nk = input().split()
index = int(nk[1]) -1
s = input()
c = 0
for i in s:
  if c == index: print(i.lower(),end="")
  else: print(i,end="")
  c+= 1
N,T=map(int,input().split())
cost=1000
for _ in range(N):
    c,t=map(int,input().split())
    if t<=T:
        if cost>c:
            cost=c
if cost>1000:
    print(cost)
else:print("TLE")

### FIXED CODE ###

n=int(input())
if n==1:
  print("Hello World")
else:
  a,b=[int(input()) for i in range(2)]
  print(a+b)
N = int(input())
A = list(map(int, input().split()))

count = 0
while sum(list(map(lambda x: x % 2, A))) == 0 :
    count += 1
    A = list(map(lambda x: x / 2, A))

print(count)


### FIXED CODE ###

print(input().count('1'))
s = list(map(int, input().split()))
print(ma(s) - min(s))

### FIXED CODE ###

input()
s = sorted(map(int, input().split()))
print(s[len(s) - 1] - s[0])
n=int(input())
import numpy as np
npi = np.array(list(map(int,input().split())))
if npi.mean()%1>0.5:
  p=npi.mean()//1 +1
else:
  p=npi.mean()//1
print(int(np.sum((npi-p)**2)))


### FIXED CODE ###

n=int(input())
import numpy as np
npi = np.array(list(map(int,input().split())))
if npi.mean()%1>0.5:
  p=npi.mean()//1 +1
else:
  p=npi.mean()//1
print(int(np.sum((npi-p)**2)))
l=list(map(int,input().split()))
m=len(set(l))
if(m==1):
  print("Yes")
else:
  prit("No")

### FIXED CODE ###

l=list(map(int,input().split()))
m=len(set(l))
if(m==1):
  print("Yes")
else:
  print("No")
n, x = input().strip().split()
n = int(n)
x = int(x)
l = input().strip().split()
now = 0
for i in range(n):
  now += l[i]
  if now > x:
    print(i)


### FIXED CODE ###

n, x = input().strip().split()
n = int(n)
x = int(x)
l = input().strip().split()
l = list(map(int, l))
now = 0
for i in range(n):
  now += l[i]
  if now > x:
    print(i+1)
    exit()
print(n+1)
a,b = random.randint(1, 20)
if a+b <= 18:
  print(a*b)
  else:
    print(-1)

### FIXED CODE ###

a,b=map(int, input().split())
if a<=9 and b<=9:
  print(a*b)
else:
  print(-1)
b=0
if (b-a)>k:
  print("ok")
else:
  for i in range(1,1001):
    if a<i*k<b:
      b=1
if b=0:
  print("ng")
else:
  print("ok")

### FIXED CODE ###

k=int(input())
suzi_list=input().split()
a=int(suzi_list[0])
b=int(suzi_list[1])
c=(b//k)*k
if a<=c:
  print('OK\n')
else:
  print('NG\n')
N,M= map(int, input().split())

def dividable(x,y):
    if x/y == x//y:
        return True
    else:
        return False

for i in range(2,int(M//N)+1):
    if dividable(M,i) and int(M/i) >= N:
            answer = i

print(answer)

### FIXED CODE ###

import math
N,M= map(int, input().split())
 
answer = 1
list = []
for i in range(1,math.floor(M**(1/2))+1):
    if M % i == 0 and int(M/i) >= N:
        answer = i
        list.append(int(M/i))
 
 
for k in list:
    if M/k >= N:
        answer = k
        break
 
print(answer)
a,b,c,d=map(int,input().split())
h=k-a
h2=h-b
if a>k:print(k)
else:if h<=b:print(a)
     else: print(a+h2*(-1))

### FIXED CODE ###

a,b,c,k=map(int,input().split())
h=k-a
h2=h-b
if a>k:
  print(k)
else:
  if h<=b:
    print(a)
  else:
    print(a+h2*(-1))
N = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)
ans = 0

A = []
n = N * 3
for i in range(1, n+1, 2):
    A.append(a[i])

for i in range(N):
    ans += A[i]
print(ans)


### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)
ans = 0
count = 0
for i in range(1, N*3+1, 2):
    if count == N:
        break
    else:
        ans += a[i]
        count += 1

print(ans)
import sys
import random
import numpy as np
from fractions import gcd
def main(a, b):
    #a, b = [int(i) for i in sys.stdin.readline().split()]
    _gcd = gcd(a,b)
    memo_ls = np.zeros(_gcd).flatten()
    #memo_set = set()
    cnt = 0
    if _gcd == 1:
        print(1)
    else:
        for i in range(2, _gcd+1):
            if _gcd % i == 0 and memo_ls[i-1] != 1:
                #memo_ls[i-1::i] = 1
                cnt += 1
                #memo_set.add(i)
        #print(memo_set)
        print(cnt + 1)

if __name__ == "__main__":
    a, b = [int(i) for i in sys.stdin.readline().split()]
    main(a, b)

### FIXED CODE ###

import sys
from fractions import gcd
def prime_factorize(n):
    a = set()
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a

def main(a, b):
    #a, b = [int(i) for i in sys.stdin.readline().split()]
    _gcd = gcd(a,b)
    #memo_ls = [0 for i in range(_gcd)]
    #memo_set = set()
    cnt = 0
    if _gcd == 1:
        print(1)
    else:
        res = prime_factorize(_gcd)
        print(len(res) + 1)
if __name__ == "__main__":
    a, b = [int(i) for i in sys.stdin.readline().split()]
    main(a, b)
N = int(input())
X = input().split()
X = [int(l) for l in X]

s = 0
for x in X:
    s += (x-1)**2

S = s

if N == 1:
    print(0)
else:
    m = max(X)
    n = min(X)
    for P in range(n,m+1):
        s = 0
        for x in X:
            s += (x-P)**2
        if s < S:
            S = s
	print(S)

### FIXED CODE ###

N = int(input())
X = input().split()
X = [int(l) for l in X]

s = 0
for x in X:
    s += (x-X[0])**2
S = s

if N == 1:
    print(S)
else:
    m = max(X)
    n = min(X)
    for P in range(n,m+1):
        s = 0
        for x in X:
            s += (x-P)**2
        if s < S:
            S = s
    print(S)
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=[]
for i in range(m):
    p=list(map(int,input().split()))
    b.append(p)
b.sort(key=lambda x:-x[1])
a.sort()
print(a)
print(b)
wes=-1
i=0
s=0
while True:
    wes+=b[i][0]
    if a[wes]>=b[i][1]:
        wes-=b[i][0]
        wes+=1
        break
    else:
        
        s+=b[i][0]*b[i][1]
        i+=1
for j in range(b[i][0]):
    if a[wes+j]<b[i][1]:
        a[wes+j]=b[i][1]
f=a[wes:]
print(s)
s+=sum(f)
print(f)
print(s)

### FIXED CODE ###

n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=[]
s=0
for i in range(m):
    p=list(map(int,input().split()))
    b.append(p)
    s+=p[0]
b.sort(key=lambda x:-x[1])
a.sort()
if s>n:
    s=n
c=[]
i=0
sun=0
while sun<s:
    for j in range(b[i][0]):
        c.append(b[i][1])
    sun+=b[i][0]
    i+=1
for u in range(s):
    if a[u]<c[u]:
        a[u]=c[u]
    
print(sum(a))
A,B=[int(s) for s in input().split(" ")]
N1list=[]
N2list=[]

for i in range(0,10,1):
    N1list.append((A+(i/10))/0.08)   
    N2list.append((B+(i/10))/0.1)

N3=-2
N1list.sort(reverse=True)
N2list.sort(reverse=True)

if N1list[9]<N2list[0]:
    for i in range(10):
        N=N1list[i]
        if N==int(N):
            for j in range(10):
                if N==N2list[j]:
                    N3=N
                    break
        else:
            N4=-1
else:
    N4=-1
            
print(int(N3) if N4<N3 else N4)

### FIXED CODE ###

N,A,B=[int(s) for s in input().split(" ")]
Ans1=N//(A+B)
Ans2=N%(A+B)
if Ans2>A:
    Ans3=A
else:
    Ans3=Ans2

Ans=A*Ans1+Ans3

print(int(Ans))
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A,B,C,D = map(int, input().split())
A-=1

AC=int(A/C)
AD=int(A/D)
BC=int(B/C)
BD=int(B/D)
ACD=int(A/lcm(C,D))
BCD=int(B/lcm(C,D))
A_=AC+AD-ACD
B_=BC+BD-BCD

print((B-B_)-(A-A_))


### FIXED CODE ###

a,b,c,d = map(int,input().split(" "))
def gcd(c,d):
	if(c==0):
		return d
	else:
		return gcd(d%c,c)
prod = c*d
lcm = prod//gcd(c,d)
a1=b//c - (a-1)//c
a2=b//d - (a-1)//d
a3=b//lcm-(a-1)//lcm
print(b-a+1-a1-a2+a3)