Problem:
 Score : 300 points    Problem Statement There are N people living on a number line.  The i -th person lives at coordinate X_i .  You are going to hold a meeting that all N people have to attend.  The meeting can be held at any integer coordinate . If you choose to hold the meeting at coordinate P , the i -th person will spend (X_i - P)^2 points of stamina to attend the meeting.  Find the minimum total points of stamina the N people have to spend.      Constraints  All values in input are integers.  1 \leq N \leq 100  1 \leq X_i \leq 100         Input Input is given from Standard Input in the following format:  N  X_1  X_2  ...  X_N       Output Print the minimum total stamina the N people have to spend.        Sample Input 1 2
1 4      Sample Output 1 5  Assume the meeting is held at coordinate 2 . In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.  Note that you can hold the meeting only at an integer coordinate.       Sample Input 2 7
14 14 2 13 56 2 37      Sample Output 2 2354

Solution (Python):
n=int(input())
x=[int(x) for x in input().split()]
ave=sum(x)/len(x)
if ave>=int(ave)+0.5:
    ave=int(ave)+1
else:
    ave=int(ave)
val=0
for i in x:
    val+=(ave-i)**2
print(val)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))


ans = 10**7
for p in range(0, max(x) + 1):
    sums = 0
    for i in x:
        sums += (i - p) ** 2
    ans = min(sums, ans)

print(ans)

Solution (Python):

N = int(input())
A = list(map(int,input().split()))
mi = min(A)
ma = max(A)
ans = 10 ** 12
for i in range(mi,ma+1):
    su = 0
    for j in A:
        su += (i-j)**2
    ans = min(ans,su)
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
sum=0
for i in range(N):
    sum = sum+A[i]
