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()))
p = int(sum(x)/len(x))
ans1 = sum(map(lambda a:(a-p)**2, x))
ans2 = sum(map(lambda a:(a-p-1)**2, x))

if ans1 > ans2:
    print(ans2)
else:
    print(ans1)

Solution (Python):
_=input()
a=list(map(int,input().split()))
b=round(sum(a)/len(a))
res=0
for i in a:
    res+=(i-b)**2
print(res)

Solution (Python):
def rally(n , xl):

    ans = 0

    aaa = round(sum(xl) / n)

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

    return ans

def main():
    n = int(input())
    xl = list(map(int , input().split()))
    print(rally(n , xl))

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
sum = 0
min_sum = 100000000
P = 1
while P <= 100:
  for n in X:
    sum = sum +(n-P)**2
  if sum <= min_sum:
    min_sum = sum
  P = P + 1
  sum = 0
print(min_sum)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
def P(n):
    return sum([(X[i]-n)**2 for i in range(0,N)])
l=[P(i) for i in range(1,101)]
print(min(l))

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

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

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

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

for i in range(max(X) + 1):
    for a in X:
        b = b + pow((a - i),2)
    Z.append(b)
    b = 0

print(min(Z))

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

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

if N%n ==0:
	print(ans)
else:
	print(min(ans,ans+n-2*N+2*(N//n)*n))

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

mini, maxi = min(x), max(x)
min2, max2 = mini**2*n, maxi**2*n
ans = max2 if max2 > min2 else min2

for p in range(mini, maxi+1):
  suma = 0
  for z in x:
    suma += (z-p)**2
  if ans > suma:
    ans = suma
    
print(ans)

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

X.sort()

ans = 0

for i in range(X[-1] - X[0] + 1):
    tmp = 0
    for j in X:
        tmp += (j - (X[0] + i))**2
    
    if i == 0:
        ans = tmp
    else:
        if ans > tmp:
            ans = tmp

print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
s = 0
for i in range(1,101):
    temp = 0
    for j in range(N):
        temp += (i - X[j])**2
    if i == 1:
        s = temp
    elif s < temp:
        pass
    elif s >= temp:
        s = temp
print(s)

Solution (Python):
import numpy as np
N = int(input())
X = [int(i) for i in input().split()]
X = np.array(X)
res = 100**100
for i in range(max(X+1)):
    tmp = sum((abs(X-i))**2)
    
    if res > tmp:
        res = tmp
print(res)

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

def answer(n,l):
    ans = 10000000
    tmp = 0
    for i in range(min(l),max(l)+1):
        tmp = 0
        tmp_L = map(lambda x:(x-i)**2,l)
        tmp = sum(tmp_L)
        if ans >= tmp:
            ans = tmp
    return(ans)        
print(answer(N,L_X))

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

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
s = 0
for i in range(1,101):
    temp = 0
    for j in range(N):
        temp += (i - X[j])**2
    if i == 1:
        s = temp
    elif s < temp:
        pass
    elif s >= temp:
        s = temp
print(s)

Solution (Python):
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  x = list(int(i) for i in input().split())
  ans = 10**15
  for i in range(1,101):
    score = 0
    for j in range(n):
      score += (x[j]-i)**2
    ans = min(ans,score)    
  print(ans)
solve()

Solution (Python):
import numpy as np
N=int(input())
n = np.array([int(i) for i in input().split()])
n=n-int(round(np.sum(n)/N))
print(np.sum(n*n))

Solution (Python):
import numpy as np
N=int(input())
n = np.array([int(i) for i in input().split()])
n=n-int(round(sum(n)/N))
print(sum(n*n))

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

s=float("inf")
for i in range(min(X),max(X)+1):
   d=0
   for j in X:
      d+=(j-i)**2
   s=min(s,d)
print(s)

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

ans = 1000000
for p in range(X[0], X[-1]+1):
    health = 0
    for i in X:
        health += (p-i)**2

    ans = min(ans, health)

print(ans)

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

p = sum(x)/N

q = int(p)

ans1 = 0
ans2 = 0
for i in range(N):
	ans1 += (x[i]-q)*(x[i]-q)
	ans2 += (x[i]-q-1)*(x[i]-q-1)
print(min(ans1,ans2))

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

Solution (Python):
INF = 10**10

def solve(n, x):
    best = INF
    for p in range(min(x), max(x)+1):
        cost = sum((xi-p)**2 for xi in x)
        best = min(best, cost)
    return best

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

Solution (Python):
a=int(input())
lis=sorted(list(map(int , input().split())))
ans=float('inf')
ans2=0
for i in range(lis[-1]):
  for j in lis:
    ans2+=(j-(i+1))**2
  if ans>ans2:
    ans=ans2
  ans2=0
print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
s = [0] * (max(x) - min(x) + 1)
ans = 0

for p in range(min(x),max(x)+1):
    for j in range(n):
        s[p - x[0]] += (x[j] - p)**2

ans = min(s)
print(ans)

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

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

def calc(center):
    ret = 0
    for a in A:
        ret += (a - center)**2
    return ret

ans = 10**10
for c in range(min(A), max(A) + 1):
    ans = min(ans, calc(c))

print(ans)

Solution (Python):
def main():
	k = int(input())
	a = list(map(int,input().split()))
	
	minans = []
	minlist = []
	for i in range(100):
		for s in range(k):
			minans.append((a[s] - i)**2)
		minlist.append(int(sum(minans)))
		minans = []
	print(min(minlist))
		
	
	
 
if __name__ == '__main__':
	main()

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
ans = 10**7
for p in range(1,101):
    res = 0
    for x in X:
        res += (x-p) ** 2
    ans = min(ans, res)
print(ans)

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

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

for i in arr:
  ans+= ((i-aprx)**2)
  
  
  
print(ans)

Solution (Python):
import numpy as np
n=int(input())
x=np.fromstring(input(),int,sep=' ')
p=0
hoge=np.inf
for i in range(1,np.max(x)+1):
    sux=sum((x-i)**2)
    if sux<hoge:
        p=i
        hoge=sux
print(hoge)

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

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

    P = sum(X) // N
    ans1 = 0
    for x in X:
        ans1 += (x - P) ** 2
    ans2 = 0
    for x in X:
        ans2 += (x - (P + 1)) ** 2
    print(min(ans1, ans2))


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
min_tairyoku_sum = float("inf")
for i in range(1,101):
    tairyoku_sum = 0
    for x in X:
        tairyoku_sum += (x - i) ** 2
    min_tairyoku_sum = min(tairyoku_sum, min_tairyoku_sum)
print(min_tairyoku_sum)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
a=sum(x)//n
ans=0
anss=0
for i in x:
  ans=ans+(i-a)**2
a=a+1
for i in x:
  anss=anss+(i-a)**2
if anss < ans:
  ans=anss
print(ans)

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

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

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

ave = sum(x)/n
y0 = int(ave)
z0 = sum([(i-y0)**2 for i in x])
y1 = y0+1
z1 = sum([(i-y1)**2 for i in x])

print(min(z0, z1))

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

Solution (Python):
n = int(input())
x = [int(t) for t in input().split()]
ans = 10 ** 9
for i in range(1, 101):
    sum = 0
    for xi in x:
        sum += (xi - i) ** 2
    ans = min(ans, sum)
print(ans)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
ans = 1000000000000000000000000000000000
for i in range(100):
    d = 0
    for j in l:
        d += (j-(i+1))**2
    if ans > d:
        ans = d
print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
num = 0
ans = 10**7 + 10

for p in range(1, 101):
    for i in range(N):
        num += (X[i] - p) ** 2
    if num < ans:
        ans = num
        num = 0

print(ans)

Solution (Python):
def calc_sum_energy(p, x_list) -> int:
    return sum([(p - x) ** 2 for x in x_list])


def main(n, x_list):
    print(min([calc_sum_energy(p, x_list) for p in range(1, 101)]))


if __name__ == "__main__":
    n = int(input())
    x_list = [int(i) for i in input().split()]

    main(n, x_list)

Solution (Python):
n = int(input())
*x, = map(int, input().split())
ans = float('inf')

for i in range(min(x), max(x)+1):
    tmp = 0
    for j in x:
        tmp += (j - i)*(j - i)
    ans = min(ans, tmp)
print(ans)

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


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


def read_index():
    return map(lambda x: x - 1, map(int, input().split()))


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def main():
    N = int(input())
    X = read_list()
    res = 10 ** 10
    for y in range(1, 101):
        res = min(res, sum((x - y) ** 2 for x in X))
    print(res)


if __name__ == "__main__":
    main()

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

center = round(sum(l) / N)
ans = 0

for i in range(N):
    ans += (center - l[i]) ** 2
    
print(ans)

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

Solution (Python):
N = int(input())
X = list(int(x) for x in input().split())
p = round(sum(X)/len(X))
ans = 0

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

print(ans)

Solution (Python):
import numpy as np

N = int(input())
X = np.array(list(int(x) for x in input().split()))
m = round(np.mean(X))

print(int(sum((X-m)**2)))

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

m = min(X)
M = max(X)

min_val = 100 * 100 * 100
for p in range(m, M+1):
    score = 0
    for x in X:
         score += (x-p)*(x-p)
    if score < min_val: min_val = score
print(min_val)

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

m = min(X)
M = max(X)

cost = [1000000009 for _ in range(101)]
for p in range(1,101):
    c = 0
    for x in X:
        c += (x-p)**2
    cost[p] = c

print(min(cost))

Solution (Python):
import numpy as np
n = int(input())
l = np.array([int(i) for i in input().split()])
mean = np.mean(l)

ans = 10 ** 9

for i in [int(mean),int(mean)-1,int(mean)+1]:
    ans = min(ans, np.sum(((l-i)*(l-i))))

print(ans)

Solution (Python):
n = list(map(int, input().split()))[0]
x = list(map(int, input().split()))
m = 1000000009
for i in range(100):
    sum = 0
    for j in range(len(x)):
        sum += (i - x[j]) ** 2
    m = min([m, sum])
print(m)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
mini = 980100
for i in range(1, 101):
    l_sum = sum(list(map(lambda x: (x - i)**2, l)))
    if mini > l_sum:
        mini = l_sum
print(mini)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
import numpy as np
P = np.average(X)
P = round(P)
d = [(x - P)**2 for x in X]
ans = int(np.sum(d))
print(ans)

Solution (Python):


import sys

def solve(xs):
    xs.sort()
    ans = float('inf')
    for p in range(xs[0], xs[-1] + 1):
        distance = 0
        for x in xs:
            distance += (p - x)**2
        if distance < ans:
            ans = distance
    return ans


def read_int_list():
    return [int(s) for s in sys.stdin.readline().rstrip().split(" ")]


def dprint(*args, **kwargs):
    return
    print(*args, **kwargs)


def main():
    n = int(sys.stdin.readline().rstrip())
    print(solve(read_int_list()))


if __name__ == "__main__":
    main()

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

mpow = 100*100*100*100*100

for P in range(100):
    temp = 0
    for Xi in X:
        temp += (Xi-P)*(Xi-P)
        if temp > mpow:
            break 
    if temp < mpow:
        mpow = temp

print(mpow)

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

Solution (Python):
import numpy as np
N = int(input())
Xs = np.array(input().split(), dtype=int)


scales = np.arange(-100, 100) ** 2

res = np.zeros(100)
for x in Xs:
    res += scales[100 - x: 200 - x]

print(res.min().astype(int))

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
k = sum(X) / N - 1 / 2
P = int(k) + 1

X = list(map(lambda x: (x - P)**2 ,X))
ans = sum(X)
print(ans)

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

minimum = 1e17
coor = 1
for i in range(1, 101):
    s = sum((x-i)**2 for x in l)
    if s < minimum:
        minimum = s
        coor = i

print(minimum)

Solution (Python):
n = int(input())
x_arr = [i for i in map(int,input().split())]
ans = 999999999
for i in range(1,100):
  temp = 0
  for j in range(len(x_arr)):
    temp += (x_arr[j] - i)**2
  if temp < ans:
    ans = temp
    
print(ans)

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

l = x[0]
r = x[-1]
S = 10 ** 9

for i in range(l, r+1):
    s = sum([(p-i)**2 for p in x])
    S = min(s, S)
print(S)

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

s = 0
for xi in X:
    s += xi
si = round(s / N)
ps = 0
for xi in X:
    ps += int(math.pow(xi-si, 2))
print(ps)

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
mi = 10**10
for i in range(100):
    point = 0
    for j in li:
        point += (j-i)**2
    mi = min(mi,point)
print(mi)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

























def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')

def main():
	N = inputInt()
	X = inputList()

	ans = inf
	for i in range(1,101):
		total = 0
		for j,val in enumerate(X):
			tmp = (val-i)**2
			total += tmp
		
		if ans > total:
			ans = total

	print(ans)


if __name__ == "__main__":
	main()

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

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

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

print(ans)

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

min_cost = float('inf')
for i in range(min(Xs), max(Xs)+1):
    cost = 0
    for x in Xs:
        cost += (x-i)**2
    if cost < min_cost:
        min_cost = cost

print(min_cost)

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

r = list(map(int,input().split(' ')))

res = []
for i in range(min(r),max(r) + 1):
  k = 0
  for j in r:
    k = k + (j - i) ** 2
  res.append(k)
print(min(res))

Solution (Python):
import sys

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

for i in range(1, 100):
    hp = 0    
    for j in range(n):
        hp += (x[j] - i) * (x[j] - i)

    
    min_hp = min(hp, min_hp)
    
print(min_hp)

Solution (Python):
import sys

INF = 1000000000

def resolve():
  n = int(input())
  x = list(map(int, input().split()))
  ans = INF
  for i in range(1, 100):
    t = x
    tmp = 0
    for j in x:
      tmp += abs(i - j) ** 2
    ans = min(ans, tmp)
  print(ans)
  return

if __name__ == "__main__":
    resolve()

Solution (Python):
n = int(input())
*x, = map(int, input().split())
x.sort()
ans = float('inf')

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

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

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

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]
avg = round(sum(X) / N)
print(sum([int((x - avg) ** 2) for x in X]))

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]
avg = round(sum(X) / N)
print(sum(map(lambda x: int((x - avg) ** 2), X)))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
X.sort()
ans=1000000000
for i in range(X[0],X[N-1]+1):
    tmp=0
    for j in range(N):
        tmp+=(i-X[j])**2
    if tmp<ans:
        ans=tmp
print(ans)

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

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

X.sort()

sumx = sum(X)
lenx = len(X)

point = round(sumx / lenx)

totalcost = 0
for Xi in X:
    totalcost += pow((Xi - point), 2)

print(totalcost)

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

Solution (Python):
import numpy as np


n = int(input())
X = np.array(list(map(int, input().split())), dtype=np.int64)

ans = []
for pos in range(1, 101):
    cost = ((X - pos) ** 2).sum()
    ans.append(cost)

print(min(ans))

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

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

ans = float("inf")

for i in range(min(x), max(x)+1):
    power = 0
    for j in range(len(x)):
        power += (x[j] - i) ** 2
    ans = min(ans, power)
print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
S = []
for p in range(min(X), (max(X) + 1)):
    t = [(i - p) ** 2 for i in X]
    S.append(sum(t))
print(min(S))

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

m = sum(X)//len(X)
S = min(sum([(x-m)**2 for x in X]),sum([(x-m-1)**2 for x in X]))
print(S)

Solution (Python):
n = int(input())
 
x = input().split()
x = [int(_x) for _x in x]
 
_p = sum(x) // n
 
_p_value = sum([(_x - _p) ** 2 for _x in x])
__p_value = sum([(_x - _p + 1) ** 2 for _x in x])
___p_value = sum([(_x - _p - 1) ** 2 for _x in x])
 
print(min(_p_value, min(__p_value, ___p_value)))

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

x_min = min(x)
x_max = max(x)
ans = 0

for i in range(x_min + 1, x_max + 1):
    tmp = 0
    for k in x:
        tmp = tmp + (k - i) ** 2
    
    if ans == 0:
        ans = tmp
    elif ans > tmp:
        ans = tmp
        
print(ans)

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

ans = x[-1]**2 *n
for _n in range(x[0], x[-1]+1):
    _ans = sum([(_x - _n)**2 for _x in x])
    ans = min(_ans, ans)

print(ans)

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

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

Solution (Python):
N = int(input())
Xs = list(map(int, input().split()))
L,R = min(Xs), max(Xs)
cost = 0 if L==R else float("inf")
for p in range(L+1,R):
  cost_p = sum([(xi-p)**2 for xi in Xs])
  cost = cost_p if cost_p < cost else cost
print(cost)

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

y = []
for p in range(100):
    y.append(sum([(p-x)**2 for x in xs]))
print(min(y))

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

x = [int(i) for i in x]
x = sorted(x)

s =round(sum(x)/n)
l = 0

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

print(l)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
x.sort()
Sum = 0
Min = float("inf")
for i in range(100):
    Sum = 0
    for j in x:
        Sum += (j - i)**2
    if Sum < Min:
        Min = Sum
print(Min)

Solution (Python):
import math

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

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
x.sort()
Sum = 0
Min = 9999999999
for i in range(100):
    Sum = 0
    for j in x:
        Sum += (j - i)**2
    if Sum < Min:
        Min = Sum
print(Min)

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP
import numpy as np
n = int(input())
x = np.array(input().split(), int)

m = Decimal(np.sum(x) / n)
mq = int(m.quantize(0, rounding=ROUND_HALF_UP))

s = np.sum((x-mq)**2)
print(s)

Solution (Python):
import math

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

a = sum(lst)//len(lst)
b = -(-sum(lst)//len(lst))

ans_a=0
ans_b=0
for i in lst:
    ans_a += (i-a)**2
    ans_b += (i-b)**2

print(min(ans_a,ans_b))

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


ans = 10**18
def rally(p):
    n = 0
    for a in range(N):
        n += (int(p)-List[a])**2
    return n

for i in range(1,101):
    ans = min(rally(i),ans)

print(ans)

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

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

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

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines





import numpy as np

def main():
	n=int(input())
	X=list(map(int,input().split()))
	X=np.array(X)
	X.sort()
	ans=10**10
	
	for i in range(X[0],X[-1]+1,1):
		ans=min(ans,sum((X-i)**2))
	print(ans)
	
	
	
	
	
	
	
	
	
	
	
	
	
if __name__ == "__main__":
	main()

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

a = sum(x*x for x in X)
b = sum(X)

print(min(a - 2 * p * b + N * p * p for p in [b//N, b//N+1]))

Solution (Python):
N = int(input())
 
X = list(map(int, input().split()))
 
a = round((sum(X) / N), 3)
integer = int(a)
f = a - integer
 
if f < 0.5:
    P = integer
else:
    P = integer + 1
 
total = 0
for i in X:
    total += (i - P) ** 2
 
print(total)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
P = sum(X)//N
ans1 = 0
ans2 = 0
for x in X:
    ans1 += (P-x)**2
    ans2 += (P+1-x)**2
print(min(ans1, ans2))

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()]

    ans = float('inf')
    for i in range(1,101):
        tmp = 0
        for x in X:
            tmp += (x - i)**2
        
        if tmp < ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
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()]
    X = np.array(X)

    ans = np.min(np.sum((X - np.arange(1,101).reshape(100, 1))**2, axis=1))
    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
min_total = 100000000
for syukai in range(1, 100):
  total = 0
  for x in X:
    total += (x - syukai)**2
  else:
    min_total = min(total, min_total)
print(min_total)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
tairyoku = [0]*100

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

print(min(tairyoku))

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

dist_min = 10 ** 6
for p in range(1, 100, 1):
    dist = 0
    for x in xlist:
        dist += (x - p) ** 2
    dist_min = min(dist_min, dist)

print(dist_min)

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

Solution (Python):
n=int(input())
Xs=list(map(int,input().split()))
Xs.sort()
a=Xs[0]
b=Xs[-1]
ans=float("inf")
for p in range(a,b+1):
    m=0
    for x in Xs:
        m+=(x-p)**2
    if m<ans:
        ans=m
print(ans)

Solution (Python):

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)



def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    
            

    for d in directions:
        nx = d+x
        
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

N=int(input())
X=np.array(acinput())

u = round(np.mean(X))


res=0

print(int(np.sum((u-X)**2)))

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

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

left = min(x)
right = max(x)
ans = float('inf')

for p in range(left,right+1):
  summed = 0
  
  for xi in x:
    summed += (xi -p)**2
  ans = min(ans,summed)
print(ans)

Solution (Python):

N = input()
X = input().split()
total1 = 0
total2 = 0
for i in X:
    i = int(i)
    total1 += 1
    total2 += i
total2 *= 2
total1 *= 2
min = total2/total1
if min >= 1:
    if min%int(min) >=0.5:
        min = int(min) + 1
    elif min%int(min) == 0 :
        min = int(min)
    else:
        min = int(min) 
else:
    min = 1


sum = 0
for i in X:
    i  = int(i)
    sum += (min-i)*(min-i)
print(sum,end="")

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

hp = 0
ans = 10**18

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

    if ans > hp:
        ans = hp

    hp = 0

print(ans)

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

for ps in s:
  xs.append(int(ps))

max_x = max(xs)
min_x = min(xs)
for i in range(min_x, max_x + 1):
  dist = 0
  for x in xs:
    dist += abs((i - x) ** 2)
  
  try:
    if min_dist > dist:
      min_dist = dist
  except NameError:
    min_dist = dist

print(min_dist)

Solution (Python):
n=int(input())
X=[int(i) for i in input().split()]
X.sort()
ans=float("inf")
a,b=X[0],X[-1]
for i in range(a,b+1):
  cur=0
  for x in X:
    cur+=(x-i)**2
  ans=min(cur,ans)
print(ans)

Solution (Python):



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

    
    
    
    left = min(x)
    right = max(x)

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

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

        ans = min(ans, summed)

    print(ans)


if __name__ == '__main__':
    main()