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):
from math import ceil, floor

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

P = sum(X) / N
ans = []
for p in (floor(P), ceil(P)):
    ans.append(sum((x - p) ** 2 for x in X))
print(min(ans))

Solution (Python):
def main():
    n=int(input())
    xx=list(map(int,input().split()))
    m=None
    for i in range(1,101):
        mm=sum([(x-i)**2 for x in xx])
        if m is None or m>mm:
            m=mm
    print(m)
main()

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

P = sum(X)/N
P = [math.ceil(P), math.floor(P)]
print(min([sum([(x-p)**2 for x in X]) for p in P]))

Solution (Python):
n = int(input().strip())
xs = list(map(int, input().split()))
tmp = sum(xs) // n
print(min(sum(map(lambda x: (x - tmp) ** 2, xs)), sum(map(lambda x: (x - (tmp + 1)) ** 2, xs))))

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

print(sum)

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

Solution (Python):
N = int(input())
X = sorted(list(map(int, input().split(" "))))
min = -1
for i in range(X[0], X[-1]+1):
  s = sum((x - i) ** 2for x in X)
  if min == -1:
    min = s
  if s < min:
    min = s
print(min)

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

ans = 1000000
for p in range(1, 101):
    hp_sum = 0
    for x in xs:
        hp_sum += (x - p) ** 2
    ans = min(ans, hp_sum)

print(ans)

Solution (Python):
def solve(string):
    n, *x = map(int, string.split())
    return str(sum((_x - int(sum(x) / n + 0.5))**2 for _x in x))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
def solve(string):
    n, *x = map(int, string.split())
    c = int(sum(x) / n + 0.5)
    return str(sum((_x - c)**2 for _x in x))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

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


for p in range(min(X), max(X) + 1):
    sum_HP = 0
    for x in X:
        sum_HP += (x - p) ** 2
    N_sum_HP.append(sum_HP)
print(min(N_sum_HP))

Solution (Python):
n= int(input())
x= list(map(int,input().split()))
xsum = sum(x)
xxsum = sum([c*c for c in x])
gmin = 999999999
for c in range(1,101):gmin=min(gmin,xxsum+n*c*c-2*c*xsum)
print(gmin)

Solution (Python):
import math

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

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

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

print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ans = float('inf')
for i in range(100):
  ans = min(ans, sum([pow(y - i - 1, 2) for y in x]))
print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
min = 1000000
for i in range(101):
    d = 0
    for j in range(N):
        d += (i-X[j])**2
    if min > d:
        min = d
print(min)

Solution (Python):
n = int(input())
x = [int(x) for x in input().split()]
x.sort()
ans = 10**9+7
for i in range(1, x[-1]+1):
  key = 0
  for j in range(n):
    key += (x[j]-i)**2
  if key < ans:
    ans = key
print(ans)

Solution (Python):

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

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

Solution (Python):

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

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

ans = 100**3
for p in range(1, 101):
    cost = sum((xi - p)**2 for xi in x)
    ans = min(ans, cost)

print(ans)

Solution (Python):

"""
Created on Mon Mar  2 23:58:34 2020

@author: Kanaru Sato
"""

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

for P in range(1,101):
    Pvalue = 0
    for i in range(0,N):
        Pvalue += (X[i]-P)**2
    Pvalues.append(Pvalue)

print(min(Pvalues))

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

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

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

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

Solution (Python):

import numpy as np

N = int(input())
X = [int(x) for x in input().split()]
X = np.array(X)

ans = 1e6
for x in range(1, 100) :
    s = (X-x)**2
    ans = min(ans, s.sum())
print(ans)

Solution (Python):


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

ans = []
for i in range(101):
    sum = 0
    for j in range(len(x)):
        sum += (x[j] - i)**2
    ans.append(sum)
print(min(ans))

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

def func(p):
	a=0
	for i in x:
		a += (i-p)**2
	return a


xsum = sum(x)
p1 = int(xsum/n)
p2 = p1+1


if func(p1)<func(p2):
	print(func(p1))
else:
	print(func(p2))

