Problem:
 Score : 300 points    Problem Statement There are N people living on a number line.  The i -th person lives at coordinate X_i .  You are going to hold a meeting that all N people have to attend.  The meeting can be held at any integer coordinate . If you choose to hold the meeting at coordinate P , the i -th person will spend (X_i - P)^2 points of stamina to attend the meeting.  Find the minimum total points of stamina the N people have to spend.      Constraints  All values in input are integers.  1 \leq N \leq 100  1 \leq X_i \leq 100         Input Input is given from Standard Input in the following format:  N  X_1  X_2  ...  X_N       Output Print the minimum total stamina the N people have to spend.        Sample Input 1 2
1 4      Sample Output 1 5  Assume the meeting is held at coordinate 2 . In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.  Note that you can hold the meeting only at an integer coordinate.       Sample Input 2 7
14 14 2 13 56 2 37      Sample Output 2 2354

Solution (Python):
import statistics

N = int(input())
X = [int(i) for i in input().split()]
X.sort()
mid = statistics.mean(X)
ans = 0
ans1 = 0
ans2 = 0

for i in range(N):
    ans1 += (X[i] - int(mid)) ** 2
    ans2 += (X[i] - int(mid) - 1) ** 2
ans = min(ans1, ans2)

print(ans)

Solution (Python):
def calc(a):
    y = 0
    for xx in x:
        y += (a - xx) ** 2
    return y


n = int(input())
x = [int(i) for i in input().split()]
left = min(x)
right = max(x)
while (right - left > 1):
    l = calc(left)
    r = calc(right)
    if (l < r):
        right = (right + left) // 2
    else:
        left = (right + left) // 2
print(min(calc(left), calc(right)))

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

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

ans = 0
for p in range(1,101):
    sum = 0
    for x in X:
        sum += (x-p)**2
    if p == 1:
        ans = sum
    elif sum < ans:
        ans = sum

print(ans)

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

ans = 100000000000000
for i in range(101):
  temp = 0
  for j in range(len(A)):
    temp += (A[j]-i)**2
  if(temp < ans):
    ans = temp
print(ans)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
lmax=0
for i in range(n):
    if lmax<l[i]:
        lmax=l[i]
sumlist=[]
for i in range(lmax):
    sumlist.append(0)
total=0
for i in range(lmax):
    for j in range(n):
        t=(l[j]-(i+1))*(l[j]-(i+1))
        total+=t
    sumlist[i]=total
    total=0
min=10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
for i in range(lmax):
    if min>sumlist[i]:
        min=sumlist[i]
print(min)

Solution (Python):
n = int(input())
ls = list(map(int, input().split()))
ls2 =[]
for x in range(1,101):
    k = 0
    for y in ls:
        k += (x - y) ** 2
    ls2 += [k]
m = min(ls2)
print(m)

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

res = 999999999
for i in range(1, 101):
    res = min(res, sum([(i-xi)**2 for xi in x]))
print(res)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
import numpy as np
x = np.array(x)
mi = 1000000
for i in range(100):
  h = (x-i)**2
  s = h.sum()
  if s < mi:
    mi = s
print(mi)

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

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

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

l = []

for p in range(min(X), max(X)+1):
    cnt = 0
    for i in range(N):
        cnt += (X[i] - p) ** 2
    l.append(cnt)
print(min(l))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
INF = 114514191981036436433-4

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

