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 fractions
import collections
from collections import deque
import math
import itertools

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

ans=10000000
for i in range(1,101):
    tmp=0
    for j in range(N):
        tmp+=(i-X[j])**2
    ans=min(tmp,ans)
print(ans)

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

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

miner = 10**100
for i in range(1, 101):
    sumer = 0
    for j in x:
        sumer += (j - i)**2
    miner = min(miner ,sumer)

print(miner)

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

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

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

ans = float('inf')
for p in range(min(X), max(X)+1):
  ans = min(ans, sum([(p-x)**2 for x in X]))

print(ans)

Solution (Python):
def calc(X, i):
    return sum([(x-i)**2 for x in X])


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

ans = float('inf')

for i in range(1, 101):
    c = calc(X, i)
    ans = min(ans, c)

print(ans)

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

    print(ans)


if __name__ == "__main__":
    main()

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

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

    if tmp < ans:
        ans = tmp

print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
x=list(map(int,input().split()))
s=sum(x)
a=s//n
temp=0
for i in range(n):
    temp+=(x[i]-a)**2
ans=temp
a+=1
temp=0
for i in range(n):
    temp+=(x[i]-a)**2
ans=min(ans,temp)
print(ans)

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

x = round(sum(a) / n)

print(sum((i - x) ** 2 for i in a))

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

mn =  10000000000
for i in range(1,101):
    sm =0
    for j in x:
        sm += (j-i)*(j-i)
    if sm < mn :
        mn = sm
print(mn)

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

minv = 1000000000000


for i in range(1, 101):
    v = 0
    for j in A:
        v += (j-i)*(j-i)
    minv = min(minv, v)

print(minv)

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

min_d = 10000000

for p in range(1,101):
    d = 0
    for x in X:
        d += (x-p)**2
    if d <= min_d:
        min_d = d
print(min_d)

Solution (Python):
import numpy as np

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

minval = 1000000000000
ans=0
for candidate in range(101):
    tmp = sum((X-candidate)**2)
    if tmp < minval:
        minval=tmp
        ans = candidate

print(minval)

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    vn = vk = vn_k = 1
    for i in range(1, n+1):
        vn = vn * i % modp
        if i == k:
            vk = vn
        if i == n-k:
            vn_k = vn
    return vn * get_inv(vk, modp) * get_inv(vn_k, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp



def main():
    N=ii()
    import numpy as np
    X = np.array(lmis())
    ans = INF
    for i in range(1, 100+1):
        ans = min(ans, np.sum((X-i)**2))
    print(ans)

main()

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

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

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

Solution (Python):
def subpow(x, p):
    return (x - p) ** 2

n = int(input())
x = sorted(map(int, input().split()))
mini = 10000000000000
for p in range(x[-1] + 1):
    sum = 0
    for i in range(n):
        sum += subpow(x[i], p)
    mini = min(sum, mini)
print(mini)

Solution (Python):



from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe




def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)

def pin(type=int):
    return map(type,input().split())
    

"""
"""


def dis2(a,p):
    return (a-p)**2

N,=pin()
X=sorted(list(pin()))

ans=0
mx=100000000
for p in range(X[0],X[-1]+1):
    temp=0
    for x in X:
        temp+=dis2(x,p)
    if temp < mx:
        ans=p
        mx=temp
print(mx)


"""


"""
"""
お前カッコ閉じるの忘れてるだろ
"""

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

lo=min(x)
hi=max(x)
ans=float('inf')
for p in range(lo, hi+1):
    newx=(x-p)**2
    tmp=np.sum(newx)
    ans=min(ans,tmp)
print(ans)

Solution (Python):
n,*a=map(int,open(0).read().split())
ave=sum(a)//n
b=sum((x-ave)**2 for x in a)
c=sum((x-ave-1)**2 for x in a)
print(min(b,c))

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

ans = 1000000000
for P in range(min(X), max(X) + 1):
    S = sum([(Xi - P) * (Xi - P) for Xi in X])
    ans = min(ans, S)
print(ans)

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

P1 = sum(Xs)//N
P2 = P1+1

ans1 = sum([(X-P1)**2 for X in Xs])
ans2 = sum([(X-P2)**2 for X in Xs])


print(min(ans1, ans2))

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

ans = float('inf')
for i in range(1, 101):
    total = 0
    for j in range(N):
        total += (X[j] - i)**2
    ans = min(ans, total)

print(ans)

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

ans = 10 ** 9