Solution (Python):
n = int(input())
li = list(map(int, input().split()))
res = -1
for i in range(101):
  sum = 0
  if i == 0:
    pass
  else:
    for j in range(n):
      sum = sum + (li[j]-i)**2
    if res == -1:
      res = sum
    elif res > sum:
      res = sum
print(res)

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

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

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

X.sort()

min=10000000000
for P in range(100):

    power=0
    for j in range(len(X)):
        power=power+(X[j]-P)**2

    if power<=min:
        min=power

    P=P+1


print(min)

Solution (Python):
n=int(input())
lst=list(map(int,input().split()))
min_lst=sorted(lst)
ans=[]

for i in range(min_lst[0],min_lst[-1]+1):
  
  sum=0
  for j in lst:
    sum+=(i-j)**2
    
  ans.append(sum)
  
print(min(ans))

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

result = 1e9
for i in range(100):
    sta = 0
    for x in X:
        sta += (x - i) * (x - i)
    result = min(sta, result)
print(result)

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

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

for x in X:
    ans += (x - R)**2

print(ans)

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

Solution (Python):
MAX = 10000000

N = int(input())
human_points = list(map(lambda x: int(x), input().split()))

min_sum = MAX

for i in range(1, 100):
  tmp_sum = 0
  for point in human_points:
    tmp_sum += (point - i)**2
  if min_sum > tmp_sum:
    min_sum = tmp_sum
print(min_sum)

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

x_li = [int(w) for w in input().split()]

x_ave = sum(x_li) / len(x_li)
ave_pos = int(x_ave+0.5)

ans = 0
for x in x_li:
    ans += (x - ave_pos) ** 2

print(ans)

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

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
count = 1000000000
sumX = 0
l = max(x)
for j in range(l):
    sumX = 0
    for k in range(n):
        sumX +=(x[k]-(j+1)) ** 2
    count = min(sumX,count)
print(count)

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

min_sum = float('inf')
for i in range(x[0], x[len(x) - 1] + 1):
    sum = 0
    for j in range(n):
        sum += (x[j] - i) ** 2
    if sum < min_sum:
        min_sum = sum

print(min_sum)

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

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

print(ans)

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

min_x, max_x = min(x), max(x)

min_cost = sum([(x[i] - min_x) ** 2 for i in range(n)])
for p in range(min_x + 1, max_x + 1):
  cost = sum([(x[i] - p) ** 2 for i in range(n)])
  min_cost = min(cost, min_cost)

print(min_cost)

Solution (Python):
import statistics
import math

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

p = math.ceil(statistics.mean(X))
print(min(
    sum([(x - p) ** 2 for x in X]),
    sum([(x - (p-1)) ** 2 for x in X]),
    sum([(x - (p+1)) ** 2 for x in X]),
    ))

Solution (Python):

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

print(min(ans))

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

minX = min(X)
maxX = max(X)
li = []
for i in range(100):
    temp = 0
    for j in range(N):
        temp += (X[j] - i)**2
    li.append(temp)

print(min(li))

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

Solution (Python):
def main():

    N = int(input())
    X = list(map(int, input().split()))
    X.sort()
    ans = float('inf')
    for y in range(min(X), max(X)+1):
        p = 0
        for i in range(N):
            p += pow(y - X[i], 2)
        ans = min(ans, p)
    return ans

if __name__ == '__main__':
    print(main())

Solution (Python):
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60


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

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

print(ans)

Solution (Python):
import numpy as np

def resolve():
    n = int(input())
    x = np.array(list(map(int, input().split())))

    ans = 1000000

    for i in range(100):
        ans = np.minimum(np.sum(np.square(x - i)), ans)

    print(ans)

resolve()

Solution (Python):
N = int(input())
*X, = map(int, input().split())
ans = 10**10
for p in range(1, 101):
    temp = sum((x - p)**2 for x in X)
    ans = min(ans, temp)
print(ans)

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

ans = None
ans_dist = 1000000007
for Xref in range(1, 100 + 1):
    dist = 0
    for i, Xi in enumerate(X):
        dist += (Xi - Xref) ** 2
    
    if ans_dist > dist:
        ans = Xref
        ans_dist = dist

