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 = list(map(int, input().split()))
ans = float('inf')
for s in range(1,101):
    ans_pre = 0
    for i in x:
        ans_pre += (i-s)**2
    ans = min(ans,ans_pre)

print(ans)

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

for i in range(N):
    ans += (X[i] - ave) ** 2

print(ans)

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

center = round(sum(x) / len(x))
results = [(hp - center) ** 2 for hp in x]
print(sum(results))

Solution (Python):
def resolve():
    import numpy as np
    n=int(input())
    x_base=list(map(int,input().split()))
    x_base.sort()
    x=np.array(x_base)
    ans=10**10
    for i in range(x[0],x[-1]+1):
        if sum((x-i)**2) <=ans:
            ans=sum((x-i)**2)
    print(ans)
resolve()

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


li = []
p = 0
for i in range(1, 101):
    for j in range(n):
        p += (x[j] - i) ** 2

    li.append(p)
    p = 0

print(min(li))

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

ans = 100000000000000000

for i in range(1, 101):
  num = 0
  for j in range(N):
    num += (X[j]-i)**2
  ans = min(ans, num)
print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
h = [0, 0]

p = sum(x) // len(x)

for i in x:
    h[0] += (i - p)**2
    h[1] += (i - (p + 1))**2

print(min(h))

Solution (Python):

n = int(input())
xs = list(map(int, input().split()))
ans = 10 ** 9
for p in range(101):
    s = 0
    for x in xs:
        s += (x - p) ** 2
    ans = min(ans, s)
print(ans)

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

Solution (Python):
N=int(input())
X = list(map(int, input().split()))
X.sort()
p = X[0]
min_power = float('inf')
while p <= X[-1]:
  power = 0
  for x in X:
    power += pow((x-p),2)
  min_power = min(min_power, power)
  p += 1
print(min_power)

Solution (Python):
n = int(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))

Solution (Python):
n = int(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))

Solution (Python):
n = int(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))

Solution (Python):
import math


def inp():
    return(int(input()))


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


n = inp()
arr = invr()
arr = sorted(arr)
max = arr[n-1]
min = arr[0]

cost = 100000000000
for p in range(min, max+1):
    temp_cost = 0
    for xi in arr:
        temp_cost += (xi-p)**2
    if temp_cost < cost:
        cost = temp_cost
print(cost)

Solution (Python):
import statistics
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

n = int(input())

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

mean = statistics.mean(x)

syukai = Decimal(str(mean)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)



sum = 0

for i in range(len(x)):
    sum += (x[i] - syukai)**2

print(sum)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=10e8
for j in range(l[0],l[-1]+1):
    hp=0
    for i in l:
        hp+=(i-j)**2
    if ans>hp:
        ans=hp
print(ans)

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

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

Solution (Python):
N =int(input())
X = [int(i) for i in input().split()]
m = sum(X)//len(X)
mm = m+1

suma1 = 0
suma2 = 0
for i in X:
  suma1 += (i-m)**2
  suma2 += (i-mm)**2
print(min(suma1,suma2))

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

Solution (Python):
num = int(input())
lst = sorted(list(map(int, input().split())))
result = float('inf')
for i in range(lst[0], lst[-1] + 1):
    tmp = 0
    for v in lst:
        tmp += (v - i) ** 2
    if tmp < result:
        result = tmp
print(result)

Solution (Python):
from sys import stdin

n = int(stdin.readline().strip())
x_lst = [int(x) for x in stdin.readline().strip().split()]

p1 = sum(x_lst) // n
p2 = sum(x_lst) // n + 1

p1_sum = sum([(x-p1) ** 2 for x in x_lst])
p2_sum = sum([(x-p2) ** 2 for x in x_lst])

print(min(p1_sum, p2_sum))

Solution (Python):
N = int(input())

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

L = min(X)
R = max(X)

ans = 1000000

for i in range(L, R+1):
    tmp = 0
    for j in X:
        tmp += (j - i)**2
    ans = min(ans, tmp)

print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
X2SUM = sum([i**2 for i in X])
XSUM = sum([i for i in X])
minn = float('inf')
for i in range(1,101):
    minn = min(minn, X2SUM+-2*XSUM*i+N*(i**2))
print(minn)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
minx = min(x)
maxx = max(x)
list = []
for i in range(minx,maxx+1):
  klist = []
  for j in x:
    k = (j-i)*(j-i)
    klist.append(k)
  
  list.append(sum(klist))
print(min(list))

Solution (Python):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]

def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]

def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)

MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
X = LI()
max_x = max(X)
ans = INF
for i in range(1,max_x+1):
    temp = 0
    for j in X:
        temp += (j-i)**2
    ans = min(ans,temp)