for p in range(1,100+1):
    sum_len = 0
    for q in X:
        sum_len += (q-p)**2

    ans = min(ans,sum_len)

print(ans)

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

X.sort()

def solve(X, P):
    ans = 0
    for x in X:
        ans += (P - x)**2
    return ans

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

Solution (Python):
a = int(input())
l = list(map(int,input().split()))
m = 1000000000

for i in range(1,101):
    t = 0
    for j in l:
        t += (i-j)**2

    m = min(t,m)
print(m)

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


def get_vital_sum(pos):
    ret = 0
    for x in X:
        ret += (pos - x) ** 2
    return ret


ans = 100000000
for p in range(1,101):
    ans = min(ans, get_vital_sum(p))

print(ans)

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

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

target = round(sum(xn) / xn.__len__())

print(sum([(i - target) * (i - target) for i in xn]))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    ans=10**9
    n=II()
    xx=LI()
    for p in range(1,101):
        cur=sum((p-x)**2 for x in xx)
        ans=min(cur,ans)
    print(ans)

main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())
X = [int(x) for x in input().strip().split()]

def f(p):
    ret = 0
    for x in X:
        ret += (x - p) ** 2
    return ret

ans = float('inf')
for i in range(1, 101):
    ans = min(ans, f(i))

print(ans)

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

ans = 10 ** 9
for kaisai in range(100 + 1):
    tairyoku = 0
    for c in coord:
        tairyoku += (c - kaisai) ** 2
    ans = min(ans, tairyoku)

print(ans)

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

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

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


def get_score(i):
  res = 0
  for x in X:
    res += (x-i)**2
  return res
    
ans = float('inf')
for  i in range(1,101):
  ans = min(get_score(i),ans)
print(ans)

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

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

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

print(answer)

Solution (Python):
import math
n = int(input())
x = list(map(int, input().split()))
a = sum(x)//n
b = math.ceil(sum(x)/n)
ma = 0
mb = 0
for i in x:
	ma += (i-a)**2
for i in x:
	mb += (i-b)**2
print (min(ma,mb))

Solution (Python):
n = int(input())
xl = list(map(int, input().split()))
xl.sort()
t = xl[0]
INF = float("inf")
ans = INF
for p in range(t, xl[-1]+1):
    ans = min(ans, sum([(x-p)**2 for x in xl]))
print(ans//1)

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

ans = 10**10

for p in range(1,101) :
    sump = 0
    for x in list_X :
        sump += (x-p)**2
    ans = min(ans,sump)

print(ans)

Solution (Python):
from math import factorial
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


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


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def MS(): return map(str, input().split())


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']



show_flg = True


def main():
    N = I()
    X = LI()
    mi = 10**19

    for p in range(1, 101):
        temp = 0
        for i in range(N):
            temp += (X[i] - p) ** 2
        mi = min(temp, mi)

    print(mi)


if __name__ == '__main__':
    main()

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

print(ans)

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

x.sort()

ans=10**9
for i in range(111):
    sm=0
    for tmp in x:
        sm+=(tmp-i)**2
    if ans > sm:
        ans=sm
print(ans)

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

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

print(ans)

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

Solution (Python):
import math

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

center = sum(X) / len(X)
if center - int(center) >= 0.5:
    center = math.ceil(center)
else:
    center = math.floor(center)
ans = 0
for x in X:
    ans += (center - x) ** 2
print(ans)

Solution (Python):
import numpy as np

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

ans = 10**10
for i in range(1, 101):
    v = ((X - i)**2).sum()
    if ans > v:
        ans = v
print(ans)

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

m=sum(X)//N
if sum(X)/N-m>=0.5:
    m+=1
ans=0
for i in range(N):
    ans+=(X[i]-m)**2

print(ans)

Solution (Python):
from math import floor
N = int(input())
X = list(map(int,input().split()))
avg = sum(X)/N
l = floor(avg)
r = floor(avg)+1
ans1 = sum([(x-l)**2 for x in X])
ans2 = sum([(x-r)**2 for x in X])
print(min(ans1,ans2))

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
mX = sum(X)//n
mX1 = mX+1
r = 0
r1 = 0
for i in range(n):
    r += (X[i]-mX)**2
    r1 += (X[i]-mX1)**2
print(min(r, r1))

Solution (Python):
N = int(input())
*X, = map(int, input().split())
ans = 10**20
for i in range(100):
    s = sum([(x-i)*(x-i) for x in X])
    if s < ans:
        ans = s
print(ans)

Solution (Python):
from bisect import bisect_right, bisect_left
from collections import Counter, deque
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import groupby, permutations, combinations, product
from sys import stdin, stderr





def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)