print(ans_dist)

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

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

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

Solution (Python):
import math



n = int(input())
n_list = list(map(int,input().split(" ")))

min_num = 100000000000000

for p in range(min(n_list), max(n_list)+1):
    sum = 0
    for j in n_list:
        sum += (j-p)**2

    if sum<min_num:
        min_num = sum

print(min_num)

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

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

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

mean = round(sum(x) / n)

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

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

ave = sum(X) / N

kouho1 = int(ave)

if ave != int(ave):
  kouho2 = kouho1 + 1
else:
  kouho2 = kouho1
  
def tairyoku(a):
  tai = 0
  for i in X:
    tai = tai + (i - a)**2
  return tai

tairyoku1 = tairyoku(kouho1)
tairyoku2 = tairyoku(kouho2)
print(min(tairyoku1, tairyoku2))

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

ans = 0
i = X[0]
while i <= X[N-1]:
    eng=0
    for k in range(N):
        eng += (X[k]-i)**2
    if i == X[0] or eng < ans:
        ans = eng
    i += 1
print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
xp = round(sum(X) / N)
Xe = map(lambda x: abs(x - xp) ** 2, X)
print(sum(Xe))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
sav = float("inf")
for i in range(min(X), max(X)+1):
    Xe = map(lambda x:abs(x-i)**2,X)
    health = sum(Xe)
    if sav > health:
        sav = health

print(sav)

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

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

avg = round(sum(X) / N)
ans = 0

for i in X:
    ans += (i - avg) ** 2

print(ans)

Solution (Python):
N = int(input())
ans = 10**9+7
X_list = list(map(int,input().split()))
for P in range(min(X_list),max(X_list)+1):
    ans = min(ans,sum([(i-P)**2 for i in X_list]))
print(ans)

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

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

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

INF = 10**9
m = INF
for x in range(1,max(X)+1):
    temp = 0
    for i in range(N):
        temp += (x - X[i])**2
    if m > temp:
        m = temp
print(m)

Solution (Python):
import numpy as np
n = int(input())
l = list(map(int, input().split()))

l = np.array(l)
ans = np.sum((l - round(np.mean(l)))**2)
print(int(ans))

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
ans = 100100100
for i in range(1,101) :
    s = 0
    for o in x :
        s+=(i-o)*(i-o)
    ans = min(ans,s)
print(ans)

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

p = 1
v_list = [0 for _ in range(N)]


def calc(p, x):
    return (x - p) ** 2

ans = 0
for _ in range(100):
    new_v_list = [calc(p, x) for x in x_list]
    s = sum(v_list)
    new_s = sum(new_v_list)
    
    if p==1:
        pass        
    elif s < new_s:
        ans = s
        break
        
    ans = new_s
    p+=1
    v_list = new_v_list

print(ans)

Solution (Python):
import numpy as np

n = int(input())
x = np.array(list(map(int,input().split())))
r = np.full(100, 100 * n)

for p in range(100):
    r[p] = np.sum((x - p + 1)**2)
print(int(np.min(r)))

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

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

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

t = round(sum(x)/n)

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

Solution (Python):
N = int(input())
X = list(map(int, input().strip().split()))
total = 0
points = 0
for i in X:
  total += i
avg = int(round(total/N))
for i in X:
  points += (i-avg)**2
print(points)

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

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

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

ans = 10**9

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

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

point = (sum(X) / N * 2 + 1) // 2
result = 0
for x in X:
	result += int((x - point) ** 2)

print(result)

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













min = min(xs)
max = max(xs)
smallestS = 99999999999999999999

for _ in range(min,max+1):
    stamina = 0
    for x in xs:
        stamina +=(x-_)*(x-_)
    if stamina<smallestS:
        smallestS = stamina

print(smallestS)

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

answer = sum([x ** 2 for x in li_x])
for p in range(min(li_x),max(li_x) + 1):
    answer = min(answer, sum([(x - p) ** 2 for x in li_x]))