ans = 0
if sum%N <= N//2:
    for i in range(N):
        ans = ans+ (A[i]-(sum//N))**2
    print(ans)
else:
    for i in range(N):
        ans = ans+ (A[i]-1-(sum//N))**2
    print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
sum_x = sum(x)
sum_x2 = sum([i**2 for i in x])
p0 = sum_x//n
p1 = p0+1
r0 = n*p0**2 - 2*sum_x*p0 + sum_x2
r1 = n*p1**2 - 2*sum_x*p1 + sum_x2
print(min(r0,r1))

Solution (Python):
import math

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




avg = math.ceil(sum(x)/n)
avg2 = sum(x)//n

ans = min(sum([(X-avg)**2 for X in x]), sum([(X-avg2)**2 for X in x]))

print(ans)

Solution (Python):

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

ans = 10 ** 10
for i in range(1,101):
    mps = 0
    for X in Xs:
        mps += (X - i)**2
    ans = min(ans, mps)


print(ans)

Solution (Python):
n = int(input())
ls = list(map(int,input().split()))

ls = sorted(ls)

ans = 10000000000000
x = 0
for i in range(ls[0],ls[-1]+1):
  tmp = 0
  for a in ls:
    tmp += (a-i)**2
  if ans > tmp:
    x = i
    ans = tmp
print(ans)

Solution (Python):
n = int(input())
ls = list(map(int, input().split()))

wa = sum(ls)

wa2 = 0
for i in ls:
    wa2 += i ** 2

p = round(wa / n)

ans = wa2 - 2 * p * wa + n * (p ** 2)

print(ans)

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    x = [int(i) for i in input().split()]
    min = -1

    for i in range (100):
        sum = 0
        i = i+1
        for j in x:
            sum =sum + (i - j) * (i - j )

        if min == -1 or min > sum:
            min = sum
    print(min)

Solution (Python):
import sys

n = int(input())

x = [int(i) for i in input().split()]

cofg=sum(x)//n
cofg2=cofg+1

sum=0
sum2=0
for i in range(n):
    sum+=(x[i]-cofg)**2
    sum2+=(x[i]-cofg2)**2


ans = sum if sum < sum2 else sum2



print(ans)

Solution (Python):
N = int(input())
li = list(map(int,input().split()))	
mi = 10000000000
for i in range(1,100):
    hp = 0
    for j in range(0,len(li)):
        hp += (i-li[j])**2
    if mi >= hp:
        mi = hp
print(mi)

Solution (Python):


from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


yn = 'YNeos'
ynflg = False
cnt = 0
ans = None

def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas



N = intinput()
xs = list(mulinputs())


l = max(xs)
total = []
m = 10**6
for p in range(l+1):
    t, larr = 0, []
    for x in xs:
        t += abs(x-p)*abs(x-p)
    if t < m:
        m = t



print(m)

Solution (Python):
N=int(input())
X=list(map(int, input().split()))

R=round(sum(X)/N)
ans=0
for i in range(N):
  ans+=(R-X[i])**2
print(ans)

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]

INF = (100 ** 2) * 100

minD = INF

for xi in range(1, 101):
    D = 0
    for n in range(N):
        D += (xi-X[n])**2
    if D < minD:
        minD = D

print(minD)

Solution (Python):
def main():
    from sys import stdin, setrecursionlimit
    
    
    
    
    
    
    
    
    
    
    
    

    n= int(input())
    x = list(map(int, input().split()))
    avr = sum(x) // len(x)
    avr2 = avr + 1
    x2 = [(i-avr)**2 for i in x]
    x3 = [(i-avr2)**2 for i in x]
    print(min(sum(x2),sum(x3)))

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
sum = sum(x)
ave = int(round((sum/n), 0))
sum2 = 0
for i in range(n):
  sum2 = sum2 + (x[i] - ave) **2
print(sum2)

Solution (Python):
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))
import string
numbers = "0123456789"
alphabets = string.ascii_letters 
characters = numbers + alphabets
 
def base_cvt(value, n=2):
    try:
        tmp = int(value)
    except:
        raise ValueError('Invalid value:', value)
 
    if n < 2 or n > len(characters):
        raise ValueError('Invalid n:', value)
 
    result = ''
    tmp = int(value)
    while tmp >= n:
        idx = tmp%n
        result = characters[idx] + result
        tmp = int(tmp / n)
    idx = tmp%n
    result = characters[idx] + result
    return result

N = num()
X = nums()
def get_cost(l,pos):
    cost = 0
    for xi in l:
        cost += (xi - pos)**2
    return cost
costs = set()
for i in range(min(X)-1,max(X)+1):
    costs.add(get_cost(X,i))
print(min(costs))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
hpmin = (100 ** 2) * 100
for p in range(1, 101):
    hp = 0
    for j in range(n):
        hp += (x[j] - p) ** 2
    if hp < hpmin:
        hpmin = hp
print(hpmin)

Solution (Python):




import sys
input = sys.stdin.readline



def main():
    N = int(input())
    X = list(map(int,input().split()))

    dp = [0] * 101

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

    res = min(dp)

    print(res)



main()

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
m=0;n=1000000000000
for i in range(1,101):
  for j in range(N):
    m=m+((X[j]-i)**2)
  n=min(n,m)
  m=0
print(n)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))

SINGLE_SUM = sum(X)
DOUBLE_SUM = sum([x ** 2 for x in X])


def f(n, p):
    return n * p ** 2 - 2 * p * SINGLE_SUM + DOUBLE_SUM


min_ = None
for p in range(min(X), max(X) + 1):
    val = f(N, p)
    if min_ is None or val < min_:
        min_ = val

print(min_)

Solution (Python):
N = int(input())
X = sorted([int(n) for n in input().split()])
ans = 10**9
for p in range(X[0], X[-1]+1):
    c = 0
    for x in X:
        c += (x-p)**2
    if c < ans:
        ans = c
print(ans)

Solution (Python):
N = int(input())
x = list(map(int, input().split()))

ans = 10 ** 8
for p in range(1, 101):
    temp = 0
    for i in x:
        temp += (i - p)** 2
    if temp < ans:
        ans = temp
print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ans = 1000000000

for i in range(1, 101):
    s = 0
    for j in x:
        s += (i - j) ** 2
    ans = min(ans, s)
print(ans)

Solution (Python):
n= int(input())
x = list(map(int,input().split()))
ans = 10**10
tmp = 0
for i in range(min(x),max(x)+1):
         for j in range(len(x)):
                  tmp+=(x[j]-i)**2
         if ans > tmp:
                  ans = tmp
         tmp = 0