Solution (Python):
import numpy as np
n=int(input())
x=list(map(int,input().split()))
b=round(sum(x)/len(x))
x=np.array(x)
x1=abs(x-b)
print(sum(x1*x1))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = sum(A)
C = 0
if(B%N < N/2):
  for i in(A):
    C += (B//N-i)**2
else:
  for i in(A):
    C += (B//N+1-i)**2
print(C)

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

res = 10**9

for i in range(101):
  res = min(res, sum([(i - x)**2 for x in X]))
  
print(res)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
if min(x) == max(x):
    print(0)
    exit()

dist_min = 9999999999999
for i in range(min(x),max(x)):
    dist_sum = 0
    for j in range(n):
        dist_sum += (x[j] - i)**2
    if dist_sum < dist_min:
        dist_min = dist_sum

print(dist_min)

Solution (Python):
n=int(input())
x=list(map(int, input().split()))
maxn=0
for i in range(n):
    if x[i]>maxn:
        maxn=x[i]
    else:
        maxn=maxn
minp=0
for j in range(n):
    minp=minp+(x[j]-1)**2
for i in range(maxn+1):
    power=0
    for j in range(n):
        power=power+(x[j]-i)**2
    if power<minp:
        minp=power
    else:
        minp=minp
print(minp)

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

ans = 100**3
for i in range(1, 100):
    tmp = 0
    for j in range(n):
        tmp += (a[j]-i)**2
    if tmp < ans:
        ans = tmp
print(ans)

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

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

    ans = 0

    for i in range(min(x_li), max(x_li)+1):
        sum_p = sum(list(map(lambda x: (x - i)**2, x_li)))
        if ans == 0:
            ans = sum_p
        elif sum_p < ans:
            ans = sum_p

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
P=(sum(A))//N
P0=P-1
P1=P+1
M,M1,M0=0,0,0
for i in A:
  M+=(i-P)**2
  M1+=(i-P1)**2
  M0+=(i-P0)**2
print(min(M,M1,M0))

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

Solution (Python):
x = int(input())
num = list(map(int, input().split()))
num.sort()
y = round(sum(num) / x)
sum_num = 0

for i in num:
  sum_num += (abs(i - y)) ** 2

print(sum_num)

Solution (Python):
people=int(input())
vector=list(map(int,input().split()))
min_cordination=min(vector)
max_cordination=max(vector)
sum_squared_list=[]
for i in range(min_cordination,max_cordination+1):
  tmp_sum_squared=0
  for one_person in vector:
    tmp_sum_squared+=(i-one_person)**2
  sum_squared_list.append(tmp_sum_squared)
print(min(sum_squared_list))

Solution (Python):
N = int(input())
X = [int(i) for i in input().split(' ')]
MIN = 10 ** 9
for i in range(101):
    SUM = 0
    for x in X:
        SUM += (x - i) **2
    if SUM < MIN:
        MIN = SUM

print(MIN)

Solution (Python):
import math
N = int(input())
X = list(map(int, input().split()))
E1 = 0
E2 = 0
x1 = math.floor(1/N*sum(X))
x2 = math.ceil(1/N*sum(X))
for i in range(N):
  E1 += (X[i]-x1)**2
  E2 += (X[i]-x2)**2
if E1 <= E2:
  print(E1)
else:
  print(E2)

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

print(ans)

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

min_power = 10**10


for i in range(1,101):
    power = 0
    for j in X:
        power += (j-i)**2
    min_power = min(min_power,power)

print(min_power)

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



def party(person_place,party_place):
    energy=pow(abs(party_place-person_place),2)
    return(energy)

if abs(sum(x)//len(x)-sum(x)/len(x))<0.5:
    party_place=sum(x)//len(x)
else:
    party_place=sum(x)//len(x)+1




answer=0    
for i in range(0,len(x)):
    answer+=party(x[i],party_place)
    
print(answer)

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

L = []
for i in range(1, 101):
    s = 0
    for j, v in enumerate(X):
        s = s + (v - i)**2
    L.append(s)
print(min(L))

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

print(min([sum([(x - p) ** 2 for x in xs]) for p in range(1, 101)]))

Solution (Python):
n = int(input())
*X, = map(int, input().split())
m = 10**10
for i in range(1, 100+1):
    m = min(m, sum([(x-i)**2 for x in X]))
print(m)

Solution (Python):
def main():
    N = int(input())
    X = [int(a) for a in input().split()]
    mi = 10**9
    for i in range(1, max(X) + 1):
        hp = sum([(X[j] - i)**2 for j in range(N)])
        if hp < mi:
            mi = hp
    print(mi)
if __name__ == "__main__":
    main()

Solution (Python):
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)


args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])


