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



Sample input:
2
1 4


Sample output:
5

Submission status: Accepted

Solution code:
ninzuu = int(input())
a_list = list(map(int, input().split()))
min_zahyou = min(a_list)
max_zahyou = max(a_list)
ans = 0

for i in range(min_zahyou, max_zahyou+1):
  tmp_sum = 0
  for j in a_list:
    tmp_sum += (j-i)**2
  if ans == 0 or ans > tmp_sum:
    ans = tmp_sum

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
ans=1000000000000
for i in range(min(x),max(x)+1):
  tmp=0
  for j in x:
    tmp += (j-i)**2
  if ans >= tmp:
    ans=tmp
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = [int(x) for x in input().split()]
m = sum(l) / n
s = 0
sp = 0

if sum(l) % n == 0:
    now = sum(l) // n

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

    print(s)
    
else:
    now = sum(l) // n

    for x in l:
        s += (now - x) * (now - x)
        sp += (now - x + 1) * (now - x + 1)

    print(s if (s < sp) else sp)

Submission status: Accepted

Solution code:
N = int(input())
S=0
x = list(map(int, input().split()))
for i in range(N):
    S += x[i]

p = round(S/N)
s =0
for i in range(N):
    s+=(p-x[i])**2
print(s)

Submission status: Accepted