print(ans)

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

small = min(x)
large = max(x)

ans = 1000000
for p in range(small,large+1):
    tmp = 0
    for i in x:
        tmp += (i -p)**2
    ans = min(ans, tmp)


print(ans)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))
ans = 10 ** 20
for i in range(1, 101):
  cont = 0
  for j in arr:
    cont += (j - i)**2
  ans = min(ans, cont)
print(ans)

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

for P in range(min(X),max(X)+1):
    tmp = 0
    for j in range(N):
        t = (X[j] - P)**2
        tmp += t
    ans.append(tmp)
print(min(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 += (x[i]-p)**2
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
import numpy as np
mn=min(a)
mx=max(a)

def lambda_d(ii):
  rr=0
  for jj in range(n):
    rr+=(a[jj]-ii)**2
  return rr

r=lambda_d(mn)
for ii in np.arange(mn,mx+1):
  tempr=lambda_d(ii)
  if tempr<r:
    r=tempr
print(r)

Solution (Python):
a=int(input())
list1=list(map(int, input().split()))
list2=[0]*max(list1)
for i in range(max(list1)):
    for j in range(a):
        list2[i]+=(list1[j]-(i+1))**2
print(min(list2))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
a = round(sum(x)/n)
ans = 0

for i in range(n):
    ans += (x[i] - a) ** 2

print(ans)

Solution (Python):
import sys

N = int(input())
X = sorted([int(i) for i in input().split()])
ub = X[N - 1]
lb = X[0]

ans = sys.maxsize
for i in range(lb, ub + 1):
    t = 0
    for j in X:
        t += (j - i) ** 2
    if t < ans:
        ans = t

print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
mx = max(X)
ans = float('inf')
for i in range(mx+1):
  tmp = 0
  for x in X:
    tmp += (x-(i+1))**2
  ans = min(ans, tmp)
print(ans)

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

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

P = round(sum(pos)/N)

print(sum([(i - P)**2 for i in pos]))

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

ans = 10 ** 9

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

for i in range(xmin, xmax + 1):
    tmp = 0
    for j in range(n):
        tmp += (X[j] - i) ** 2
    ans = min(ans, tmp)
print(ans)

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
x = nl()

mn = 100100100
for p in range(101):
  cnt = 0
  for xi in x:
    cnt += (p-xi)**2
  mn = min(mn, cnt)
print(mn)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
X.sort()
avg = sum(X) / N
avg_int = sum(X)// N

if avg-avg_int <= 0.5:
    m = avg_int
else:
    m = avg_int + 1

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

print(cnt)

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

min_p = min(X)
max_p = max(X)

ans = float("inf")
for p in range(min_p, max_p+1):
    hp = 0
    for i in range(N):
        hp += (X[i]-p)**2
    ans = min(ans, hp)
    
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 range(N):
        s+=(X[j]-i)**2
    ans = min(ans,s)
print(ans)

Solution (Python):
from operator import mul
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

    ans = INF
    x_min = min(X)
    x_max = max(X)
    for p in range(x_min, x_max + 1):
        tmp = 0
        for x in X:
            tmp += (x - p) ** 2
        ans = min(ans, tmp)
    
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    n = int(sys.stdin.readline())
    X = list(map(int,sys.stdin.readline().split()))
    ans = -1
    for i in range(1,max(X)+1):
        
        ans_tmp = 0
        for j in X:
            ans_tmp += (j - i)**2
        
        if ans > ans_tmp or ans == -1:
            ans = ans_tmp
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
dmin = 100000000
for i in range(min(x),max(x)+1):
  d = 0
  for j in x:
    d += (j-i)**2
  if d<dmin:
    dmin = d
print(dmin)

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

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

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

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
print(sum((i-int(sum(x)/n + 0.5))**2 for i in x))

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

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

s = sum(x)//n
ss = s+1

ans1 = sum((i-s)**2 for i in x)
ans2 = sum((i-ss)**2 for i in x)
print(min(ans1, ans2))

Solution (Python):
import numpy as np

def resolve():
    N = int(input())
    n_array = np.array(list(map(int,input().split())))
    mea = int(np.average(n_array) + 0.5)
    ans = n_array - mea 
    print(sum(ans*ans))
resolve()

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




tsukare = [0 for i in range(max(x)-min(x)+1)]




for i in range(min(x), max(x)+1):
    for k in range(len(x)):
        tsukare[i-min(x)] += (i-x[k])**2

print(min(tsukare))

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    x = list(map(int, input().split()))
    sum = 0
    for xi in x:
        sum += xi
    ans_1 = sum // n
    ans_2 = sum // n + 1
    score_1 = 0
    score_2 = 0
    for xi in x:
        score_1 += (xi - ans_1) ** 2
        score_2 += (xi - ans_2) ** 2
    print(min(score_1, score_2))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ans = -1
for n in range(min(X), max(X) + 1):
  cnt = 0
  for x in X:
    cnt += (x - n) **2
  if ans > 0:
    ans = min(ans, cnt)
  else:
    ans = cnt
print(ans)

Solution (Python):
n = int(input())
x_l = [int(x) for x in input().split()]
ans = float('INF')
for p in range(1,101):
    sumn = 0
    for j in range(n):
        sumn += (x_l[j]-p)**2
        if(ans<sumn):
            break
    
    if(ans>sumn):
        ans = sumn

print(ans)

Solution (Python):
from statistics import mean

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

check_list = range(1, 101)

life_list = []
for check in check_list:
    life = 0
    for x in X_list:
        life += (x - check)**2
    life_list.append(life)

answer = min(life_list)
print(answer)

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

Solution (Python):
import sys

stdin = sys.stdin

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


N = ni()
X = na()

minc = 99999999999999999

for i in range(1, 101):
    cost = 0
    for x in X:
        cost += (x-i)**2

    minc = min(cost, minc)

print(minc)

Solution (Python):


import numpy as np
def f(n, x):
    mean =  np.mean(x)
    s1 = sum((x-np.floor(mean))**2)
    s2 = sum((x-np.ceil(mean))**2)
    print(int(min(s1, s2)))

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

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

Xmax = max(X)
Xmin = min(X)

Pmin = 1000000
for i in range(Xmin, Xmax + 1):
    p = 0
    for x in X:
        p += (x - i) ** 2
        
    Pmin = min(Pmin, p)

print(Pmin)

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

ans = 1000000
for i in range(1,101):
    e = 0
    for j in x:
        e += (i-j)**2
    if ans > e:
        ans = e

print(ans)

Solution (Python):
import math

n = int(input())
x = list(map(int, input().split()))
p1 = math.floor(sum(x) / n)
p2 = math.ceil(sum(x) / n)

result_1 = 0
result_2 = 0
for i in range(n):
    result_1 += (x[i] - p1) ** 2
    result_2 += (x[i] - p2) ** 2
print(min(result_1,result_2))

Solution (Python):
import math

n=int(input())
x=list(map(int,input().split()))
a=(sum(x)/n)
b1=math.ceil(a)
b2=math.floor(a)

s1=0
s2=0
for i in range(n):
    k1=(x[i]-b1)**2
    k2=(x[i]-b2)**2
    s1+=k1
    s2+=k2
    
if s1<s2:
    print(s1)
else:
    print(s2)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
rec = []
for p in range(1,101):
    s = 0
    for i in x:
        s += (i-p)**2
    rec.append(s)
rec.sort()
print(rec[0])

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

for i in range(0,N):
     t += x[i]/N

s = round(t)
for i in range(0,N):
    min += (x[i] - s) **2

print(min)

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

for i in range(0,N):
     t += x[i]/N

s = round(t)
for i in range(0,N):
    min += (x[i] - s) **2

print(min)

Solution (Python):
N = int(input())
X = [int(i) for i in input().split()]
P = sum(X)/N
if P - int(P) <= 0.5:
    P = int(P)
else:
    P = int(P)+1
print(sum([(x-P)**2 for x in X]))

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
mini=999999999
for i in range(100):
    t=0
    for j in range(n):
        t+=pow(x[j]-1-i,2)
        
    mini=min(t,mini)
    
    
print(mini)

Solution (Python):
import sys
from io import StringIO
import unittest
from decimal import Decimal, ROUND_HALF_UP


def resolve():
    N = int(input())
    X = [int(i) for i in input().split()]
    p = int(Decimal(str(sum(X) / N))
            .quantize(Decimal("0"), rounding=ROUND_HALF_UP))
    sumXP = 0
    for xi in X:
        sumXP += (xi - p)**2
    print(sumXP)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
1 4"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7
14 14 2 13 56 2 37"""
        output = """2354"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

Solution (Python):


N = int(input())
X = [int(j) for j in input().split()]
X = sorted(X)
m = N * (100**2)
for i in range(min(X),max(X)+1):
    tmp = sum([(x-i) ** 2 for x in X])
    if tmp < m:
        m = tmp
print(m)

Solution (Python):

n = int(input())
x = list(map(int, input().split()))
s = sum(x)
s = s / n
if s * 10 % 10 >= 5:
    s = int(s) + 1
else:
    s = int(s)

ans = 0
for i in x:
    ans += (i - s)** 2
print(ans)

Solution (Python):

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

zahyo1=sum(x)//n
zahyo2=sum(x)//n+1

tairyoku1=0
tairyoku2=0
for i in range(n):
    tairyoku1+=(x[i]-zahyo1)**2
    tairyoku2+=(x[i]-zahyo2)**2

print(min(tairyoku1,tairyoku2))

Solution (Python):
N=int(input())
ans=[]
X=list(map(int,input().split()))
total=0

for i in range(101):
  for j in X:
    total+=(i-j)**2
  else:
    ans.append(total)
    total=0

print(min(ans))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
chushin = sum(A)//N
chushin_1 = sum(A)//N +1
answer = 0
answer_1 = 0
for a in A:
    answer += abs(a-chushin) ** 2
    answer_1 += abs(a-chushin_1) ** 2
print(min(answer,answer_1))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
answer = 10 ** 9
for i in range(1,101):
    tmp = 0
    for a in A:
        tmp += abs(a-i) ** 2
    answer = min(answer,tmp)
print(answer)

Solution (Python):
import itertools
import math
import fractions
import functools
n = int(input())
k = list(map(int, input().split()))

minimum = 1000
maximum = 0

for i in range(n):
    minimum = min(minimum,k[i])
    maximum = max(maximum,k[i])

minimum_ans = 10**9
for i in range(minimum, maximum + 1):
    sum = 0
    for j in range(n):
        sum += (k[j] - i)**2
    minimum_ans = min(minimum_ans,sum)

print(minimum_ans)

Solution (Python):

n = int(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)

Solution (Python):
n = int(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)

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

average = sum(x) / n
p = round(average)

exhaust = [(xi - p)**2 for xi in x]
print(sum(exhaust))

Solution (Python):
import collections
n,cc = int(raw_input()), collections.Counter(map(int, raw_input().split(' ')))
print min([sum([cc[k]*(k-p)*(k-p) for k in cc]) for p in range(1,100+1)])

Solution (Python):
n = int(input())
xs = list(map(int, input().split()))
m = min(xs)
M = max(xs)

ans = float('inf')
for i in range(m, M+1):
  result = 0
  for x in xs:
    result += (x-i) ** 2
  ans = min(ans, result)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = [0]*100
for i in range(100):
  ans = 0
  for j in range(N):
    a = A[j]
    ans += (i-a)**2
  B[i] = ans
print(min(B))

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    X = list(map(int, input().split()))
    assert N == len(X)
    P = round(sum(X)/len(X))
    print(sum([(i-P)**2 for i in X]))


if __name__ == '__main__':
    main()

Solution (Python):
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter

from functools import lru_cache

sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def comb(n, r):
    if n - r < r:
        r = n - r
    res = 1
    for i in range(r):
        res *= (n - i) % mod
        res %= mod
        res *= pow(r - i, mod - 2, mod)
        res %= mod
    return res


n = inp()
x = inpl()
left = min(x)
right = max(x)
ans = INF
for i in range(left, right + 1):
    tmp = sum([(j - i) * (j - i) for j in x])
    ans = min(ans, tmp)
print(ans)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
s = [i ** 2 for i in range(100)]
ans = 1001001
for i in range(1, 101):
    cost = sum([s[abs(x - i)] for x in X])
    ans = min(ans, cost)
print(ans)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
r = float('inf')
for p in range(1, 101):
    c = sum([(x - p) ** 2 for x in X])
    if c < r:
        r = c
print(r)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
 
ans = float('inf')  

for p in range(1,101):
 tmp = 0
 for x in X:
   tmp += (x-p)*(x-p)
 ans = min(tmp,ans)

print(ans)

Solution (Python):
a=2
n = int(input())
x = list(map(int, input().split())) 
ans =[]

for i in range(1,100+1):
    cost = 0
    for j in x:
        cost +=(i-j)**a 
        
    ans.append(cost)

print(min(ans))

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

sum = 0
for x in X:
    sum += x
avg = round(sum / n)

ans = 0
for x in X:
    ans += pow((x-avg), 2)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(100000000)




def main():
    n = int(input())
    x_ls = list(map(int, input().split()))

    sumx = sum(x_ls)
    sumx2 = sum([x**2 for x in x_ls])

    res = 10000000
    for p in range(1, 101):
        z = n* (p**2) -2*sumx*p + sumx2
        if z < res:
            res = z

    print(res)


main()

Solution (Python):
N = int(input())
X = [int(hoge) for hoge in input().split()]
curmin = 100000000000000
for x in range(1,101):
    score = sum([(p-x)**2 for p in X])
    curmin = min(score,curmin)
print(curmin)

Solution (Python):
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): 
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): 
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} 
def bitArr(n):
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1