def main():
    """エントリーポイント"""
    N = input(int)
    X = input([int, N])
    f, c = floor(sum(X) / N), ceil(sum(X) / N)
    ans = [0, 0]
    for x in X:
        ans[0] += (f - x) ** 2
        ans[1] += (c - x) ** 2
    print(min(ans))


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Solution (Python):

def atcoder2():
    a = [list(map(int,input().split())) for l in range(2)]

    n= a[0][0]
    x_l = a[1]

    P = sum(x_l)/n

    
    
    if P - int(P) >= 0.5:
        add= 1
    else:
        add = 0

    P = int(P)+add
    
    

    result = 0
    for Xi in x_l:
        result = result + (Xi-P)**2 

    print(result)
    return 


atcoder2()

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

ans = 10 ** 9
for i in range(1, 101):
    tmp = np.square(x - i).sum()
    ans = min(ans, tmp)

print(ans)

Solution (Python):
import sys

num = []

while True:
    try:
        num.extend([int(n) for n in input().split()])
    except EOFError:
        break
    
s = sum(num[1:num[0]+1])/num[0]
s = round(s)
r = 0
for i in range(1,num[0]+1):
    r += pow(num[i]-s,2)
print(r)

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

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

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

Solution (Python):

url = "https://atcoder.jp//contests/abc156/tasks/abc156_c"

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

    syukai_pos = max(people_pos) + min(people_pos) // 2
    tmp = 0
    tmp2 = 0
    for pp in people_pos:
        tmp += (pp - syukai_pos) ** 2
        tmp2 += (pp - syukai_pos + 1) ** 2
    print(tmp) if tmp < tmp2 else print(tmp2)


def main2():
    n = int(input())
    people_pos = list(map(int, input().split()))
    people_pos.sort()
    count = 10000000000
    for i in range(people_pos[0] , people_pos[-1] + 1):
        tmp = 0
        for pp in people_pos:
            tmp += (pp - i) ** 2
        count = count if count < tmp else tmp
    print(count)




if __name__ == '__main__':
    main2()

Solution (Python):
n=int(input())
li = list(map(int,input().split()))
ans=[]
i=1
while i<=101:
	for j in range(n):
		cost=[(li[j]-i)**2 for j in range(n)]
		ans.append(sum(cost))
	i+=1
print(min(ans))

Solution (Python):
n = input()
l = map(int,raw_input().split())
mxs = 10**9


for i in range(max(l)+1):
    sm = 0
    for j in l:
        sm += (j-i)**2
    if sm<mxs:
        mxs = sm
print mxs

Solution (Python):
from collections import Counter
n=int(input())
x=list(map(int,input().split()))
max=max(x)
d=dict(Counter(x))
m=1000000
for i in range(1,max+1):
    s=0
    for key,vlaue in d.items():
        s+=(i-key)**2*vlaue
    m=min(s,m)
print(m)

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP
n = int(input())
x = list(map(int,input().split()))
a = sum(x)/n
a = int(Decimal(str(a)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
s=0
for i in range(n):
    s += (x[i]-a)*(x[i]-a)
print(s)

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

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

total = 100**n
for p in range(min(x), max(x) + 1):
    tmp = 0
    for i in x:
        tmp += (i - p)**2
    if tmp <= total:
        total = tmp

print(total)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
C=[]
for p in range(100):
    c=0
    for j in range(len(X)):
        c += (X[j] - p)**2


    C.append(c)

print(min(C))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ptc = 0
tc = 100**2*100
for i in range(min(X), max(X)+1):
    for k in X:
        ptc += (k-i)**2
    tc = min(ptc,tc)
    ptc = 0
print(tc)

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

Solution (Python):
N = int(input())
X = []
max_ = -1

for i in input().split(" "):
    tmp = int(i)
    if tmp > max_:
        max_ = tmp
    X.append(tmp)

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

print(ans)

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
n = int(input())
x = list(map(int, input().split()))

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

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

print(ans)

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

Solution (Python):


stdin = open(0)
import numpy as np
 

data = np.fromstring(stdin.read(), np.int64, sep=' ')
 

X = data[1:]
costs = []
for p in range(101):
    costs.append(np.sum((X-p)**2))
 

answer = min(costs)
print(answer)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=1e10
for i in range(1,101):
  sum=0
  for x in a: sum+=pow(abs(x-i),2)
  ans=min(ans,sum)
print(ans)

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

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

ans=[]
for i in range(a,b+1):
    total=0
    for j in X:
        total+=(i-j)*(i-j)
    ans.append(total)

print(min(ans))

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

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)



def in_int():
    return (int(input()))


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


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


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

mod = 7 + 10**9


n = in_int()

a = in_list()


aa = sum(a)//n

ans1 = 0
ans2 = 0

for xx in a:
    ans1 += (xx-aa)**2
    ans2 += (xx-aa-1)**2


print(min(ans1,ans2))

Solution (Python):
N = int(input())
List = list(map(int, input().split()))
s = 1000000000000000000000
t = 0

for i in range(100):
  for j in range(N):
    t += (List[j]-i-1)**2

  if s>t:
    s = t
    t = 0
  else:
    t = 0

print(s)

Solution (Python):
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split(' '))))
avg = np.mean(a)
mid_1 = np.ceil(avg)
mid_2 = np.floor(avg)
ans = int(min(((a-mid_1)**2).sum(), ((a-mid_2)**2).sum()))
print(ans)

