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):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): 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 LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	X = LI()
	m = round(sum(X) / N)
	ans = 0
	for x in X:
		ans += ((x-m)**2)
	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): 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 LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	X = LI()
	X = np.array(X)
	m = round(np.sum(X) / N)
	print(int(np.sum((X-m)**2)))

if __name__ == '__main__':
	main()

Solution (Python):
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): 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 LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	X = LI()
	X = np.array(X, dtype="int32")
	m = round(np.sum(X) / N)
	print(int(np.sum((X-m)**2)))

if __name__ == '__main__':
	main()

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

Solution (Python):
n = int(input())
xs = tuple(map(int, input().split()))

ret = min(
    sum(
        (x - p) * (x - p)
        for x in xs
    ) for p in range(1, 100 + 1)
)

print(ret)

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

min_n = min(X_list)
max_n = max(X_list)
min_cost = 10**16

for n in range(min_n,max_n+1):
    cost = 0
    for x in X_list:
        cost = cost + (x - n)**2
    min_cost = min(min_cost, cost)

print(min_cost)

Solution (Python):
_,x=open(0);print(min(sum((i-int(j))**2for j in x.split())for i in range(99)))

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
m=sum(l)/n
if m-int(m) < 0.5:
  m=int(m)
else:
  m=int(m)+1
print(sum([(k-m)**2 for k in l]))

Solution (Python):
_,x=open(0);print(min(sum((i-int(j))**2for j in x.split())for i in range(99)))

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

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

Solution (Python):

N = int(input())

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

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

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

print(ans)

Solution (Python):
import sys
import numpy as np

read = sys.stdin.read

N, *X = map(int, read().split())
X = np.array(X, np.int64)
n = np.arange(X.max() + 1)
answer = (X.reshape(-1, 1) - n) ** 2
answer = answer.sum(axis=0)
print(answer.min())

Solution (Python):
N = int(input())
X_list = list(map(int, input().split()))
min1 = 10**9
for i in range(100):
    tmp = 0
    for j in range(N):
        tmp += (X_list[j]-i)**2
    if min1 > tmp:
        min1 = tmp
print(min1)

Solution (Python):

import sys


def solve(N: int, X: "List[int]"):
    p = round(sum(X) / len(X))
    ans = sum([(x - p)**2 for x in X])
    print(ans)

    



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())
x = list(map(int, input().split()))
avg = round(sum(x) / n)
ans = 0
for xi in x:
    ans += (xi - avg) ** 2
print(ans)

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

