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):
a = int(input())
c = list(map(int, input().split()))
ma, mi = max(c), min(c)
j = list()
for i in range(mi, ma+1):
    d = sum([(x-i)**2 for x in c])
    j.append(d)
print(min(j))

Solution (Python):
import numpy as np
N, *X = map(int,open(0).read().split())

X = np.array(X)
g0 = sum(X)//len(X)
g1 = sum(X)//len(X)+1

print(min(sum((X-g0)**2),sum((X-g1)**2)))

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

mini = min(X)
maxi = max(X)
consume = 999999999

for i in range(mini, maxi+1):
    pos = i
    total = sum([(pos - j) ** 2 for j in X])
    consume = min(total, consume)

print(consume)

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

import math

a = sum(x) // n
r1 = 0
r2 = 0
for xi in x:
  r1 += (xi - a)**2
  r2 += (xi - (a+1))**2

print(min(r1,r2))

Solution (Python):
def Main(N, X):
    av = round(sum(X)/N)
    ans = 0
    for i in range(N):
        ans += (X[i]-av)**2
    return ans

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

if __name__ == '__main__':
    main()

Solution (Python):
total = 0
from decimal import Decimal, ROUND_HALF_UP
N = int(input())
A = list(map(int,input().split(" ")))
sum_number = sum(A) / N
sum_number = Decimal(str(sum_number))
sum_number = sum_number.quantize(Decimal('0'), rounding=ROUND_HALF_UP)
for i in range(N):
    total += abs(A[i] - sum_number) ** 2
print(total)

Solution (Python):


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

h = []
for s in range(1, 101):
    total = 0
    for t in x:
        total += (s - t) * (s - t)
    h.append(total)
print(min(h))

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

Solution (Python):
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))
ans = 1000000000

for P in range(1, 101):
    temp = np.sum((X - P)**2)
    if ans > temp:
        ans = temp
print(ans)

Solution (Python):
N = int(input())
X = [int(i) for i in input().split()]
mini = 10**6
for p in range(1,100):
	HP = sum(list(map(lambda x:(x-p)**2,X)))
	mini = min(mini,HP)
print(mini)

Solution (Python):
N = input()
list_X =  list(map(float,input().split()))