print(answer)

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

answer = []
p = min(X)
while p <= max(X):
  a = [(x-p)**2 for x in X]
  answer.append(sum(a))
  p += 1
  
print(min(answer))

Solution (Python):
import numpy as np
N = int(input())
X = np.array([int(i) for i in input().split()])
print(min([np.sum((X-i)**2) for i in range(101)]))

Solution (Python):
N = int(input())
x = []
s = input()
x = s.split()
y = len(x)
summ1 = 0
summ2 = 0
sr = 0
setx = set(x)
h = len(setx)
if N == 1:
    print("0")
else:
    if h == 0:
        print("0")
    else:
        for i in range(y):
            x[i] = int(x[i])
            sr = sr + x[i]
        PMA = (sr//N)+1
        PMM = sr//N
        for i in range(y):
            summ1 = summ1 + ((x[i]-PMA)*(x[i]-PMA))
        for i in range(y):
            summ2 = summ2 + ((x[i] - PMM) * (x[i] - PMM))
        if summ2 > summ1:
            print(summ1)
        else:
            print(summ2)

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

Solution (Python):
def power(x, n):
  return (x-n) * (x-n)

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

ave = round(sum(nums) / n)

new_nums = []

for i in nums:
  r = power(i, ave)
  new_nums.append(r)

print(sum(new_nums))

Solution (Python):
import sys
import os


def calc(x, p):
    return pow(x - p, 2)


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

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

    ret = float('inf')
    for p in range(100):
        tmp = 0
        for n in range(N):
            tmp += calc(X[n], p)
        ret = min(tmp, ret)

    print(ret)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import numpy as np
N = int(input())
xs = np.array(list(map(int,input().split(" "))))
x_min,x_max = xs.min(),xs.max()
powers = []
for x in range(x_min,x_max + 1,1):
    powers.append(sum((xs-x)**2))
print(min(powers))

Solution (Python):
import math

N=int(input())

inputs=input().split(" ")
X=[]

mini=100
maxi=0


for i in inputs:
    i=int(i)
    X.append(i)

    if int(i)<mini:
        mini=i

    if int(i)>maxi:
        maxi=i

minpowersum=math.pow(10,9)
for P in range(mini,maxi+1):

    powersum=0
    for j in range(N):
        powersum+=math.pow((X[j]-P),2)

    if powersum<minpowersum:
        minpowersum=powersum


print(int(minpowersum))

Solution (Python):
import statistics
N = int(input())
X = list(map(int,input().split()))
P = int(statistics.mean(X))
b = 0
for i in range(0,N):
    b = b + (X[i] - P) ** 2

while True:
    bb = 0
    P = P + 1
    for i in range(0,N):
        bb = bb + (X[i] - P) ** 2
    if b < bb:
        break
    elif b > bb:
        b = bb
print(b)

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

Solution (Python):
import math

N = int(input())
Xi = list(map(int, input().split(" ")))

Xi_min = min(Xi)
Xi_max = max(Xi)

ans = 999999999
for i in range(Xi_min, Xi_max+1):
    tmp = 0
    for j in range(N):
        tmp += pow(Xi[j] - i, 2)
    if tmp < ans:
        ans = tmp

print(ans)

Solution (Python):

N = int(input())
X = [int(x) for x in input().split()]
cnt = 0
A = 0
while cnt <= 100:
  cnt += 1
  i = 0
  while i < N:
    A += (int(X[i])-cnt)*(int(X[i])-cnt)
    i += 1
  if cnt == 1:
    ans = A
  else:
    ans = min(ans, A)
  A = 0
print (ans)

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

Solution (Python):
import math
N = int(input())
X = list(map(int,input().split()))
ave_h=math.ceil(sum(X)/N)
ave_l=math.floor(sum(X)/N)
count_1=0
count_2=0
for i in range(N):
    count_1+=(X[i]-ave_h)**2
    count_2+=(X[i]-ave_l)**2
print(min(count_1,count_2))

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

mn = 10 ** 10
for p in range(1, 101):
    tmp = 0
    for i in x:
        tmp += (i - p) ** 2
    mn = min(mn, tmp)
print(mn)

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

total = float('inf')

for p in range(1, 100):
    tmp = 0
    for num in nums:
        tmp += pow((p - num), 2)
    if tmp < total:
        total = tmp

print(total)

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

maxdist = x[int(n)-1]
p=int(sum(x)/len(x))
ret = 0
ret2 = 0
for i in x:
    ret = ret + (p-i)**2
    ret2 = ret2 + (p-i+1)**2
ret = ret if ret < ret2 else ret2
print(ret)

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

w = 0
sum = []
for p in range(1,101):
    w = 0
    for i in range(n):
        w += (x[i] - p)**2
    sum.append(w)
print(min(sum))

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

P = int((sum(x) / len(x)))
a = 0
b = 0
c = 0
ans_list = []

for i in range(N):
    a += (x[i] - P) * (x[i] - P)
    b += (x[i] - (P + 1)) * (x[i] - (P + 1))
    c += (x[i] - (P - 1)) * (x[i] - (P - 1)) 
ans_list.append(a)
ans_list.append(b)
ans_list.append(c)

print("{}".format(min(ans_list)))

Solution (Python):
import numpy as np
import math as m

def main(**kwargs):
    minx = min(X)
    maxx = max(X)
    r = min([sum((X - x) ** 2) for x in range(minx, maxx+1)])
    return r

if __name__ == "__main__":
    cin = np.array(input().split(" ")).astype("int")
    n = cin[0]

    cin = np.array(input().split(" ")).astype("int")
    X = np.array(cin)
    
    cout = main(n=n, X=X)
    print(cout)

Solution (Python):
n=int(input())
hoge=list(map(int,input().split()))
ans=9999999
for i in range(1,101):
  huga=0
  for ho in hoge:
    huga+=(i-ho)**2
  ans=min(ans,huga)
  
print(ans)

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
ave = int(sum(L)/len(L))
ave2 = ave + 1
Answer = 0
Answer2 = 0
for i in range(N):
  Answer += (ave-L[i])**2
  Answer2 += (ave2-L[i])**2
if Answer <= Answer2:
  print(Answer)
else:
  print(Answer2)

Solution (Python):
import numpy as np

def main(n, xs):
    minx = min(xs)
    maxx = max(xs)
    ress = []

    for x in range(minx, maxx+1):
        res = sum((xs - x) ** 2)
        ress.append(res)

    res = min(ress)
    return res

if __name__ == "__main__":
    cin = input()
    n = int(cin.split(" ")[0])
    cin = input()
    xs = np.array(cin.split(" ")).astype("int")
    cout = main(n, xs)
    print(cout)

Solution (Python):
import numpy as np

def main(n, xs):
    minx = min(xs)
    maxx = max(xs)
    ress = []

    for x in range(minx, maxx+1):
        res = sum((xs - x) ** 2)
        ress.append(res)

    res = min(ress)
    return res

if __name__ == "__main__":
    cin = input()
    n = int(cin.split(" ")[0])
    cin = input()
    xs = np.array([], dtype="int")

    for i in range(n):
        xs = np.append(xs, int(cin.split(" ")[i]))
    cout = main(n, xs)
    print(cout)

Solution (Python):
N = int(input())
X = list(map(int, input().split(" ")))
minX, maxX = min(X), max(X)
ans = 100*N**2+1
for i in range(minX, maxX+1):
    ans = min(ans, sum([abs(i - x)**2 for x in X]))
print(ans)

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):
n = int(input())
x_list = list(map(int, input().split(' ')))