p=sum(x)/n
if p-(sum(x)//n)<0.5:
    p=sum(x)//n
else:
    p=(sum(x)//n)+1

ans=[]
for i in range(n):
    ans.append((x[i]-p)**2)
print(sum(ans))

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
a=round(sum(l)/n)
k=0
for j in l:
  k+=(j-a)**2
print(k)

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

min = 1000000
result = 0
for i in range(100):
    for j in X:
        result += (i + 1 - j) ** 2
    if min > result:
        min = result
    result = 0

print(min)

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

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
x_max = max(x)
x_min = min(x)
sum_dif_ls =[]
for i in range(x_min, x_max+1):
    sum_dif = 0
    for j in x:
        dif = (i - j)**2
        sum_dif += dif
    sum_dif_ls.append(sum_dif)

print(min(sum_dif_ls))

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

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()
arr=limii()
ans=10**1000
for i in range(100):
    cnt=0
    for j in range(n):
        cnt+=(arr[j]-(i+1))**2
    ans=min(ans,cnt)
print(ans)

Solution (Python):
_ = int(input())
x = list(map(int,input().split()))
def p(m):
  l = [] 
  for i in x:
    s = (i-m)**2
    if s < 0:
      l.append(-s)
    else:
      l.append(s)
  return(sum(l))
a = [p(i) for i in range(100)]
print(min(a))

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

N = int(input())
X = [int(x) for x in input().split()]
P = int(sum(X) / N + 0.5)
total = 0
for x in X:
  kyori = (x - P) * (x - P)
  total += kyori
print(total)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
p = round((1/n) * sum(x))

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

print(ans)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
p=0
for i in range(n):
    p+=2*x[i]
  
p1=p//(2*n)
p2=p1+1

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

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

wa=[]
for p in range(1,101):
    T=[]
    for i in range(0,N):
        T.append((X[i]-p)**2)
    wa.append(sum(T))

print(min(wa))

Solution (Python):
def slv(x, p):
    return (x-p)**2
n = int(input())
X = list(map(int, input().split()))
m = 10**6
mx = max(X)
for i in range(0, mx+1):
    t = 0
    for j in X:
        t += slv(j, i)
    if t < m:
        m = t

print(m)

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

N = int(input())
X = [int(x) for x in input().split()]
P = int(sum(X) / N + 0.5)
total = 0
for x in X:
  kyori = (x - P) * (x - P)
  total += kyori
print(total)

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

X.sort()
top = X[-1]
bot = X[0]
lowest = 1145141919810112231231231231081081081081072072072

for i in range(bot, top+1):
  cal = 0
  for x in range(N):
    cal += (X[x] - i)**2
  
  if cal < lowest:
    lowest = cal
    
print(lowest)

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

    x_ave = sum(X) // N
    return min(sum([(x - (x_ave + p))**2 for x in X]) for p in (0, 1))

print(c_rally())

Solution (Python):
n = int(input())
index = list(map(int, input().split()))
energy = []
for p in range(min(index), max(index)+1):
    sum = 0
    for xi in index:
        sum += (xi-p)**2
    energy.append(sum)
print(min(energy))

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())
X = list(map(int, input().split()))

lower = min(X)
upper = max(X)

min_shouhi = 0
asn_zahyou = 0
for zahyou in range(lower, upper):
    shouhi = 0
    for i in range(N):
        shouhi += (X[i] - zahyou)**2
    
    if zahyou == lower:
        min_shouhi = shouhi
        asn_zahyou = zahyou
    else:
        if min_shouhi > shouhi:
            min_shouhi = shouhi
            asn_zahyou = zahyou

print(min_shouhi)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))
m = 1000000000000000
for p in range (1, max(arr)+1):
  r = 0
  for i in arr:
    r += (p-i)**2
  m = min(m, r)
print(m)

Solution (Python):
n = int(input())
r = list(map(int, input().split()))
old = None
for x in range(min(r), max(r)+1):
  t = sum([(i - x) ** 2 for i in r])
  if not old:
      old = t
      continue
  if t < old:
    old = t
print(old)

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

ans=10**10
for i in range(min(X),max(X)+1):
  p=0
  for j in range(len(X)):
    p+=(X[j]-i)**2
  if p<ans:
    ans=p
print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
A = []
for P in range(1, max(X)+1):
    S = 0
    for i in range(N):
        S = S + (X[i]-P)**2
    A.append(S)

print(min(A))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
sum = 0
all = True
for a in X:
    sum = sum + a
C = int(sum / N + 0.5)
ans = 0
for b in X:
    ans = ans + (b-C)**2
print(ans)

Solution (Python):
P=int(input())
X=list(map(int,input().split()))
l=[]
for j in range(min(X),max(X)+1):
    ans = [(i-j)**2 for i in X ]
    l.append(sum(ans))
print(min(l))

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
d = []
for i in range(min(x), max(x)+1):
  a = 0
  for j in x:
    a += (j - i)**2

  d.append(a)
print(min(d))

Solution (Python):
def rally(n, x):
    if not len(x) == n:
        return "==== pleas input based on n times in one line ===="
    else:
        mini = round(sum(x)/n)
        new_list = []
        for i in x:
            r = (i - mini)**2
            new_list.append(r)
        return (sum(new_list))


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

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

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

Solution (Python):


iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = int(input())
    X = list(iim())

    av = (2 * sum(X) + N) // N // 2
    ans = 0
    for x in X:
        ans += (x - av)**2
    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):