print(ans)

Solution (Python):



import numpy

def main():
  n = int(input())
  xs = numpy.array(list(map(int, input().strip().split())))
  min = 10**9
  for p in range(1, 101):
    cost = numpy.sum((xs - p) ** 2)
    if min > cost:
      min = cost
  print(int(min))

if __name__=='__main__':
  main()

Solution (Python):
def main():
    N=int(input())
    X=list(map(int,input().split()))

    count=0
    result=10**10
    for p in range(101):
        count=0
        for i in range(N):
            count+=(X[i]-p)**2
        result=min(result,count)
    print(result)
if __name__=="__main__":
    main()

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ans = 10**9
for P in range(1,101):
    sum = 0
    for j in range(N):
        sum += (X[j]-P)**2
    ans = min(ans,sum)
print(ans)

Solution (Python):



n = int(input())
x = [int(i) for i in input().split()]

s = 0
for i in x:
    s += i

p = s//n

m = 0
mm = 0
for i in x:
    m += (i - p)**2
    mm += (i - p - 1)**2
    
print(min([m, mm]))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))

x_min = min(X)
x_max = max(X)

ans = 10000**10

for i in range(x_min, x_max + 1):
    
    sum_ = 0
    for xi in X:
        sum_ += (xi - i) ** 2
    
    ans = min(ans, sum_)

print(ans)

Solution (Python):
n = int(input())
x_L = list(map(int,input().split()))
x_L = list(sorted(x_L))
start = x_L[0]
end = x_L[-1]
a = 10**20
for i in range(start,end+1):
    sums = 0
    for k,val in enumerate(x_L):
        sums += (x_L[k]-i)**2
    a = min(a,sums)
print(a)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))

mm = 0
for x in X:
    mm += x**2

for i in range(min(X), max(X) + 1):
    s = 0
    for x in X:
        s += (x - i)**2

    if s < mm:
        mm = s

print(mm)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
ans=10000000
for i in range(1,101):
    P=i
    sums=0
    for j in range(N):
        sums+=(X[j]-P)*(X[j]-P)
    if(sums<ans):
        ans=sums
print(ans)

Solution (Python):
n = int(input())
*x, = map(int, input().split())
ans = float("inf")
for i in range(max(x)):
    ans = min(ans, sum(map(lambda a: (a-(i+1))**2, x)))

print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))

avg = round(sum(x)/n)
ans = 0
for i in x:
    ans += (avg-i)**2
print(ans)

Solution (Python):
import numpy as np
N =int(input())
X = np.array(list(map(int,input().split())))

m = np.inf
for i in range(1,101):
  m = min( np.sum((X -i)**2),m)
  
print(int(m))

Solution (Python):
import sys


N = int(sys.stdin.readline())
X = list(map(int, sys.stdin.readline().split()))

temp = sum(X)/N
shukai = round(temp)

total = 0
for i in range(N):
    total += (X[i] - shukai)*(X[i] - shukai)
print(total)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))


ans=10**100
for j in range(1,101):
    ans2=0
    for i in range(n):
        ans2+=(x[i]-j)**2
    ans=min(ans,ans2)

print(ans)

Solution (Python):
n = int(input())
x_i = list(map(int, input().split()))
ave = round(sum(x_i) / n)
ans = 0
for id in range(n):
    ans += (x_i[id] - ave) ** 2
print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ans = float("INF")
for i in range(1, max(x) + 1):
    tmp = 0
    for j in x:
        tmp += (j - i) ** 2
    ans = min(ans, tmp)
print(ans)

Solution (Python):
N = int(input())
XList = list(map(int, input().split()))

Z = 0
for i in range(N):
    Z += XList[i]

result = 0
if Z % N == 0:
    Z //= N
    for i in range(N):
        result += (XList[i] - Z) ** 2
else:
    Z //= N
    tmp = 0
    for i in range(N):
        tmp += (XList[i] - Z) ** 2
    Z += 1
    for i in range(N):
        result += (XList[i] - Z) ** 2
    if tmp < result:
        result = tmp

print(result)