Solution code:
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/g.inp"
exit $?
'''
import sys

def _i(): return int(sys.stdin.readline().strip())
def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

n = _i()
x = sorted(_ia())

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

Submission status: Accepted

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

def f(X,P):
    ans=0
    for i in range(len(X)):
        ans+=(X[i]-P)**2
    return ans
ans=10**9
for p in range(1,101):
    ans=min(ans,f(X,p))
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int, input().split()))
min_s=1000000
for i in range(min(X),max(X)+1):
  s = sum([(j-i)**2 for j in X])
  min_s = min(min_s, s)
print(min_s)

Submission status: Accepted

Solution code:
N=int(input())
lx=list(map(int,input().split()))
pav=sum(lx)/N
a=int(pav)
b=a+1
sa=0
sb=0
for i in range(N):
    sa+=(lx[i]-a)**2
    sb+=(lx[i]-b)**2
print(min(sa,sb))

Submission status: Accepted

Solution code:
n=input()
arr=[int(i) for i in input().split()]
arr.sort()
ansmin=99999999
for i in range(arr[0],arr[-1]+1):
    ans=0
    for j in arr:
        ans+=(i-j)**2
    ansmin=min(ansmin,ans)
print(ansmin)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    X = [int(i) for i in readline().split()]

    m = sum(X) / N
    m = round(m)

    ans = 0
    for i in X:
        ans += (i - m)**2
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    ans = []
    for p in range(100):
        dis = 0
        for x in X:
            dis += pow((x-p), 2)
        ans.append(dis)

    print(min(ans))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
import math
N = int(input())
X = np.array(list(map(int, input().split())))

P_floor = math.floor(np.sum(X)/N)
P_ceil = math.ceil(np.sum(X)/N)

ans = min(np.sum((X-P_floor)**2), np.sum((X-P_ceil)**2))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
miner = 1000000000000
for p in range(1,101):
    cnt = 0
    for g in range(n):
        cnt += (x[g]-p)**2
    if cnt < miner:
        miner = cnt
print(miner)

Submission status: Accepted

Solution code:
N = int(input())
X = [int(n) for n in input().split()]
ans = 10000000
for n in range(101):
    p = 0
    for x in X:
        p += (x - n) ** 2
    ans  = min(p,ans)
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

p1 = sum(x)//len(x)
p2 = p1 + 1
s1 = 0
s2 = 0
for i in x:
  s1 += (p1-i)**2
  s2 += (p2-i)**2
print(min(s1,s2))

Submission status: Accepted

Solution code:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    X = LMIIS()
    to2 = 0
    sumX = sum(X)
    for x in X:
        to2 += x**2
    
    P = round(sumX / N)
    

    print(to2 -2*sumX*P + N*P**2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
x = inl()
mn = 10**8
for p in range(1,101):
    sm = 0
    for j in range(n):
        sm += (x[j]-p)**2
    mn = min(mn,sm)
print(mn)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 10 ** 7
for p in range(1, 101):
    s = 0
    for i in range(n):
        s += (x[i] - p) ** 2
    ans = min(ans, s)

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
xs = [int(x) for x in input().split()]

def variance(xs,mean):
    return sum([(x-mean)**2 for x in xs])

mean = sum(xs)/N
variance1 = variance(xs,int(mean))
variance2 = variance(xs,int(mean)+1)
print(min(variance1,variance2))

Submission status: Accepted

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

res = float('inf')
for p in range(100+1):
    tmp = sum([(i-p)**2 for i in x])
    res = min(res, tmp)
print(res)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int , input().split()))
g = round(sum(x) / n)

ans = 0
for xi in x:
    ans += (g - xi) ** 2
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
N=int(input())
X=list(map(int,input().split()))
cost=0
for i in range(N):
    cost+=(X[i]-1)**2
for i in range(2,101):
    cost1=0
    for j in range(N):
        cost1+=(X[j]-i)**2
    if cost1<cost:
        cost=cost1
    
print(cost)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
ans = 1000000
for i in range(1, 101):
    tmp = 0
    for j in x:
        tmp += int((j - i) ** 2)
    if ans > tmp:
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

SQ_total = 0
total = 0

for i in X:
  total += i
  SQ_total += i**2
  
ans = 100 * 100 * 2

for P in range(1,101):
  temp = N * P * P - 2 * P * total # -2(total)P + N*P^2
  ans = min(ans, temp)
  
print(SQ_total + ans)

Submission status: Accepted

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

ans = 0
me = int(round(np.mean(l)))
#print(me)
for i in range(n):
  ans += (l[i]-me)**2
print(ans)

Submission status: Accepted

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

ave=sum(X)//N

s1=0
s2=0

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

for i in range(N):
    s2=s2+(X[i]-ave-1)**2

print(min(s1,s2))

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
a=10**9
for i in range(min(x),max(x)+1):
    b=0
    for k in range(n):
        b+=(x[k]-i)**2
    a=min(a,b)
print(a)

Submission status: Accepted

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

ans = 10 ** 9

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

for i in range(x_min, x_max+1):
    tmp = sum([(i-j)*(i-j) for j in x])
    if ans > tmp:
        ans = tmp

print(ans)

Submission status: Accepted

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

ave = 0
for i in range(N):
    ave += X[i]
ave //= N

ans1,ans2 = 0,0
for i in range(N):
    ans1 += (X[i] - ave)**2
    ans2 += (X[i] - ave-1) ** 2

print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = int(input())
    X = list(iim())

    av = sum(X) / N
    av = int((2*av+1) // 2)
    ans = 0
    for x in X:
        ans += (x - av)**2
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

X.sort()
ans = sum(X) // len(X)
ans1 = ans + 1

tmp = 0
tmp1 = 0
for i in X:
    tmp = tmp + (i - ans) ** 2
    tmp1 = tmp1 + (i - ans1) ** 2
print(min(tmp, tmp1))

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
x = np.asarray(input().split(), dtype=np.int64)

p = np.mean(x)

p = (p+0.5).astype(np.int64)

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
x = list(map(int, input().split()))
n = round(sum(x)/N)
tmp=[]
for i in range(N):
    tmp.append((x[i] - n) **2)
print(sum(tmp))

Submission status: Accepted

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

optimum = 10 ** 18
for i in range(1, 101):
    total = 0
    for x_i in x:
        total += (x_i - i) ** 2
    optimum = min(optimum, total)
print(optimum)

Submission status: Accepted

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

m = max(Xn)

ans = 10**9
for i in range(m+1):
    k = sum((x-i)**2 for x in Xn)
    ans = min(ans, k)

print(ans)

Submission status: Accepted

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

x = sorted(x)

mi = 0
for i in range(len(x)):
    mi += (x[i] - x[0])**2

for j in range(x[0], x[-1]+1):
    temp = 0
    for i in range(len(x)):
        temp += (x[i] - j)**2

    mi = min(temp, mi)

print(mi)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    xs = sorted(list(map(int, input().split())))

    min_total_energy = 1e9
    for p in range(xs[0], xs[-1] + 1):
        total_energy = 0
        for i in range(n):
            total_energy += (xs[i] - p)**2
        min_total_energy = min(min_total_energy, total_energy)

    print(min_total_energy)

Submission status: Accepted

Solution code:
# じょえチャンネル
# 高評価・チャンネル登録宜しくお願いします！
# https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ

import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')
def Z(f):
    if f:
        print('Yay!')
    else:
        print(':(')
def ispow(n):
    if int(n**.5)**2==n:
        return True
    return False

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

res = 10 ** 100
for i in range(-100, 200):
    tmp = 0
    for j in a:
        tmp += (i - j) ** 2
    res = min(res, tmp)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 10**31

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

Submission status: Accepted

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

c = [0] * 100

for p in range(100):
    for x in X:
        c[p] += (x - (p + 1)) ** 2

print(min(c))

Submission status: Accepted

Solution code:
n = int(input())
#a,b = map(int,input().split())
x_L = list(map(int,input().split()))

def destance(a,b):
    return (a-b)**2

x_L = list(sorted(x_L))
start = x_L[0]
end = x_L[-1]

ans = 10**20
for i in range(start,end+1):
    tmp = 0
    for k,val in enumerate(x_L):
        tmp += destance(x_L[k],i)
    ans = min(ans,tmp)
print(ans)

Submission status: Accepted

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

avg = sum(X) // N

c1 = avg
c2 = avg + 1

ans1 = 0
ans2 = 0
for xi in X:
    ans1 += (xi - c1) ** 2
    ans2 += (xi - c2) ** 2

ans = min(ans1, ans2)
print(ans)

Submission status: Accepted

Solution code:
def read():
    N = int(input().strip())
    X = list(map(int, input().strip().split()))
    return N, X

def solve(N, X):
    smin = 1000000000
    for p in range(1, 101):
        s = sum([(x - p) ** 2 for x in X])
        smin = min(smin, s)
    return smin


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
x = sorted(list(map(int,input().split())))
ans = float("inf")
def solve(p,m):
  a = len(m)
  b = 0
  for i in range(a):
    b += (m[i]-p)**2
  return b
for j in range(1,101):
  ans = min(ans,solve(j,x))
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
xs=list(map(int,input().split()))
p1=sum(xs)//n
p2=(sum(xs)+n-1)//n
print(min(sum((x-p)*(x-p) for x in xs) for p in (p1,p2)))

Submission status: Accepted

Solution code:
import sys
import heapq
import copy
import numpy as np
from collections import deque

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

cnt=10**10

for p in range(min(x),max(x)+1):
    curcnt=0
    for xx in x:
        curcnt+=(xx-p)**2
    cnt=min(cnt,curcnt)
print(cnt)

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    X=list(map(int,input().split()))
    ans=100**2*n
    for p in range(101):
        s = 0
        for x in X:
            s += (x-p)**2
        ans = min(ans, s)
    print(ans)
main()

Submission status: Accepted

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

min_sum = 10e9
for i in range(1,100):
    sum = 0
    for j in range(0,n):
        sum += (x[j]-i)*(x[j]-i)
    if sum < min_sum:
        min_sum = sum
print(min_sum)

Submission status: Accepted

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

median = round(sum(X) / N)
res = 0
for i in X:
    res += (i - median) ** 2
print(res)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
for i in range(1,101):
  if i == 1:
    x=sum([(i-a)**2 for a in X])
  else:
    _x=sum([(i-a)**2 for a in X])
    if x<_x:
      break
    else:
      x=_x
print(x)

Submission status: Accepted

Solution code:
N = int(input())
Xs = list(map(lambda x: int(x), input().split(" ")))

result = float("inf")

min_num = min(Xs)
max_num = max(Xs)

for i in range(min_num, max_num+1):
    temp_result = 0
    for x in Xs:
        temp_result += pow(x-i, 2)
    result = min(result, temp_result)


print(result)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
n = int(input())
x = [int(i) for i in input().split()]
ls1 = []
ls2 = []
mx = sum(x)/n
if math.ceil(mx) == math.floor(mx):
    for i in range(n):
        ls1.append((x[i]-mx)**2)
    print(int(sum(ls1)))
else:
    l = math.floor(mx)
    m = math.ceil(mx)
    for i in range(n):
        ls1.append((x[i]-l)**2)
        ls2.append((x[i]-m)**2)
    print(int(min(sum(ls1),sum(ls2))))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
ans = 10**10

for i in range(min(x), max(x)+1):
    temp = 0

    for j in range(n):
        temp += (i - x[j])**2

    ans = min(ans, temp)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

s = 0
for i in X:
    s += i
s = s/N

muf = math.floor(s)
muc = math.ceil(s)
ansf = 0
ansc = 0
for i in X:
    ansf += (muf-i)**2
    ansc += (muc-i)**2

print(min(int(ansf),int(ansc)))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    X = [int(i) for i in input().split()]
    ans = 10**9
    for i in range(1, 101):
        p = i
        cur = 0
        for j in range(N):
            cur += (X[j] - p)**2
        ans = min(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int, input().split()))
ans = 10 ** 18

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

Submission status: Accepted

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

ave = sum(X) / N
ave = round(ave)

ans = 0

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

Submission status: Accepted

Solution code:
n=int(input())
xlist=list(map(int,input().split()))
stamin=10**7
for i in range(1,101):
    sta=0
    for j in range(n):
        sta+=(xlist[j]-i)**2
    if stamin>sta:
        stamin=sta
print(stamin)

Submission status: Accepted

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

avg = round( sum(x) / len(x) )

result = 0
for i in x:
  result += (i - avg)**2

print(result)

Submission status: Accepted

Solution code:
n = int(input())
nums = [int(i) for i in input().split()]

m = 10 ** 10
for num1 in range(1, max(nums)+1):
    tmp = 0
    for num2 in nums:
        tmp += (num1 - num2) ** 2
    m = min(m, tmp)
print(m)

Submission status: Accepted

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

y = sorted(x)

cost = 0
for i in x:
    cost += (i-1)*(i-1)
mini = cost
for p in range(y[0], y[-1]+1):
    cost = 0
    for i in x:
        cost += (i-p)*(i-p)
    if cost < mini:
        mini = cost

print(mini)

Submission status: Accepted

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

X.sort()
ans = []
for i in range(X[0], X[-1]+1):
    tmp = 0
    for j in range(N):
        tmp += (abs(X[j]-i))**2
    ans.append(tmp)

print(min(ans))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    n=int(input())
    x=list(map(int,input().split()))
    mans=100**4
    for i in range(1,101):
        ans=0
        for j in x:
            ans+=(j-i)**2
        mans=min(mans,ans)
    print(mans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans=10**9
for p in range(1,101):
  ans=min(ans,sum([(x[i]-p)**2 for i in range(n)]))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
D = []
for p in range(min(X), max(X)+1):
    d = sum([(x-p)**2 for x in X])
    D.append(d)
print(min(D))

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
a=min(X)
b=max(X)
ans=10**9
for i in range(a,b+1):
  d=0
  for j in X:
    d+=(j-i)**2
  ans=min(d,ans)    
print(ans)

Submission status: Accepted

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

List.sort()
ans = []

for i in range(1,100):
  sum=0
  for j in List:
    sum += (j - i) * (j-i)
  ans.append(sum)
  
print(min(ans))

Submission status: Accepted

Solution code:
mod=1000000007
n=int(input())
x=[int(i) for i in input().split()]
ans=mod**2
for i in range(1,101):
    chk=0
    for j in x:
        chk+=(j-i)**2
    ans=min(ans,chk)
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
hp = 0
hp_li = []
for p in range(1,101):
  hp = 0
  for k in range(n):
    hp += (li[k]-p)**2
  hp_li.append(hp)
print(min(hp_li))

Submission status: Accepted

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


min_sigma = 1000000000
for i in range(1,101):
    #print(i)
    sigma = 0
    for j in range(N):
        sigma= sigma + (i-X[j])**2
    if min_sigma>sigma:
        min_sigma=sigma

print(min_sigma)

Submission status: Accepted

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

ans = 1000000000

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

Submission status: Accepted

Solution code:
import numpy as np

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

av=sum(x)/n

a=int(av)

v1=sum([(int)(i-a)*(i-a) for i in x])
v2=sum([(int)(i-a-1)*(i-a-1) for i in x])

print(min(v1,v2))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
x.sort()
score = []
for a in range(min(x),max(x)+1):
    s = 0
    for b in x:
        s += (b-a)**2
    score.append(s)
print (min(score))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
ans = 100 ** 4
for cand in range(1, 101):
    tmp = 0
    for xi in x:
        tmp += (xi - cand) ** 2
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

min_ = float('inf')
for p in range(1, 101):
    s = 0
    for i in range(n):
        s += (X[i]-p)**2
    if s <= min_:
        min_ = s

print(min_)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
sum = 0
ans = 10 ** 9
for i in range(1,101):
    for j in range(N):
        sum += (X[j] - i) ** 2
    if ans > sum:
        ans = sum
    sum = 0

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
power = []
for p in range(1,101):
    power.append(sum([(x-p)**2 for x in X]))
print(min(power))

Submission status: Accepted

Solution code:
input()
x = sorted([int(i) for i in input().split()])
cost = sum([xi**2 for xi in x])
for p in range(x[0], x[-1] + 1):
    c = 0
    for xi in x:
        c += (xi - p)**2
    cost = min(c, cost)
print(cost)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
ans=0
hantei=100000000000
for i in range(100):
  ans=0
  for j in range(n):
    ans+=(x[j]-i)**2
  if hantei>ans:
    hantei=ans
print(hantei)

Submission status: Accepted

Solution code:
N = int(input())
lis = list(map(int,input().split()))
lis.sort()
S = 0
ans = 10**10
for i in range(lis[0],lis[N-1]+1):
    for j in range(N):
        S += (i-lis[j])**2
    if S < ans:
        ans = S
    S = 0
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*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))

N = I()
X = LI()

p = sum(X) // N
ret = INF

for pp in range(p - 1, p + 2):
    ans = 0
    for x in X:
        ans += (x - pp)**2
    ret = min(ret, ans)

print(ret)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
A = range(min(X), max(X)+1, 1)

ans = set()
for p in A:
    HP = 0
    for j in range(N):
        HP += (X[j] - p) ** 2
    ans.add(HP)

print(min(ans))

Submission status: Accepted

Solution code:
import math
n = int(input())
x = list(map(int,input().split()))
p = (round(sum(x)/n))
ans = 0
for i in x:
    ans += abs(i-p)**2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

P = int(sum(X_list) / N)

Ps = [P - 1, P, P + 1]

print(min([sum([(X - P) * (X - P) for X in X_list]) for P in Ps]))

Submission status: Accepted

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

answer = 9e+100

for i in range(max(x)+1):
    _sum = 0
    for _n in x:
        _sum += (_n-i)**2
    answer = min(answer, _sum)
print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
X = tuple(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)

Submission status: Accepted

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

ave = np.mean(lst)
ave = round(ave)
loss = [(l - ave)**2 for l in lst]
print(int(np.sum(loss)))

Submission status: Accepted

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

min_dist = 1 << 32

def evaluate(posi):
    ans = 0
    for i in range(N):
        ans += (X[i]-posi)**2
    return ans

for i in range(1,101):
    tmp = evaluate(i)
    if tmp < min_dist:
        min_dist = tmp

print(min_dist)

Submission status: Accepted

Solution code:
import numpy as np

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

average = np.mean(X)

m1 = int(average)
m2 = m1 + 1

ans1 = np.dot(X - m1, X - m1)
ans2 = np.dot(X - m2, X - m2)

print(min(ans1, ans2))

Submission status: Accepted

Solution code:

n = int(input())
l = list(map(int,input().split()))
l.sort()

ans = 10**15
c = l[-1]+l[0]
c //= 2
for i in range(l[0],l[-1]+1):
    check = 0
    for j in l:
        check += (i-j)**2
    ans = min(check,ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
pe_lis = list(input().split())

result = []
for i in range(1, 101):
  base = 0
  for j in pe_lis:
    base += (int(j)-i)**2
  result.append(base)
  
print(min(result))

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
x2=sorted(x)
bunsi=0
for i in range(n):
    bunsi+=x2[i]
ave=bunsi/n
ave=round(ave)
ans=0
for i in range(n):
    ans+=(x2[i]-ave)**2
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

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

res = 100000000000000000000000000000000

t.sort()
#print(t)
for i in range(t[0], t[-1]+1):
    memo = 0
    for j in t:
        memo += (j-i)**2
    res = min(memo, res)

print(res)

Submission status: Accepted

Solution code:
import math

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

med = 0
for i in a:
    med += i
    
p = math.ceil(med/n)
q = math.floor(med/n)

ans1 = 0
ans2 = 0

for i in a:
    ans1 += (p-i)**2
    ans2 += (q-i)**2
    
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
n=int(input())
#a,b=map(int,input().split())
xl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]


mn=min(xl)
mx=max(xl)
dis=[]
for p in range(mn,mx+1):
    total=0
    for i in range(n):
        total+=(xl[i]-p)**2
    dis.append(total)
print(min(dis))

Submission status: Accepted

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

ans = []
for i in range(max(x)):
  i+=1
  sqrt = 0
  for j in x:
    sqrt += ((i-j)**2)

  ans.append(sqrt)

print(min(ans))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
INF = 1001001001

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n=int(input())
x=[]
x=list(map(int,input().split()))
x.sort()
cost=[]
for i in range(x[0],x[-1]+1):
    aaa=[(xx-i)**2 for xx in x]
    cost.append(sum(aaa))
ans=min(cost)
print(ans)