n = readInt()
x = readInts()
x.sort()
ans = 100000000

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

print(ans)

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

s = 0

for i in range(len(x)):
    s += int(x[i])

    
p = round(s/n)

en = 0
for i in range(len(x)):
    en += (int(x[i])-p)**2

print(en)

Solution (Python):
INF = 1001001001

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

ans = INF
for i in range(1, 101):
    stamina = 0
    for j in range(1, N+1):
        stamina += (X[j-1] - i)**2
    ans = min(ans, stamina)

print(ans)

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

p=sum(x)/n
import math
p1=math.floor(p)
p2=math.ceil(p)
ans1=0
ans2=0

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

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

Solution (Python):
import sys
import math
import bisect

def query_value(A, m):
    ans = 0
    for a in A:
        ans += (m - a) ** 2
    return ans

def main():
    n = int(input())
    A = list(map(int, input().split()))
    min_val = 10 ** 18
    for i in range(1, 101):
        val = query_value(A, i)
        min_val = min(min_val, val)
    print(min_val)

if __name__ == "__main__":
    main()

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

hp = []
for p in range(min(X),max(X)+1):
  h = 0
  for x in X:
    h += (p-x)*(p-x)
  hp.append(h)
print(min(hp))

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

HP = []
for p in range(1, 101, 1):
    P = [p] * len(X)
    delta = sum([(i - j) ** 2 for (i, j) in zip(X, P)])
    HP.append(delta)