Solution (Python):
n,*a=map(int,open(0).read().split())
b=10**8
for i in range(1,101):
    b=min(b,sum((j-i)**2 for j in a))
print(b)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))

x_max, x_min = max(X), min(X)

min_cost = float('inf')
for p in range(x_min, x_max+1):
    cost = 0
    for j in range(N):
        cost += (X[j] - p) ** 2
    if cost < min_cost:
        min_cost = cost

print(min_cost)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))

minX = min(x)
maxX = max(x)

s = [0] * (maxX + 1)
for i in range(minX, maxX+1):
    for _x in x:
        s[i] += (_x - i)**2

print(min(s[minX:]))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
s = min(x)
e = max(x)

f_inf = float("inf")
ans = f_inf
for j in range(s, e + 1):
    res = 0
    for i in range(n):
        res += (x[i] - j) ** 2

    ans = min(ans, res)

print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
p1=sum(A)//N
p2=p1+1
s1,s2=0,0
for i in A:
  s1+=(i-p1)**2
  s2+=(i-p2)**2
print(min(s1,s2))

Solution (Python):
n = int(input())
x = sorted(list(map(int, input().split())))

if n == 1:
    print(0)
else:
    ans = float('inf')
    for i in range(x[0], x[-1]+1):
        temp = 0
        for j in range(n):
            temp += (i - x[j])**2
        ans = min(ans, temp)
    print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))

ans = 100**3

for i in range(100):
    l = 0
    for j in range(n):
        l += (x[j]-i)**2
    ans = min(ans, l)
print(ans)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
a = min(X)
b = max(X)

res = 10**8

for i in range(a, b + 1):
    k = 0
    for j in range(n):
        k += (i - X[j])**2
    res = min(res, k)
    
print(res)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
a=max(x)
ans=sum([(1-i)**2 for i in x])

for i in range(1,a+1):
    hp=sum([(i-j)**2 for j in x])
    if ans>=hp:
        ans=hp
print(ans)

Solution (Python):
N = int(input())
X_list = [int(item) for item in input().split()]
res = 1000000
next_res = 10000000

for j in range(100):
    res = min(res, next_res)
    next_res = 0
    for i in range(N):
        next_res += (X_list[i] - j)**2

print(res)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))

ans = 100 * 100 * 100
for i in range(100):
  temp = 0
  for j in x:
    temp += pow(j - i, 2)
  if temp < ans:
    ans = temp

print(ans)

Solution (Python):
import math

n = int(input())
x_n = list(map(lambda x:int(x),input().split()))


def abs(n):
    if n<0:
        return -1*n
    else:
        return n



def sum(list):
    sum = 0
    for i in list:
        sum = sum + i
    return sum


w = sum(x_n)/n
ceil_w = math.ceil(w)

if abs(ceil_w-w) <= 0.5:
    w =ceil_w
else:
    w = math.floor(w)

energy = 0
for i in x_n:
    energy = energy + (w - i) **2


print(energy)

Solution (Python):

from math import ceil,floor
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nms = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
x=nl()






ans=10**10
for i in range(1,101):
    t=0
    for j in range(n):
        t+=(x[j]-i)**2
    ans=min(ans,t)
print(ans)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
P=round(sum(X)/N)
ans=0
for i in range(N):
    ans+=(P-X[i])**2
print(ans)

Solution (Python):
n = int(input())
xl = list(map(int, input().split()))

mi = 10**10
for i in range(1, 101):
    tmp = 0
    for x in xl:
        tmp += (x - i)**2
    if tmp < mi:
        mi = tmp

print(mi)

Solution (Python):
import math
N = int(input())
X = list(map(int, input().split()))
s = 0
t = 0

for x in X:
    s += x
    t += x ** 2

def check(k):
    return t - 2 * s * k + N * (k ** 2)

if check(math.floor(s / N)) < check(math.ceil(s / N)):
    print(check(math.floor(s / N)))
else:
    print(check(math.ceil(s / N)))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
a=sum(x)//n
b=a+1
s=[(i-a)**2 for i in x]
t=[(i-b)**2 for i in x]
print(min(sum(s),sum(t)))

Solution (Python):

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


ave= sum(X) // N
ave2 = ave+1