Solution (Python):
N = int(input())
List = list(map(int, input().split()))
s = 1000000000000000000000
t = 0

for i in range(100):
  for j in range(N):
    t += (List[j]-i-1)**2

  if s>t:
    s = t
    t = 0
  else:
    t = 0

print(s)

Solution (Python):
def func(x_list, num):
    total = sum([(x - num)**2 for x in x_list])
    return total

N = int(input())
x_list = list(map(int, input().split()))
max_x = max(x_list)
min_num = func(x_list, 1)

for i in range(2, max_x+1):
    tmp = func(x_list, i)
    if min_num > tmp:
        min_num = tmp

print(min_num)

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

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

print(ans)

Solution (Python):
import sys

n, *x = map(int, sys.stdin.read().split())

def main():
    p = round(sum(x) / n)
    res = sum([(p - i) ** 2 for i in x])
    print(res)

if __name__ ==  '__main__':
    main()

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

ans = 10000000

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

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

import math

c1 = math.ceil(sum(xlst)/n)
c2 = math.floor(sum(xlst)/n)
s1 = [(c1-x)**2 for x in xlst]
s2 = [(c2-x)**2 for x in xlst]

print(min(sum(s1),sum(s2)))

Solution (Python):
n=int(input())
position=list(map(int,input().split()))
m=10000000
for i in range(101):
  accum=0
  for pos in position:
    accum+=(pos-i)**2
  m=min(accum,m)
print(m)

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

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

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

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

ans=1000000000

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

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

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

cnt = 1000000
for j in range(99):
    t = 0
    for i in li:
        t += (i-(j+1))**2
    if t <= cnt:
        cnt = t
print(cnt)

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

for p in range(x_list[0],x_list[-1]+1):
    cost_tot = 0
    for x in x_list:
        cost = (x-p)**2
        cost_tot += cost
    if cost_tot < cost_tot_min:
        cost_tot_min = cost_tot

print(cost_tot_min)

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


if __name__ == "__main__":
    resolve()

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

X_list = [int(n) for n in input().split()]
total = 0
for X in X_list:
    total += X