p = round(sum(x_list)/n)

print(sum([(x - p)**2 for x in x_list]))

Solution (Python):
n=int(input())
x=list(map(int, input().split()))
d=999999
for i in range (1,100):
    k=0
    for j in range (0,n):
        k=k+(x[j]-i)**2
    if k<=d:
        d=k
        
print(d)

Solution (Python):
num = int(input())
num_list = list(map(int,input().split()))

sum = 0
for i in range(0,num):
  sum = sum + num_list[i]
  
p = int(round(sum/num,0))

ans = 0
for i in range(0,num):
  ans = ans + (p-num_list[i])**2
  
print(ans)

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
 
 
def variance(x):
    avg = sum(X) // len(X)
    return (avg - x) ** 2
 
 
def main(X):
    tot = 0
    tot2 = 0
    for x in X:
        tot += variance(x)
        tot2 += variance(x - 1)
    return min(tot, tot2)
 
 
ans = main(X)
print(ans)

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


def variance(x):
    avg = sum(X) // len(X)
    return (avg - x) ** 2


def main(X):
    tot = 0
    tot2 = 0
    for x in X:
        tot += variance(x)
        tot2 += variance(x - 1)
    return min(tot, tot2)


ans = main(X)
print(ans)

Solution (Python):
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n = int(input())
    Xs = list(map(int, input().split()))
    
    mean = sum(Xs) / n

    cmean = ceil(mean)
    fmean = floor(mean)

    ct = 0
    ft = 0

    for i in range(n):
        ct += (Xs[i] - cmean) ** 2
        ft += (Xs[i] - fmean) ** 2
    
    print(min(ct, ft))

    return