N = int(input())
X=list(map(int, input().split())) 
X_max = max(X)
X_min = min(X)
 
answerlist = []
for i in range(X_min,X_max+1):
  newX = [(n-i)**2 for n in X]
  total = sum(newX)
  answerlist.append(total)
  
print(min(answerlist))

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

p = sum(x) / N
p0 = p - int(p)

if p0 <= 0.5:
    p = int(p)
else:
    p = int(p) + 1

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

print(ans)

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

for p in range(101):
    cost.append(0)
    for person in people:
      cost[-1]+=(person-(p+1))**2

print(min(cost))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
A = []
for P in range(1,max(X)+1):
    for i in range(N):
        A.append((X[i]-P)**2)
    if sum(A[0:N]) <= sum(A[N:2*N]) or len(A) == N:
        A = A[0:N]
    else:
        A = A[N:2*N]
print(sum(A))

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

ans = 100000000
for i in range(100):
  cost = 0
  for j in range(len(A)):
    cost += (A[j] - i) *(A[j] - i)
  ans = min (ans,cost)
print(ans)

Solution (Python):
import numpy as np
N = int(input())
X = np.array(list(map(int, input().split())))
x = int(np.sum(X) / N + 0.5)
print(np.sum(np.square(X - x)))

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

Max = max(X)
p_min = 1000000
for i in range(1, 101):
    p = 0
    for j in range(len(X)):
        p += (X[j] - i)**2
    if  p < p_min:
        p_min = p
    else:
        p_min = p_min
print(p_min)

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

Max = max(X)
p_min = 1000000000
for i in range(1, 101):
    p = 0
    for j in range(len(X)):
        p += (X[j] - i)**2
    if  p < p_min:
        p_min = p
    else:
        p_min = p_min
print(p_min)

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

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

ans = 100 ** 2 * 100
for i in range(X[0], X[-1] + 1):
    work = 0
    for x in X:
        work += (x - i) ** 2
    ans = min(ans, work)

print(ans)

Solution (Python):
n,*a=map(int,open(0).read().split());print(sum((round(sum(a)/n)-i)**2 for i in a))

Solution (Python):
input()
l=list(map(int, input().split()))
m=round(sum(l)/len(l))

print(sum((m-i)**2 for i in l))

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

a = min(X)
b = max(X)

ans = []

for i in range(a,b+1):
  S = 0
  for j in range(N):
    S += (X[j]-i)**2

  ans.append(S)
  
print(min(ans))

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]
X.sort()
P = [[0 for i in range(N)] for _ in range(101)]
for p in range(101):
  for i, x in enumerate(X):
    P[p][i] = (x - p) ** 2
print(min([sum(p) for p in P[1:]]))

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

Solution (Python):
n,*x=map(int,open(0).read().split())
ans=float("inf")
for p in range(0,101):
  s=0
  for xi in x:
    s+=(xi-p)**2
  ans=min(ans,s)
print(int(ans))

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


def cost(live_pos, held_pos):
    return (live_pos - held_pos) ** 2

mean_pos = round(sum(live_pos_list) / n)
print(sum(map(lambda live_pos: cost(live_pos, mean_pos), live_pos_list)))

Solution (Python):

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

a = []
for pp in range(1,101):
    sum = 0
    for xx in x:
        sum += abs((xx-pp) ** 2)
    a.append(sum)

print(min(a))

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

ans = float('inf')
for i in range(1, 101):
  temp = 0
  for z in x:
    temp += (z - i) ** 2
  ans = min(temp, ans)

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline

N = int(input())
X = list(map(int, input().split()))
ans = []
for i in range(1, 101):
    cost = 0
    for value in X:
        cost += (value - i)**2
    ans.append(cost)

print(min(ans))

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

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

c=0
for i in l:
    c+=i

c=c//n
c1 = c+1 



ans=0
for i in l:
    ans+=(c-i)*(c-i)
    
ans1=0
for i in l:
    ans1+=(c1-i)*(c1-i)
print(min(ans,ans1))