avg_left = total // N
avg_right = (total // N) + 1

dist_left = 0
dist_right = 0
for X in X_list:
    dist_left += (X - avg_left)**2
    dist_right += (X - avg_right)**2

print(min(dist_left,dist_right))

Solution (Python):


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

Xpwr = list()

for i in range (1, 101):
    Xpsum = list()

    for j in range(N):
        Xpsum.append((X[j] - i) ** 2)

    Xpwr.append(sum(Xpsum))

ans = min(Xpwr)
print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
x_ave = sum(x) // n
def moment(val):
    list_init = [0]*n
    for i in range(n):
        list_init[i] = (x[i] - val)**2
    return(sum(list_init))

print(min(moment(x_ave), moment(x_ave + 1)))

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

n = int(sum(aa) / len(aa) + 0.5)
a2sum = 0
for a in aa:
    a2sum += (a-n) **2
print(a2sum)

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

print(cost)

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

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

a = int(sum(x)//len(x))
b = a + 1
c = 0
d = 0

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

print(int(min(c,d)))

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

def cost_calc(list_x, p):
  cost = 0
  for x in list_x:
    cost += (x - p)**2
  return cost

cost = 10**20
for _ in range(min(list_x),max(list_x)+1):
  tmp = cost_calc(list_x, _)
  if tmp < cost:
    cost = tmp
print(cost)

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

def cost_calc(list_x, p):
  cost = 0
  for x in list_x:
    cost += (x - p)**2
  return cost

cost = 10**20
for _ in range(min(list_x),max(list_x)+1):
  tmp = cost_calc(list_x, _)
  if tmp < cost:
    cost = tmp
print(cost)

Solution (Python):
import math
N = int(input())
X = [int(x) for x in input().split()]
s = sum(X)
p = s/N
floor = s//N
if p-floor >= 0.5:
  m = math.ceil(s/N)
else:
  m = math.floor(s/N)
square = [x**2 for x in X]
result = N*m**2 - 2*s*m + sum(square)
print(result)

Solution (Python):
import math
import fractions
import sys
import itertools
import numpy as np
from collections import Counter
import datetime

def input1():
	return int(input())


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


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

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1


n=input1()
X=input_array()

min_p=min(X)
max_p=max(X)
b_p=10000
p=[]
for i in range(min_p,max_p):
	s=0
	for j in X:
		s+=(j-i)**2
	p.append(s)
	
	
	
	

if p==[]:
	print(0)
else:
	print(min(p))

Solution (Python):
stdin = open(0).read().split('\n')
N = int(stdin[0])
X = list(map(int,stdin[1].split()))
min=9999999
for i in range(1,101):
    sum=0
    for j in range(len(X)):
        sum+=(i-X[j])**2
    if sum<min:min=sum
print(min)

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

ans = float('inf')
for i in range(1,101,1):
    tai = 0
    for j in range(len(arr)):
        tai += (arr[j]-i)**2

    if tai <= ans:
        ans =tai

print(ans)

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

    tmp = (100**2)*100

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

    print(tmp)

main()

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

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

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

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

avex= sum(x) / N;

p = round(avex);

ans = sum([(a - p) ** 2 for a in x]);

print(ans)

Solution (Python):










mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    X = readInts()
    mid = (sum(X) + (n-1)) // n
    ans = float('inf')
    for k in range(-1,2,1):
        p = 0
        for i in range(n):
            p += (mid + k - X[i]) ** 2
        ans = min(ans,p)
    print(ans)
if __name__ == '__main__':
  main()

Solution (Python):
import math

N=input()
n=int(N)

p=input().split()
for i in range (len(p)):
    p[i]=int(p[i])

sum1=0

q=p.copy()

for i in range (len(q)):
    sum1=sum1+q[i]

avg=sum1/n

if avg-math.floor(avg)>=0.5:
    avg=math.floor(avg)+1
else:
    avg=math.floor(avg)


stamina=0

for i in range(len(p)):
    stamina=stamina+(avg-p[i])**2
    
print(stamina)

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

Solution (Python):
N = int(input())
x = input().split()
avg = 0

for i in range (N) :
    x[i] = int(x[i])
    avg += x[i]

avg1 = avg // N
avg2 = avg // N + 1

ans1 = 0
ans2 = 0

for i in range (N) :
    ans1 += (x[i] - avg1) ** 2
    ans2 += (x[i] - avg2) ** 2

print (int(min(ans1 , ans2)))

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

ans = int (2e9)
l, r = min (x), max (x)

for p in range (l, r + 1) :
    tmp = 0
    for loc in x:
        tmp += (loc - p) ** 2
    ans = min (ans, tmp)

print (ans)

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

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

print(ans)

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

ans = -1
for i in range(100):
    z = 0
    for x in X:
        z += (x-i) * (x-i)
    if ans == -1 or z < ans:
        ans = z

print(ans)

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

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

print(ans)