print(min(HP))

Solution (Python):
n=int(input())
xs=list(map(int,input().split()))
p=sum(xs)//n
hp,hq=0,0
for i in xs:
    hp+=(i-p)**2
    hq+=(i-p-1)**2
print(min(hp,hq))

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

a = round(sum(X)/N)
c = 0

for i in range(N):
  c += (X[i] - a)**2
  
print(c)

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

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

average = [sum(X)//N,(sum(X)//N)+1]

ans = 0

check = [[],[]]

for i in range(2):
    for j in X:
        a = (abs(j-average[i]))**2
        check[i].append(a)

if sum(check[0]) <= sum(check[1]):
    print(sum(check[0]))
else:
    print(sum(check[1]))

Solution (Python):

n = int(input())
x = list(map(int, input().split(" ")))
print(min([ sum(map(lambda x: (x-p)**2, x)) for p in range(min(x), max(x) + 1)] ))

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

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


ans = float("inf")
for i in range(1,101):
    conf_site = i
    total = sum([(x - conf_site)**2 for x in X])
    ans = min(ans, total)

print(ans)

Solution (Python):
import math
n = int(input())
A = list(map(int,input().split()))
count = 0
for i in A:
    count +=i
ave = count/n
f,i = math.modf(ave)
answer = 0
if f >=0.5:
    a = i + 1
    for i in A:
        answer += (i-a)**2
else:
    a = i
    for i in A:
        answer +=(i-a)**2
print(int(answer))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
X_a = max(a)
N_a = min(a)
L_a = X_a - N_a + 1
b=[0]*L_a

while True:
  if N_a >= X_a:
    break
  for k in range(1,L_a+1):
    for i in a:      
      b[k-1] += (i-N_a)*(i-N_a)
    N_a +=1
print(min(b))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
X_a = max(a)
N_a = min(a)
L_a = X_a - N_a + 1
b=[0]*L_a

while True:
  if N_a >= X_a:
    break
  for k in range(1,L_a+1):
    for i in a:      
      b[k-1] += (i-N_a)*(i-N_a)
    N_a +=1
print(min(b))

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

ave = sum(x) // n

r, l = 0, 0
for a in x:
    r += (a - ave)**2
    l += (a - ave - 1)**2

print(min(r, l))

Solution (Python):
n=int(input())
x_list=list(map(int,input().split()))
ans=10000000
for i in range(101):
    tem=0
    for k in x_list:
        tem+=(k-i)**2
    ans=min(tem,ans)
print(ans)

Solution (Python):
N = int(input())
x = list(map(int,input().split()))
l =[]
dis = 0
for i in range(1,max(x)+1) :
    for a in x:
        dis += (i-a)**2
    l.append(dis)
    dis = 0
print(min(l))

Solution (Python):
n = int(input())
L = list(map(int,input().split()))
min1 = 10**10

for p in range(101):
    en = 0
    for i in range(n):
        en += (L[i]-p)**2
    min1 = min(min1,en)
print(min1)