def exgcd(x, y):
    if y == 0:
        return 1, 0
    a, b = exgcd(y, x % y)
    return b, a - (x // y) * b



def lcm(x, y):
    m = gcd(x, y)
    return (x // m) * (y // m)


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    ave = sum(xs) // n
    kouho = 0
    kouho2 = 0
    ave2 = ave + 1
    for i in range(n):
        kouho += pow(xs[i] - ave, 2)
        kouho2 += pow(xs[i] - ave2, 2)

    return min(kouho, kouho2)


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

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

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

ans=float('inf')
for i in range(101):
  tmp=0
  for j in range(n):
    tmp+=(i-X[j])**2
  ans=min(ans,tmp)
print(ans)

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

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

ans = 10000000000

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

print(ans)

Solution (Python):
def main():
    N = int(input())
    X = list(map(int, input().split()))
    P = [sum(X) // N]
    P.append(P[0] + 1)
    answer = [0, 0]
    for x in X:
        for i in range(2):
            answer[i] += (x - P[i]) ** 2
    print(min(answer))


if __name__ == '__main__':
    main()

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

P = int(sum(X) / N + 0.5)
print(sum((x - P) * (x - P) for x in X))

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

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

ans = 0
m = 10 ** 1000

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

print(m)

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

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

ave = sum(x)/n
p = round(ave)
res = 0
for i in x:
  res += (i -p )**2
print(res)

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

ans = 10**10
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()))

ans = -1
for i in range(100):
    I = i + 1
    res = 0
    for j in range(N):
        res += (I - X[j]) * (I - X[j])
    if ans == -1:
        ans = res
    else:
        ans = min(ans, res)

print(ans)

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

ans = 10 ** 10

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

print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
res = INF
for i in range(1,101):
    p = i
    cnt = 0
    for j in range(n):
        cnt += (p-a[j]) ** 2
    res = min(res,cnt)
print(res)

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

Solution (Python):
import numpy as np

N = int(input())
X = np.fromstring(input(), int, sep=" ")

minimum = X.mean().round().astype(int)
print(((X - minimum) ** 2).sum())

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X.sort()
x_min = X[0]
x_max = X[-1]

ans = 10**20
for xi in range(x_min, x_max+1):
  temp = 0
  for xj in X:
    temp += (xi - xj)**2
  
  ans = min(ans, temp)

print(ans)

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

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

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    ans = INF
    for i in range(1, 101):
        t = 0
        for j in range(n):
            t += (i - v[j]) ** 2
        ans = min(ans, t)
    print(ans)

if __name__ == '__main__':
    main()

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

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

print(ans)

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

if __name__ == '__main__':
    main()

Solution (Python):

n=int(input())
a=[int(k) for k in input().strip().split(" ")]

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

print(min(r1,r2))

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

dist = 0
ans = 1e6

for i in range(101):
    p = i
    dist = 0
    for j in range(N):
        dist += (X[j]-p)**2
    ans = min(ans,dist)

print(ans)

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

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

a = sum(X) // N
b = sum(X) // N + 1

ans = float("inf")

for p in [a, b]:
	res = 0
	for x in X:
		res += (x - p) ** 2
	ans = min(ans, res)
	
print(ans)

Solution (Python):


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

ans = float("inf")

for i in range(1,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()))
print(min([sum([(x - P)**2 for x in X]) for P in range(1, 100)]))

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

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

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

ans = 10**10

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

print(ans)

Solution (Python):
import sys

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

def main():
    m = round(sum(x) / n)
    s = 0
    for i in range(n):
        s += (m - x[i]) ** 2
    
    return s

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

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
ans = 100000000
for p in range(101):
    tmp = 0
    for x in X:
        tmp += (x - p) ** 2
    if tmp < ans:
        ans = tmp
print(ans)

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

p1 = sum(x) // len(x)
p2 = p1 + 1

sum1 = sum([(item - p1) ** 2 for item in x])
sum2 = sum([(item - p2) ** 2 for item in x])
print(min(sum1, sum2))

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

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

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

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

    ans = 10000000
    for i in range(101):
        s = 0
        for x in X:
            s += (x - i) ** 2
        if ans > s:
            ans = s
    print(ans)

if __name__ == '__main__':
    main()

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

res = []

for p in range(101):
  res.append(sum([(xi - p) ** 2 for xi in x]))