Solution (Python):
N = int(input())
XXX = input().split()

xList = []
for i in XXX:
  xList.append(int(i))

dList = []
for P in range(0,max(xList)+1):
  D = 0
  for xi in xList:
    D += (xi - P)*(xi - P)
  dList.append(D)

result = min(dList)

print(result)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
a = sum(x)/n
if a-int(a) < 0.5:
  aa = int(a)
  print(sum([(xi-aa)**2 for xi in x]))
else:
  aa = int(a)+1
  print(sum([(xi-aa)**2 for xi in x]))

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

    x_sum = sum(X)
    option = (x_sum // N, (x_sum + N - 1) // N)
    return min(sum([(x - p)**2 for x in X]) for p in option)

print(c_rally())

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

P = float(sum(X) / N)
P = round(P, 0)

T = 0

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


print(int(T))

Solution (Python):
n=int(input())
l= list(int(i) for i in input().split())
a=round(sum(l)/n)
k=0
for j in l:
  k+=(j-a)**2
print(k)

Solution (Python):

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

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

ans = 10 ** 18
ind= -1
for p in range(0, 101):
    tmp = 0
    for num in x:
        tmp += (num - p) ** 2
    if tmp < ans:
        ans = tmp
        ind = p
print(ans)

Solution (Python):
n=int(input())
l= list(int(i) for i in input().split())
a=round(sum(l)/n)
k=0
for j in l:
  k+=(j-a)**2
print(k)

Solution (Python):
import os
import sys

import numpy as np
from scipy.optimize import fmin

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



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

X = np.array(X, dtype=int)


def calc(p):
    return ((X - p) ** 2).sum()


ans = INF
for i in range(200):
    ans = min(ans, calc(i))


y, = fmin(calc, x0=0, disp=False)
print(int(calc(round(y))))

Solution (Python):
n=int(input())
l= list(int(i) for i in input().split())
a=round(sum(l)/n)
k=0
for j in l:
  k = k + (j-a)**2
print(k)

Solution (Python):
n=int(input())
l= list(int(i) for i in input().split())
a=int(round(sum(l)/n))
k=0
for j in l:
  k = k + (j-a)**2
print(k)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
imax=int(max(x))
imin=int(min(x))
lis=[]
re=0
for k in range(imax+1):
  for i in x:
    re=re+(i-k)**2
  lis.append(re)
  re=0
print(min(lis))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
imax=int(max(x))
imin=int(min(x))
lis=[]
re=0
for k in range(imin,imax+1):
  for i in x:
    re=re+(i-k)**2
  lis.append(re)
  re=0
print(min(lis))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
x.sort()
z = 10**100
for p in range(x[0],x[-1]+1):
    temp = 0
    for xx in x:
        temp += (xx-p)**2
    z = min(temp,z)
print(z)

Solution (Python):
import math
from statistics import mean, median,variance,stdev
N = int(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)

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

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

ans = 0
ans_sum = 0

for P in range(Xmin,Xmax+1):
  for i in range(N):
    cal = (X[i] - P)**2
    ans_sum = ans_sum + cal
  if P == Xmin:
    ans = ans_sum
    ans_sum = 0
  elif ans >= ans_sum:
    ans = ans_sum
    ans_sum = 0
  else :
    ans_sum = 0
print(ans)

Solution (Python):
n = int(input())
people = list(int(i) for i in input().split())
min_s = 0
av = int(round(sum(people) / n))
for s in people: 
  min_s = min_s + (s - av)**2
print(min_s)

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

Solution (Python):
n = int(input())
lst = [int(x) for x in input().split()]

num = sum(lst)//n
sum1 = 0
sum2 = 0

for i in lst:
  sum1 += (i-num)**2
  sum2 += (i-num-1)**2
  
if sum1 < sum2:
  print(sum1)
else:
  print(sum2)

Solution (Python):

n = int(input())
x = list(map(int, input().split()))
xmax = max(x)
xmin = min(x)
ans=[]
a=0
for i in range(xmin,xmax+1):
    for j in x:
        a+=(j-i)**2

    ans.append(a)
    a=0
print(min(ans))

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

Solution (Python):
N=int(input(""))
l=input("").split()
L=[int(n) for n in l]
max=max(L)
min=min(L)
min_shohi=1000000
for P in range(min,max+1):
    shohi=0
    for x in L:
        shohi+=(x-P)**2
    if shohi<min_shohi:
        min_shohi=shohi
print(min_shohi)

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
mean_val = int(round(sum(X)/len(X)))
total_stamina = sum((val-mean_val)**2 for val in X)
print(total_stamina)

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

Solution (Python):
import math

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

p = 0
sum = 0

for i in range(n):
    p += x[i]

p = round(p/n)

for j in range(n):
    sum += (x[j] - p)**2

print(sum)

Solution (Python):



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

sig=0
for i in range(N):
    sig+=X[i]

sig_2=0
for i in range(N):
    sig_2+=X[i]**2

min=10**10
med=X[0]
while True:
    sum=N*med**2-2*med*sig+sig_2

    if sum<min:
        min=sum
        prev=sum
        med+=1
    else:
        break

print(prev)

Solution (Python):
N = int(input())
A = sorted(map(int, input().split()))

ave = int(sum(A) / len(A))
tmp = sum(A) / len(A)
if(tmp > ave + 0.5):
    ave += 1
ans = 0
for i in range(N):
    ans += (A[i] - ave)**2
print(ans)

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

Solution (Python):
import sys
from functools import reduce

n = int(input())
x = list(map(int, input().split()))
l = ((i, reduce(lambda a, j: a + (x[j] - i) * (x[j] - i), range(0, n), 0)) for i in range(1, 100 + 1))
print(min(l, key=lambda x: x[1])[1])

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
s=0
sum=0
for i in X:
    sum+=i

sum=round(sum/len(X))

for i in X:
    tmp=(i-sum)**2
    s+=tmp
print(s)

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

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

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

best = float('inf')
for c in range(0, 101):
    cost = 0
    for x in XS:
        cost += (x - c) * (x - c)
    best = min(cost, best)
print(best)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = []
CCC = 0
j = 1
max_A = max(A)
for j in range(101):
    if j == 0:
        continue
    CCC = 0
    for k in range(N):
        CCC += (A[k] - j) ** 2
    B.append(CCC)
x = min(B)
print(x)

Solution (Python):
import statistics

def cal_hp(p, num_list):
    total = 0
    for num in num_list:
        temp = (num - p) ** 2
        total = total + temp
    return total

line1 = input()
line2 = input()

num_list = line2.split(" ")
num_list = [int(n) for n in num_list]
ans_list = []

for i in range(0, max(num_list)+1):
    ans_list.append(cal_hp(i, num_list))
print(min(ans_list))

Solution (Python):
N = int(input())
A = list(map(int , input().split()))
bb = -(-sum(A)//N)
cc = sum(A)//N
ans = 0
ans_ = 0
for i in range(len(A)):
    ans += (A[i]-bb)**2
for i in range(len(A)):
    ans_ += (A[i]-cc)**2
print(min(ans,ans_))

Solution (Python):
n = int(input())
s = input().split()

sum = 0
for i in range(n):
  sum += int(s[i])

a = float(sum)/float(n)
if int(a)+0.5 <= a:
  a = int(a)+1
else:
  a = int(a)
  
ans = 0
for i in range(n):
  ans += (int(s[i])-a)**2

print(ans)

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

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

minx = min(list_x)
maxx = max(list_x)
sums_list = []

for i in range(minx, maxx+1):
    sums = 0
    for j in list_x:
        sums += (j - i)**2
    sums_list.append(sums)

print(min(sums_list))

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

Solution (Python):
from sys import maxsize

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

min = maxsize
for i in range(1, 101):
    hp = sum([(k-i)**2 for k in x])
    if hp < min:
        min = hp

print(min)

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

sumlist = []

if len(set(x)) == 1:
    print(0)
else:
    for i in range(1, max(max(x), n)):
        s = 0
        for j in range(n):
            s += (x[j] - i) ** 2
        sumlist.append(s)

    if sumlist == []:
        print((x[0] - n) ** 2)
    else:
        print(sorted(sumlist)[0])

Solution (Python):
import math

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


def summ(ii):
    xxx = 0
    for x in X:
        xxx += (x - ii) ** 2
    return xxx


i1 = math.ceil(sum(X) / N)
i2 = math.floor(sum(X) / N)

if i1 == i2:
    print(summ(i1))
else:
    print(min(summ(i1), summ(i2)))

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

xlist.sort()





s = sum(xlist)
p = round(s / n)
add_x = 0
for i in range(n):
    add_x = add_x + (xlist[i] - p) ** 2

print(add_x)

Solution (Python):
import math
import decimal
def main():
    n = int(input())
    x = input().split()
    x = [int(t)for t in x]
    
    x_ = sum(x)
    p = round(x_/n)

    s = [(t-p)*(t-p)for t in x]
    print(sum(s))


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

def resolve():
    input()
    x = list(map(int, input().split()))
    m = int(round(np.mean(x)))
    sum = 0
    for val in x:
        sum += (val - m) ** 2
    print(sum)

if __name__ == '__main__':
    resolve()

Solution (Python):
import numpy as np
N=int(input())
X = list(map(int,input().split()))
X.sort()
a=list()
c=N-1
for i in range(X[0],X[c]+1):
    b=0
    for j in range(0,N):
        if i-X[j]>10**5:
            break
        b+=(i-X[j])**2
    a.append(b)
print(min(a))

Solution (Python):
num=int(input())
s=input().split()
res=float('inf')
for j in range(1,101):
  temp=0
  for k in s:
    temp+=(int(k)- j)**2
  if temp < res:
    res = temp
print(res)

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

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

Physical_strength = 0
flag = 0
n=0
while 1:
    n += 1
    flag=0
    for Xi in X:
        flag += (Xi-n)**2
    if n == 1:
        Physical_strength = flag
    if Physical_strength > flag:
        Physical_strength = flag
    elif Physical_strength < flag and n > N:
        break

print(Physical_strength)

Solution (Python):
N = int(input())
x  = [int(x) for x in input().split()]
x.sort()
ans = 10**10
for l in range(100):
  ans1 = 0
  for i in x:
    ans1+=(i-l)**2
  ans = min(ans1,ans)
print(ans)

Solution (Python):
import math

N = int(input())
Xs = input().split(' ')
X = []
for i in range(N):
  X.append(int(Xs[i]))
  
 
minimizeP = sum(X)/N
P_floor = math.floor(minimizeP)
P_ceil = math.ceil(minimizeP)
minP1 = 0
minP2 = 0
X.sort()
for i in X:
  minP1 = minP1 + (i - P_floor) ** 2
  minP2 = minP2 + (i - P_ceil) ** 2
  
print(min(minP1,minP2))

Solution (Python):
def ans(n,x):
    answer=0 
    f=[]
    for i in range(min(x),max(x)+1):
        s=0
        for j in x:
            s+=(j-i)**2 
        f.append(s)
    print(min(f))
            
n=int(input())
x=[int(x) for x in input().split()]
ans(n,x)

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

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

ans_1 = 0
ans_2 = 0
x_sum = sum(x_list)

x_sum = x_sum // n

for x in x_list:
    ans_1 += (x-x_sum)**2
    ans_2 += (x-x_sum - 1)**2
    continue

print(min(ans_1,ans_2))

Solution (Python):
N = int(input())
P = 0
res = []
stamina = 0

ls = input().split()
for i in range(0, len(ls)):
  ls[i] = int(ls[i])
  
for i in range(0, 100):
  P = P + 1
  for j in range(0, len(ls)):
  	stamina = stamina + (ls[j] - P)**2
  res.append(stamina)
  stamina = 0

print(min(res))

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