ans1 = 0
ans2 = 0
for x in X:
    ans1 += pow(x-ave,2)
    ans2 += pow(x-ave2,2)

print(min(ans1, ans2))

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
mi = min(a)
ma = max(a)

dis = 10 ** 9
for idx in range(mi, ma+1):
  tmp_dis = 0
  for e in a:
    tmp_dis += (e - idx) ** 2
  dis = min(dis, tmp_dis)
print(dis)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))


meanX = sum(X)//len(X)

a1 = 0
for x in X:
    a1 += (x -  meanX)**2
a2 = 0
for x in X:
    a2 += (x- meanX + 1) ** 2

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

ans = min(a1, a2, a3)
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
import math


x = sum(a)/N
x_large = math.ceil(x)
x_small = math.floor(x)


sum_large = 0
sum_small = 0
for i in a:
	sum_large += (x_large-i)**2
	sum_small += (x_small-i)**2

print(min(sum_large,sum_small))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ave = round(sum(X) / len(X))
sum = 0
for x in X:
    sum += (x - ave) ** 2
print(sum)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X_ = sum(X) // N
HP1 = 0
HP2 = 0
for i in range(N):
  HP1 += (X[i] - X_)**2
  HP2 += (X[i] - X_ -1 )**2
if HP1>=HP2:
  print(HP2)
else:
  print(HP1)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
min = 99999999
tai = 0

for i in range(1,101):
  tai = 0
  for j in range(0,N):
    tai = tai + (X[j] - i)**2
  
  if tai < min:
    min = tai

print(min)

Solution (Python):
n=int(input())
x= list(map(int, input().split()))
ans=float('inf')
for i in range(1,101):
    cnt=0
    for j in range(n):
        cnt+=(x[j]-i)**2
    ans=min(cnt,ans)
print(ans)

Solution (Python):
N = int(input())
x = list(map(int,input().split()))

ans = float("inf")
for i in range(1,101):
    sum = 0
    for j in x:
        sum += abs(j - i)**2
    ans = min(ans,sum)
    