print(min(res))

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
ans = float("inf")
for i in range(1,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(int, input().split()))
a = 1e6
for p in range(1, 101):
    t = 0
    for i in range(n):
        t += (x[i] - p) ** 2
    a = min(a, t)
print(a)

Solution (Python):

import sys
input = sys.stdin.readline

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

ans = 10**12 
for i in range(101):
    val = 0
    for item in x:
        val += (item - i) * (item - i)
    ans = min(ans, val)
print(ans)

Solution (Python):
import sys
from collections import Counter
n = int(input())
x_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(x_ls)
INF = 10**18
ans = INF
for i in range(1,101,1):
    res = 0
    for k, v in ct.items():
        res += v * abs(k - i) ** 2
    ans = min(res, ans)
print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
ans = float('inf')
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()))

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

print(ans)

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

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

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

ans=1000000

for i in range(1,101):
    cnt=0
    for q in X:
        cnt+=(q-i)**2
    ans=min(cnt,ans)

print(ans)

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

min_x = min(x_list)
max_x = max(x_list)
min_power = 10000 * 1000
for i in range(min_x, max_x + 1):
    check_power = 0
    for j in x_list:
        check_power += (j - i) * (j - i)
    if(check_power < min_power):
        min_power = check_power
print(min_power)

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

Solution (Python):
NN = 2020202
MOD = 10**9+7
INF = float("inf")

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

vmin = float("inf")
for i in range(1, 101):
    vtmp = 0
    for j in X:
        vtmp += (i-j)**2
    vmin = min(vtmp, vmin)

print(vmin)

Solution (Python):


from collections import deque, defaultdict
import itertools as ite
import sys
import math
from decimal import *

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
X = map(int, raw_input().split())
ans = INF
for pos in range(1, 101):
    S = 0
    for x in X:
        S += (x - pos) * (x - pos)
    ans = min(ans, S)
print ans

Solution (Python):
def c_rally():
    import numpy as np
    import math
    N = int(input())
    X = [int(i) for i in input().split()]
    m = np.average(X)
    ans = float('inf')
    for j in (math.floor(m), math.ceil(m)):
        ans = min(ans, sum([(x - j)**2 for x in X]))
    return ans

print(c_rally())

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

ANS=1<<63

for i in range(101):
    ANS=min(ANS,sum([(X[j]-i)**2 for j in range(N)]))

print(ANS)

Solution (Python):
from statistics import median as m
n=int(input())
x=list(map(int,input().split()))
r=sum(x)//n
c,d=0,0
for i in range(n):
    c+=(x[i]-r)**2
    d+=(x[i]-r-1)**2
print(min(c,d))

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

ans = 10**18

for i in range(101):
    S = 0
    for x in X:
        S += (i - x) * (i - x)
    ans = min(ans, S)
print(ans)

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

value = 1e100
for p in [center, center + 1]:
    value = min(value, sum(map(lambda x: (x - p) ** 2, xs)))

print(value)

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

Solution (Python):
import sys
import math
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

N = int(input())
X = list(map(int,input().split()))
ans = INF
for i in range(1, 101):
    temp = 0
    for l in X:
        temp += (l-i)**2
    if temp < ans:
        ans = temp
print(ans)

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N = I()
X = LI()

X.sort()

ans = float('inf')
for p in range(X[0],X[-1]+1):
    now = 0
    for i in range(N):
        now += (X[i]-p)**2
    if now < ans:
        ans = now

print(ans)

Solution (Python):
from math import log, ceil
n = int(input())
x_array = [int(x) for x in input().split()]
ans = float("inf")
for i in range(1, max(x_array)+1):
    tmp = 0
    for x in x_array:
        tmp += (x-i)**2
    ans = min(ans, tmp)
print(ans)

Solution (Python):

import sys


def solve(N: int, X: "List[int]"):
    ans = 10000000
    for i in range(1, 101):
        s = 0
        for x in X:
            s += (x - i)*(x - i)
        ans = min(ans, s)

    print(ans)



    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()))
INF = float('inf')
loss = INF
for i in range(1,101):
  tmp = 0
  for x_ in x:
    tmp += (x_-i)**2
  loss = min(tmp,loss)
print(loss)

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

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

Solution (Python):
import math

n = int(input())
x = list(map(int, input().split()))
avg1 = int(math.ceil(sum(x) / n))
avg2 = int(math.floor(sum(x) / n))
ans1 = 0
ans2 = 0
for i in x:
  ans1 += (i - avg1) ** 2
  ans2 += (i - avg2) ** 2
print(min(ans1,ans2))

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

print(ans)

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

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