mean_dai = int(sum(list_X)/len(list_X)//1 +1)
mean_syo = int(sum(list_X)/len(list_X)//1)

l_dai = [(list_X[i] - mean_dai)**2 for i in range(len(list_X)) ]
l_syo = [(list_X[i] - mean_syo)**2 for i in range(len(list_X)) ]

ans = int(min(sum(l_dai),sum(l_syo)))
print(ans)

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

Solution (Python):
import numpy as np

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

point1 = min(X)
point2 = max(X)
Ans = 100000000000

for i in range(point1, point2+1):
    tmp = sum((X_arr - i) ** 2)
    if tmp < Ans:
        Ans = tmp

print(Ans)

Solution (Python):
def main():
    n = int(input())
    xn = list(map(int,input().split()[:n]))

    minsum = 0
    for point in range(min(xn),max(xn)):
        tmp = 0
        for xi in xn:
            tmp += (xi - point)**2
        if tmp < minsum or minsum == 0:
            minsum = tmp

    print(minsum)

if __name__ == "__main__":
    main()

Solution (Python):
import sys

def solve(N, X):
    ans = float("inf")
    for i in range(max(X)+1):
        cost = 0
        for x_i in X:
            cost +=  (x_i - i) ** 2
        ans = min(ans, cost)
    print(ans)

if __name__ == '__main__':
    N = int(sys.stdin.readline().strip())
    X = list(map(int,sys.stdin.readline().strip().split(" ")))
    
    solve(N, X)

Solution (Python):


def pleaseAC(ary):
    for i in range(100):
        ans = 0
        for j in ary:
            ans += (j - i)**2

        yield ans

def main():
    input()
    x = sorted(map(int, input().split()))

    print(min(pleaseAC(x)))




main()

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

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

minhp = float('inf')


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

print(minhp)

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

ma = max(X)
mi = min(X)

ans = 10**9

for n in range(mi, ma+1):
  count = 0
  for x in X:
    count += abs(x-n)**2

  if ans > count:
    ans = count

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
m=float("inf")
for x in range(1,101):
    p=0
    for y in a:
        p+=(y-x)**2
    m=min(m,p)
print(int(m))

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

Solution (Python):

N = int(input())
X = list(map(int, input().split()))
ans = 10 ** 12

for i in range(1, max(X)+1):
    tmp_ans = 0
    for xi in X:
        tmp_ans += (xi - i) ** 2
    ans = min(ans, tmp_ans)
    
print(ans)

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

ans1=0
for i in x:
    ans1+=(i-average-1)**2

print(min(ans,ans1))

Solution (Python):

import numpy as np


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

m = 1000000000
for i in range(1,101):
    d = x - i
    h = d*d
    m = min(sum(h), m)

print(m)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
min1 = 1000000000
for i in range(max(A)+1):
  sum1 = 0
  for j in range(N):
    sum1 += ((i - A[j]) ** 2)
  if(sum1 < min1):
    min1 = sum1
    
print(min1)

Solution (Python):
def main():
    n=int(input())
    X=list(map(int,input().split()))
    m=sum(X)/n
    if 2*(m//1-m)+1<0:
      m=int(m//1+1)
    else:
      m=int(m//1)
    ans=0
    for i in range(n):
        ans+=(X[i]-m)**2
    print(ans)   
if __name__=='__main__':
    main()

Solution (Python):

def solve(N, Xs):
    low = min(Xs)
    high = max(Xs)
    ans = sum([x**2 for x in Xs])

    for p in range(low, high + 1):
        cost = 0
        for x in Xs:
            cost += (x - p) ** 2
        ans = min(ans, cost)
    return ans

if __name__ == "__main__":
    N = int(input())
    Xs = list(map(int, input().split(" ")))
    print(solve(N, Xs))

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

total = 0

for X in Xs:
    total += (int)(X)

P = (int)(total/N+0.5)

ans = 0

for X in Xs:
    ans += ((int)(X)-P)**2

print(ans)

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

L= list(map(int, input().split()))
min1 = min(L)
max1 = max(L)
ans = 10**10

for i in range(min1,max1+1):
    sum1 =0
    for j in range(n):
        sum1 += (L[j]-i)**2
        
    ans = min(ans,sum1)
print(ans)

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

Solution (Python):
N=input()
X=list(map(int,input().split()))
P=9999999999
for i in range(1,101):
  tmp=0
  for j in X:
    tmp += (j-i)**2
  if(P>tmp):
    P=tmp

print(P)

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

X.sort()

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



T =[]

for i in range(1,101):
    HP = 0
    for j in X:
        HP = HP + (i-j)**2
    T.append(HP)
print(min(T))

Solution (Python):
n=int(input())
x=[int(x) for x in input().split()]
big=max(x)
small=min(x)
ans=10000000000000000
for i in range(small,big+1):
  samu=0
  for j in range(len(x)):
    samu+=(x[j]-i)*(x[j]-i)
  if samu<=ans:
    ans=samu
print(ans)

Solution (Python):
import sys

def main():
    n = int(input().replace('\n',''))
    x = input().replace('\n','').split(' ')
    x = [int(i) for i in x]
    x_sort = sorted(x)
    min = -1
    for i in range(x_sort[len(x_sort)-1]+1):
      res=0
      for j in x_sort:
        res += (j-i) ** 2
      if min > res or min == -1:
        min = res
    print(min)
if __name__ == '__main__':
    input = sys.stdin.readline
    main()

Solution (Python):
def main():
    n = int(input())
    p = list(map(int,input().split()))
    q = round(sum(p)/n)
    ans = 0
    for i in p:
        ans += (i-q)**2
    print(ans)

if __name__ == '__main__':
    main()

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

p_min = min(data)
p_max = max(data)

ans_min = 100000000000000

for i in range(p_min, p_max+2):
  ans = 0

  for d in data:
    ans += (i-d)**2

  if ans < ans_min:
    ans_min = ans

print(ans_min)

Solution (Python):
import numpy as np

N = int(input())
X = np.fromstring(input(), np.int64, sep=' ')
ans = 1000000
for p in range(1, 100):
    ans = min(ans, np.sum((X - p) ** 2))
print(ans)

Solution (Python):
N = int(input())
s = [int(x) for x in input().split()]
def count(P):
    a = 0
    for i in range(N):
        b = (s[i]-P)**2
        a = a + b
    return a

c = count(1)
for i in range(100):
    if count(i+1) <= c:
        c = count(i+1)
print(c)

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

mn = 10**9
count = 0

for i in range(-110,110):
    for j in range(len(x)):
        count += (x[j] - i)**2
    if count <= mn:
        mn = count
        count = 0

print(mn)

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




SU = sum(list)/N
SR = round(SU)




ANS = 0
for i in range(N):
  temp = (list[i] - SR)
  ANS += temp*temp

print(ANS)

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

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
a=sum(X)//N
b=sum(X)//N+1
ans_a=sum(abs(i-a)**2 for i in X)
ans_b=sum(abs(i-b)**2 for i in X)
print(min(ans_a,ans_b))

Solution (Python):
N, *X = map(int, open(0).read().split())

ans = float("inf")
for p in range(1, 101):
    ans = min(ans, sum((x - p) ** 2 for x in X))

print(ans)

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

a = min(X)
b = max(X)
l = [0]*(b-a+1)
for i, p in enumerate(range(a, b+1)):
  for j in range(N):
    l[i] += (p - X[j])**2
print(min(l))

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

Solution (Python):

N = int(input())


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

ans = 10**9

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

Solution (Python):
N = int(input())
pos_l = list(map(int,input().split()))
MAX = 100
ans = 10**6
for i in range(1,MAX+1):
    tmpans = 0
    for pos in pos_l:
        tmpans += (pos - i)**2
    
    if(tmpans < ans):
        ans = tmpans

print(ans)

Solution (Python):
N = input()
N = int(N)
X = input().split()
A = []

min = 100
max = 0
for x in X:
  x = int(x)
  A.append(x)
  if max < x:
    max = x
  if x < min:
    min = x

ans = 0
count = 1
for p in range(min, max):
  sum = 0
  for a in A:
    sum += (a - p) * (a - p) 
  if ans > sum:
    ans = sum
  if count == 1:
    ans = sum
  count += 1

print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
tmp = 0
mi =100000000000
for i in range(1,101):
  for k in range(N):
    tmp += (X[k] - i)**2
  if tmp < mi:
    mi = tmp
  tmp = 0
print(mi)

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

cost = float("inf")

for p in range(1,101):
    total=0
    for x in xl:
        total += (p-x)**2
    cost = min(cost,total)
print(cost)

Solution (Python):

import sys



def solve(N: int, X: "List[int]"):
    st=min(X)
    end=max(X)
    costmin=1000000
    for p in range(st,end+1):
        cost=0
        for i in range(N):
            cost+=(p-X[i])**2
        if cost<costmin: costmin=cost
    print(costmin)
    return



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

if __name__ == '__main__':
    main()

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

C_1 = sum(X)
P_R = C_1 / N
P_int_min = int(P_R)
P_int_max = P_int_min + 1

zahyou = -1
if (P_R - P_int_min) <= (P_int_max - P_R):

    zahyou = P_int_min
else:
    zahyou = P_int_max

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

print(ans)

Solution (Python):
import math

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

s = sum(X) / N

p1 = math.floor(s)
p2 = math.ceil(s)

l1 = 0
l2 = 0

for x in X:
    l1 += (x - p1) ** 2
    l2 += (x - p2) ** 2

print(min(l1, l2))

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

lmax = max(X)
lmin = min(X)

res = 99999999
for i in range(lmin, lmax+1):
    p = 0
    for n in X:
        p += (n-i)**2

    if p < res:
        res = p

print(res)

Solution (Python):
s=int(input())
t=list(map(int,input().split()))
a=max(t)
b=len(t)
c=0
d=10**6
for i in range(1,a+1):
  for j in range(b):
    c+=(t[j]-i)**2
  d=min(c,d)
  c=0
print(d)

Solution (Python):
import itertools
import sys
import math
import numpy as np
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
sys.setrecursionlimit(10**9)


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

    ans = 10**20
    for p in range(101):
        sum = 0
        for i in range(0,N):
            sum += (X[i] - p)**2

        ans = min(ans,sum)

    print(ans)

if __name__ == "__main__":
  main()

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
X = [int(x) for x in stdin.readline().rstrip().split()]
ans = []
for i in range(101):
    s = 0
    for j in X:
        s += (j - i)**2
    ans.append(s)
print(min(ans))

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

m =round( sum(x) / n)

print(sum([(a - m) ** 2 for a in x]))

Solution (Python):
import math

def main():
    N = int(input())
    X = list(map(int, input().split()))
    min_tai = 1000000
    min_x = -1
    for x in range(min(X), max(X)+1):
        temp_tai = 0
        for temp_x in X:
            temp_tai += math.pow(x-temp_x, 2)
        if(temp_tai < min_tai):
            min_x = x
            min_tai = temp_tai
    print(int(min_tai))

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
n=int(input())
x=np.array(list(map(int, input().split())))
ave=int(np.mean(x)+0.5)
ans=((x-ave)**2).sum()
print(ans)

Solution (Python):

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

Solution (Python):
def rally(x):
    avg = sum(x) // len(x)
    sumf = sumc = 0
    for i in x:
        sumf += (i - avg) * (i - avg)
        sumc += (i - avg - 1) * (i - avg - 1)
    print(min(sumf, sumc))

if __name__ == "__main__":
    import sys
    in_str = []
    for line in sys.stdin:
        in_str.append(line)
    x = [int(_) for _ in in_str[1].split(' ')]
    rally(x)

Solution (Python):
import math

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

P = math.floor(sum(X)/N)

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

P = math.ceil(sum(X)/N)

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

answer = e if e<ea else ea
print(answer)

Solution (Python):
def main(n, x):
    ans = []

    for p in range(1, n + 101):
        t = 0
        for _x in x:
            t += (_x - p) ** 2

        ans.append(t)

    print(min(ans))


if __name__ == "__main__":
    n = int(input())
    x = list(map(int, input().split()))

    main(n, x)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    X = list(map(int,input().split()))
    X.sort()
    min = float("inf")
    s = X[0]
    g = X[N-1]
    for p in range(s,g+1):
        s = 0
        for x in X:
            s += (x-p)**2
        if min >= s:
            min = s
    print(min)

if __name__ == "__main__":
    main()

Solution (Python):

from heapq import heapify, heappop, heappush
from random import randint
from collections import defaultdict
from itertools import accumulate
from fractions import gcd
from collections import defaultdict
import sys

def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7

N = int(input())
X = inpl()
mean = sum(X) // N

ans = 10**9
for i in range(mean-1, mean+2):
    tmp = 0
    for x in X:
        tmp += (i-x)**2
    ans = min(ans, tmp)
print(ans)

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

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

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

min_cost = 1e10
for i in range(1, 101):
    cost = 0
    for x in X_list:
        cost += (x - i)**2
    if cost <= min_cost:
        min_cost = cost
print(min_cost)

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

Solution (Python):


n = int(input())
x = [int(i) for i in input().split()]
xm = min(x)
xmm = max(x)
min = 9999999999999
for p in range(xm,xmm+1):
    sum = 0
    for xi in x:
        sum += (xi-p)**2
    if sum < min:
        min = sum
print(min)

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

cand = []
for i in range(min(X), max(X)+1):
    tmp = 0
    for x in X:
        tmp += (x - i) ** 2
    cand.append(tmp)
print(min(cand))

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

m = sum(a) / len(a)
m = round(m)

cost = 0

for elem in a:
    cost += (elem - m) ** 2

print(cost)

Solution (Python):
import sys
import numpy as np

n=int(sys.stdin.readline())

x=np.array([sys.stdin.readline().split() for i in range(1)],np.int64)

min=(100**2)*n
for i in range(1,101):
    a=np.sum((i-x)**2)
    if a<min:
        min=a
print(min)

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

X=list(map(int,input().split()))
X=sorted(X,reverse=True)
if n==1:
  print(0)
  exit()

A=[]
for i in range(1,100):
  ans=0
  for j  in range(n):
    ans += abs(i-X[j])**2
  A.append(ans)
A = sorted(A)
print(A[0])

Solution (Python):


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

ans = 10 ** 9
for i in range(min(X), max(X) + 1):
    tmp = 0
    for x in X:
        tmp += (x - i) ** 2
    ans = min(ans, tmp)

print(ans)

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
S=sorted(L)
ans=float("inf")
for i in range(S[0],S[-1]+1):
	tmp=0
	for j in range(N):
		tmp+=(S[j]-i)**2
	
	ans=min(ans,tmp)
print(ans)

Solution (Python):


def main():
    n = int(input())
    x_list = list(map(int, input().split()))
    x_min = min(x_list)
    x_max = max(x_list)
    p_list = list()

    for i in range(x_min, x_max + 1):
        power = sum(map(lambda x: pow(x - i, 2), x_list))
        p_list.append(power)
    
    print(min(p_list))

if __name__ == "__main__":
    main()

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

cost = [sum([abs(x-i)**2 for x in X]) for i in range (min(X), max(X)+1)]
print(min(cost))

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]
mini = 1000000
for i in range(100) :
    buf = 0
    for j in range(len(X)) :
        buf += (X[j] - i) ** 2
    mini = min(mini,buf)

print(mini)

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

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    x = list(map(int, input().split(" ")))

    ave = round(sum(x)/n)
    

    d = 0
    for i in x:
        d += (i - ave)**2
    print(d)

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


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

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

ans = 10**9
for i in range(100):
  r = 0
  for j in range(100):
    r += ((i-j)**2)*A[j]
  ans = min(r,ans)
print(ans)

Solution (Python):
import sys
import socket

hostnames = ['N551J', 'F551C', 'X553M']
input_file = 'c1.in'
if socket.gethostname() in hostnames:
    sys.stdin = open(input_file)


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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    inf = 10 ** 20
    n = read_int()
    x = read_int_list()
    res = inf
    for p in range(1, 101):
        s = 0
        for i in range(n):
            s += (p - x[i]) ** 2
        if res > s:
            res = s
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

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

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def solve():
    n = II()
    x = LI()
    ans = inf
    for i in range(max(x) + 1):
        tmp = 0
        for xi in x:
            tmp += (xi - i) ** 2
        ans = min(tmp, ans)
    print(ans)
    return



if __name__ == '__main__':
    solve()

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


ans=10**6

for p in range(1,101):
    _sum=0
    for i in range(0,n):
        _sum += (x[i] - p)**2
    if ans > _sum:
        ans = _sum

print(ans)

Solution (Python):
N = int(input())
XX = list(map(int,input().split()))
sumX = sum(XX)
P = round(sumX/N)

ss = [(x-P)**2 for x in XX]
print(sum(ss))

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

    ave = round(sum(x)/n)
    ans = 0
    for i in range(n):
            ans += (x[i]-ave)**2
    print(ans)
main()

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
min_x, max_x = min(x), max(x)
min_cost = float('inf')
for i in range(min_x, max_x + 1):
    cost = 0
    for j in range(n):
        cost += (x[j] - i)**2
    if cost < min_cost:
        min_cost = cost
print(min_cost)

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

hp_list = []
for p in range(int(min(X_list)), int(max(X_list))):
    hp = 0
    for x in X_list:
        hp += abs(x - p) ** 2
    hp_list.append(hp)

print(min(hp_list) if len(hp_list) > 0 else 0)

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


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

    if i == min(x):
        max_n = sum

    if sum <= max_n:
        max_n = sum

if len(set(x)) == 1:
    max_n = 0

print(max_n)

Solution (Python):
import sys
from io import StringIO
import unittest

def resolve():
    n=int(input().strip())
    xs = list(map(int,input().strip().split()))

    minPw=9999999999999

    for i in range(1,101):
        sumPw=0
        for x in xs:
            sumPw+=(x-i)**2
        if sumPw < minPw:
            minPw = sumPw

    print(str(minPw))

    return

resolve()

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
X = np.array(lr())

def F(z):
    return ((X-z) ** 2).sum()
left = 0
right = 100
while right > left + 1:
    left_mid = (2*left + right) / 3
    right_mid = (left + 2*right) / 3
    if F(left_mid) < F(right_mid):
        right = right_mid
    else:
        left = left_mid

answer = min(F(int(left)), F(int(left)+1), F(int(left)+2))
print(answer)

Solution (Python):

def solve():
    N = int(input())
    X = list(map(int, input().split()))
    res = float('inf')
    for p in range(101):
        res = min(res, sum((x-p)**2 for x in X))
    return str(res)

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

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

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

minX=min(X)
maxX=max(X)

ans=float('inf')

for p in range(minX,maxX+1):
    culc=0
    for i in range(N):
        culc+=(X[i]-p)**2
    
    if ans>culc:
        ans=culc

print(ans)

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


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

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

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

print(ans)

Solution (Python):
round2 = lambda i:(i*2+1)//2
n = int(input())
plist = [int(i) for i in input().split()]
ass = round2(sum(plist)/n)
power = 0
for j in range(n) :
    power += (plist[j] - ass)**2
print(int(power))

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


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

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

P=round(sum(X)/N)

hp=0
for i in X:
  hp+= (i-P)**2

print(hp)

Solution (Python):
import math

n = int(input())
x = list(map(int, input().split()))
avr = sum(x) / n
avr_min = int(avr)
avr_max = math.ceil(avr)

ans = 0
a = 0
b = 0

if avr_min == avr_max:
  for j in range(n):
    ans += (x[j] - avr_min)** 2
  print(ans)
else:
  for j in range(n):
    a += (x[j] - avr_min)** 2
    b += (x[j] - avr_max)** 2
  print(min(a, b))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ans = 10**10
for i in range(101):
    tmp = [abs(i - x[j])**2 for j in range(n)]
    if sum(tmp) < ans:
        ans = sum(tmp)

print(ans)

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

x_min = min(x_list)
x_max = max(x_list)

def calc_sum(x_list, P):
    sum = 0
    for x in x_list:
        sum += (x-P)**2
    return sum

sum_temp = 10**23
for i in range(x_min, x_max + 1):
    if calc_sum(x_list, i) < sum_temp:
        ans_point = i
        sum_temp = calc_sum(x_list, i)
print(calc_sum(x_list, ans_point))

Solution (Python):

N = int(input())
Xs = input().split()

X =[]
for i in Xs:
	X.append(int(i))

minnum = 10000000000

for i in range(101):
	sumnum = 0
	for j in X:
		sumnum += (i-j)*(i-j)
	
	minnum = min(sumnum,minnum)

print(minnum)

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

X.sort()
min_power = float('inf')
for i in range(X[0], X[-1]+1):
    tmp = 0
    for x in X:
        tmp += pow(x - i, 2)
    min_power = min(min_power, tmp)
    
print(min_power)

Solution (Python):
import sys
N=input()
X=map(int, sys.stdin.readline().split())
X_MAX=max(X)

ans=float("inf")

for p in range(1,X_MAX+1):
    ans_kouho=0
    for x in X:
        ans_kouho+=(x-p)**2
    ans=min(ans,ans_kouho)    
print ans

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

num = 0
min_num = 1000000000000000000000000

for p in range(1,max(a)+1):
  for i in a:
    num += (i-p)**2
    
  if num < min_num:
    min_num = num
  
  num = 0

print(min_num)

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

costs = list()

for i in range(100):
    cost = 0
    for v in x:
        l = abs(v-i)
        cost += l ** 2
    costs.append(cost)
        
print(min(costs))

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

XM = max(X)
Xm = min(X)
ans = []
res = 0
for x in range(Xm, XM+1):
    for i in range(n):
        res += (X[i]-x)**2
    ans.append(res)
    res = 0
    
print(min(ans))

Solution (Python):
N = int(input())
X = [int(x) for x in input().split(' ')]
Pa = sum(X) // N
Pb = Pa + 1
Ca = Cb = 0
for i in range(N):
  Ca += (X[i] - Pa)**2
  Cb += (X[i] - Pb)**2
print(min(Ca, Cb))

Solution (Python):
import itertools
import sys

n = int(input())
x = list(map(int,input().split()))
ans = float('inf')
for i in range(min(x),max(x)+1):
    v = 0
    for j in x:
        v += (i-j)**2
    if v < ans:
        ans = v
print(ans)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
S=(sum(X))/N
e=S-int(S)
if e<=0.5:
  p=int(S)
  t=0
  for i in range(N):
    t=t+(X[i]-p)**2
  print(t)
else:
  p=int(S)+1
  t=0
  for i in range(N):
    t=t+(X[i]-p)**2
  print(t)

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

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

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

X.sort()
mi = X[0]
ma = X[N-1]

ans = 10**9
for i in range(mi,ma+1):
  sum = 0
  for j in range(N):
    sum += abs(X[j]-i)**2
  ans = min(ans, sum)

print(ans)