print(ans)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
ave1=int(sum(x)//n)
ave2=int((sum(x)//n)+1)
tol1=0
tol2=0
for i in range(n):
  tol1+=(x[i]-ave1)**2
  tol2+=(x[i]-ave2)**2
print(min(tol1,tol2))

Solution (Python):
N = int(input())
x_list = list(map(int,input().split()))
Min_pow = 100*100*100
for i in range (1,101):
    pow_sum = 0
    for j in range(N):
        pow_sum += (x_list[j]-i)*(x_list[j]-i)
    if pow_sum < Min_pow:
        Min_pow = pow_sum

print(Min_pow)

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue


Mod = 1000000007
import sys
sys.setrecursionlimit(1000000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): 
    n = int(input())
    x = list(map(int,input().split()))
    p = 0
    ans = []
    for i in range(1,101):
        for j in range(n):
            p += (i - x[j]) ** 2
        ans.append(p)
        p = 0
    print(min(ans))


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
p1 = sum(x) // n
p2 = p1 + 1
print(min(sum((xi - p1) ** 2 for xi in x),
          sum((xi - p2) ** 2 for xi in x)))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
m = 10 ** 8
for i in range(min(x), max(x) + 1):
    c = 0
    for j in range(n):
        c += (x[j] - i) ** 2
    if c < m:
        m = c
print(m)

Solution (Python):
n=int(input())
X=list(map(int,input().split()))
R=100**2*100
for i in range(1,101):
    r=0
    for j in range(n):
        r+=(X[j]-i)**2
    R=min(R,r)
print(R)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
average = round(sum(X) / N)

ans = 0
for x in X:
    ans += (x - average) ** 2
print(ans)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def main():
	a = int(input())
	al = list(IN())
	
	avg = sum(al) // a
	
	mm= None
	for i in range(3):
		pp=avg + i - 1
		rr = sum([(v-pp)**2 for v in al])
		mm = rr if mm is None or mm > rr else mm
		
	ret=mm
	print(ret)
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
def main():
    import sys
    sys.setrecursionlimit(10000000)
    

    from collections import Counter
    from collections import deque

    
    
    
    n = int(input())
    x = list(map(int, input().split()))
    ans = 1000000000000
    for i in range(min(x), max(x)+1):
        total = 0
        for j in x:
            total += (i-j)**2
        if ans>total:
            ans = total
    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):

import numpy as np


def solve(*args: str) -> str:
    n = int(args[0])
    X = np.array(list(map(int, args[1].split())))

    ret = 10**10
    for i in range(1, 101):
        ret = min(ret, np.power((X-i), 2).sum())
    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Solution (Python):
words = lambda t : list(map(t, input().split()))
n = int(input())
xs = words(int)
ans = -1
for i in range(1,101):
    ttl = 0
    for x in xs:
        ttl += (i - x)**2
    if ans == -1:
        ans = ttl
    
    ans = min(ans,ttl)
print(ans)

Solution (Python):


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


M = max(l)

best = float("inf")
for i in range(M+1):
  HP = 0
  for j in l:
    HP += (j-i)**2
  if HP < best:
    best = HP


print(best)

Solution (Python):


N = int(input())
X = [el for el in map(int, input().split(' '))]
ans = 2 ** 63 - 1

for point in range(100):
    tmp = 0
    for x in X:
        tmp += (x - point) ** 2
    if ans > tmp:
        ans = tmp

print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
S = [0]*n
ans = 1000000000
for j in range(101):
    for i in range(n):
        S[i] = (x[i]-j)**2
    ans = min(ans, sum(S))
print(ans)

Solution (Python):
def near(x):
    if sum(x)/len(x)-sum(x)//len(x)>=0.5:
        return sum(x)//len(x)+1
    else:
        return sum(x)//len(x)

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

s=0
for i in range(len(x)):
   s+=(x[i]-near(x))**2
print(s)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ansList = []
for p in range(1, 101):
    ans = 0
    for j in range(n):
        ans += (x[j]-p)**2
    ansList.append(ans)
print(min(ansList))

Solution (Python):
import numpy as np

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

xmin = min(X)
xmax = max(X)

vmin = 1e6
for i in range(xmin, xmax+1):
    v = sum((np.array(X) - i) ** 2)
    if v < vmin:
        vmin = v

print(vmin)

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, X: "List[int]"):
    X.sort()
    
    ans = INF
    for p in range(101):
        ans = min(ans, sum([abs(X[i]-p)**2 for i in range(N)]))

    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    X = [int(next(tokens)) for _ in range(N)]  
    solve(N, X)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
xs = list(map(int, input().split()))
p = round(sum(xs) / n)
print(sum([(x - p)**2 for x in xs]))

Solution (Python):
N = int(input())
X_list = list(map(int, input().split()))
res = float('inf')
for i in range(101):
    tmp = sum([(X-i)**2 for X in X_list])
    res = min(res, tmp)
print(res)

Solution (Python):
input()
X = [int(x) for x in input().split()]
P = round(sum(X)/len(X))

S = 0
for x in X:
  S += (P-x)**2

print(S)

Solution (Python):
ninzuu = int(input())
a_list = list(map(int, input().split()))
min_zahyou = min(a_list)
max_zahyou = max(a_list)
ans = 0

for i in range(min_zahyou, max_zahyou+1):
  tmp_sum = 0
  for j in a_list:
    tmp_sum += (j-i)**2
  if ans == 0 or ans > tmp_sum:
    ans = tmp_sum

print(ans)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
ans=1000000000000
for i in range(min(x),max(x)+1):
  tmp=0
  for j in x:
    tmp += (j-i)**2
  if ans >= tmp:
    ans=tmp
print(ans)

Solution (Python):
n = int(input())
l = [int(x) for x in input().split()]
m = sum(l) / n
s = 0
sp = 0

if sum(l) % n == 0:
    now = sum(l) // n

    for x in l:
        s += (now - x) * (now - x)

    print(s)
    
else:
    now = sum(l) // n

    for x in l:
        s += (now - x) * (now - x)
        sp += (now - x + 1) * (now - x + 1)

    print(s if (s < sp) else sp)

Solution (Python):
N = int(input())
S=0
x = list(map(int, input().split()))
for i in range(N):
    S += x[i]

p = round(S/N)
s =0
for i in range(N):
    s+=(p-x[i])**2
print(s)

Solution (Python):

''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/g.inp"
exit $?
'''
import sys

def _i(): return int(sys.stdin.readline().strip())
def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

n = _i()
x = sorted(_ia())

ans = -1
for p in range(min(x), max(x)+1):
   tmp = 0
   for xx in x:
      tmp += (xx-p)**2
   if ans <0 or tmp<ans: ans= tmp
print(ans)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))

def f(X,P):
    ans=0
    for i in range(len(X)):
        ans+=(X[i]-P)**2
    return ans
ans=10**9
for p in range(1,101):
    ans=min(ans,f(X,p))
print(ans)

Solution (Python):
N=int(input())
X=list(map(int, input().split()))
min_s=1000000
for i in range(min(X),max(X)+1):
  s = sum([(j-i)**2 for j in X])
  min_s = min(min_s, s)
print(min_s)

Solution (Python):
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, *X = list(map(int, read().split()))

X = np.array(X)
P = X.sum() // N

ans = 10**8 + 7

for i in range(-1, 2):
    acc = X - (P + i)
    acc = acc**2
    acc = acc.sum()

    ans = min(ans, acc)

print(ans)

Solution (Python):
N=int(input())
lx=list(map(int,input().split()))
pav=sum(lx)/N
a=int(pav)
b=a+1
sa=0
sb=0
for i in range(N):
    sa+=(lx[i]-a)**2
    sb+=(lx[i]-b)**2
print(min(sa,sb))

Solution (Python):
n=input()
arr=[int(i) for i in input().split()]
arr.sort()
ansmin=99999999
for i in range(arr[0],arr[-1]+1):
    ans=0
    for j in arr:
        ans+=(i-j)**2
    ansmin=min(ansmin,ans)
print(ansmin)

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    X = [int(i) for i in readline().split()]

    m = sum(X) / N
    m = round(m)

    ans = 0
    for i in X:
        ans += (i - m)**2
    
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N = int(input())
    X = list(map(int, input().split(' ')))

    ans = []
    for p in range(100):
        dis = 0
        for x in X:
            dis += pow((x-p), 2)
        ans.append(dis)

    print(min(ans))

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
import math
N = int(input())
X = np.array(list(map(int, input().split())))

P_floor = math.floor(np.sum(X)/N)
P_ceil = math.ceil(np.sum(X)/N)

ans = min(np.sum((X-P_floor)**2), np.sum((X-P_ceil)**2))

print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
miner = 1000000000000
for p in range(1,101):
    cnt = 0
    for g in range(n):
        cnt += (x[g]-p)**2
    if cnt < miner:
        miner = cnt
print(miner)

Solution (Python):
N = int(input())
X = [int(n) for n in input().split()]
ans = 10000000
for n in range(101):
    p = 0
    for x in X:
        p += (x - n) ** 2
    ans  = min(p,ans)
print(ans)

Solution (Python):
import numpy as np
n = int(input())
x = list(map(int,input().split()))
x = np.array(x)
ans = 9999999
for i in range(1,101):
    ans = min(ans,sum((x-i)**2))

print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))

p1 = sum(x)//len(x)
p2 = p1 + 1
s1 = 0
s2 = 0
for i in x:
  s1 += (p1-i)**2
  s2 += (p2-i)**2
print(min(s1,s2))

Solution (Python):

import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    X = LMIIS()
    to2 = 0
    sumX = sum(X)
    for x in X:
        to2 += x**2
    
    P = round(sumX / N)
    

    print(to2 -2*sumX*P + N*P**2)


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
x = inl()
mn = 10**8
for p in range(1,101):
    sm = 0
    for j in range(n):
        sm += (x[j]-p)**2
    mn = min(mn,sm)
print(mn)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
ans=[]
for i in range(0,101):
  y=0
  for j in range(n):
    y+=(x[j]-i)**2
  ans.append(y)
print(min(ans))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))

ans=10**9
for i in range(101):
    cnt=0
    for j in range(N):
        cnt+=(X[j]-i)**2
    if cnt<ans:
        ans=cnt
print(ans)