if __name__ == '__main__':
    main()

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP

n = int(input())
habit = list(map(int, input().split(" ")))

x = Decimal(str(sum(habit)/n)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)

total = 0
for i in habit:
    total += (i - x) ** 2
print(total)

Solution (Python):
import numpy as np

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

max = 1000000
for j in range(1,101):
  energy = 0
  for i in range(len(x)):
    energy += (x[i]-j)**2
  if energy < max:
    max = energy
    
print(max)

Solution (Python):
N=int(input())
List=[int(i) for i in input().split()]
P=int(round(sum(List)/N,0))
def length(x):
 return sum([(i-P-x)**2 for i in List])

i=0
data=length(0)
while True:
 if(length(i-1)<length(i)<length(i+1)):
  i-=1
 elif(length(i-1)>length(i)>length(i+1)):
  i+=1
 else:
  print(length(i))
  break

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

Solution (Python):

if __name__ == '__main__':

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

    result = 900000
    for p in range(min(x), max(x) + 1):        
        s = sum([(i - p)** 2 for i in x])
        if result > s:
            result = s
    print(result)

Solution (Python):
import math

N = int(input())

*X,  = map(int, input().split())
total = sum(X)

c = math.ceil(total/N)
f = math.floor(total/N)

min_c = c
min_f = f
total_c = 0
total_f = 0


for x in X:
    total_c = total_c + (x-min_c)**2

for x in X:
    total_f = total_f + (x-min_f)**2

print(total_c if total_c <= total_f else total_f)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
Min,Max = min(x),max(x)
if Min == Max:
    print(0)
    exit()
s = [0] * (Max - Min)
k = 0

for i in range(Min,Max):
    for j in x:
        s[k] += (j - i) ** 2
    k += 1
print(min(s))

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

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

print(ans)

Solution (Python):
def main():
    n = int(input())
    li = list(map(int,input().split()))
    li.sort()
    size = len(li)
    ans = []
    for i in range(li[size-1]+1):
        count = 0
        for j in range(size):
            count += (i - li[j]) ** 2
        ans.append(count)
    min_val = min(ans)
    print(min_val)

if __name__ == '__main__':
  main()

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

import numpy as np
arr = np.array(X)

ans = np.inf
for i in range(1,101):
    ans = min(ans, sum(map(lambda x:x**2,arr-i)))

print(ans)

Solution (Python):
N = input()
x = list(map(int, input().split()))
start = min(x)
fin = max(x)
res = 0
for j in range(len(x)):
        res = res + (x[j]-start)*(x[j]-start)
        
for i in range(start,fin):
    sum = 0
    for j in range(len(x)):
        sum = sum + (x[j]-i)*(x[j]-i)
    if(sum < res):
        res = sum

print(res)

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


c = 10**10
for p in range(1,101):
	s = 0
	for i in range(len(l)):
		s += (l[i] - p)**2
	c=min(c,s)
print(c)