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

s = round(sum(li)/len(li))

ans = 0
for i in li:
    ans += (i-s)**2
    
print(ans)

Submission status: Accepted

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

for i in range(100):
    L0=0
    for ii in range(N):
        L0+=(i+1-X[ii])**2
    
    if i==0:
        L=L0
    else:
        L=min(L,L0)
print(L)

Submission status: Accepted

Solution code:
n = int(input())
ans = 10 ** 9
lis = list(map(int,input().split()))
for i in range(0,101):
  num = 0
  for nu in lis:
    num += (nu-i) ** 2
  ans = min(ans,num)
print(ans)

Submission status: Accepted

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

ave = sum(x) // n
ans = 10 ** 18
for i in range(ave, ave + 2):
    s = 0
    for y in x:
        s += (y - i) ** 2
    ans = min(ans, s)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

b=int(round(sum(x)/a))

count=0
for i in x:
  count=count+(i-b)*(i-b)
  
print(count)

Submission status: Accepted

Solution code:
def main():
    N = input()
    X = list(map(int,input().split()))
#    print(sum(X),len(X))
    # 全員が0の場合   全員が同じ場合 AGVは変わらない
    # 全員が100の場合 AVGは変わらない
    # 四捨五入の場合
    AVG = int(sum(X)/len(X))    # intにすることによる誤差
    AVG1 = int(sum(X)/len(X)) + 1    # intにすることによる誤差
#    print()
    total = 0
    total1 = 0
    for i in X:
        total += (AVG - i)**2

    for i in X:
        total1 += (AVG1 - i)**2

    if total >= total1:
        print(total1)
    else:
        print(total)

main()

Submission status: Accepted

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

for n in range(1,101):
    s = 0
    for x in X:
            s = s + ((x-n)*(x-n))
    sum.append(s)

print(min(sum))

Submission status: Accepted

Solution code:
N=int(input())
X=[int(s) for s in input().split()]

sum=0
Ans=0
count=0
Xmax=sorted(X)[N-1]
Xmax2=sorted(X)[N-2]

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

print(Ans)

Submission status: Accepted

Solution code:
def get_x(arr):
  pass


def main():
  input()
  X = list(map(int,input().split()))
  ans = 10 ** 8
  for i in range(min(X), max(X)+1):
    nums = [(x-i)**2 for x in X]  
    if sum(nums) < ans:
      ans = sum(nums)
  print(ans)

    
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
x = list(map(int, input().split()))

HPlist = []

for num in range(100):
    tmp = 0
    for pnum in x:
        tmp += (pnum - num) ** 2
    HPlist.append(tmp)

print(min(HPlist))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
a = max(x)
b = min(x)
y = 0
ans = 10000000

for i in range (b,a+1): #住民がいる間で
  y = 0 #初期化
  for j in x: #体力の総和を計算
    y = y + (j-i)**2
  if y < ans:
    ans = y

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

mini = 10**10
for p in range(1, 101):
    used_hp = 0
    for x in X:
        used_hp += (x-p)**2
    mini = min(mini, used_hp)

print(mini)

Submission status: Accepted

Solution code:
n=int(input())

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

maxX=max(x)
minX=min(x)

mindis=0

for i in range(minX,maxX+1):
  dis=0
  for j in x:
    dis+=(j-i)*(j-i)

  if mindis==0 or mindis>dis:
    mindis=dis

print(mindis)

Submission status: Accepted

Solution code:
n = int(input())

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

mean_x = sum(x) / len(x)

cost = 0
for i in range(len(x)):
    cost += (x[i] - round(mean_x)) ** 2
print(cost)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# problem C
N = input()
n = int(N)
X = list(map(int,input().split()))

P = []

for i in range(1,101):
    sa = list(map(lambda x:x-i, X))
    nizyo = list(map(lambda x:x**2, sa))
    summ = sum(nizyo)
    P.append(summ)

print(min(P))

Submission status: Accepted

Solution code:
import sys

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

ret = sys.maxsize

for i in range(min(X) , max(X) + 1):
    pow = 0
    for x in X:
        pow += (x - i) ** 2
    if pow < ret:
        ret = pow

print(ret)

Submission status: Accepted

Solution code:
import sys

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

ret = sys.maxsize

# for i in range(min(X) , max(X)):
for i in range(1, 100):
    pow = 0
    for x in X:
        pow += (x - i) ** 2
    if pow < ret:
        ret = pow

print(ret)

Submission status: Accepted

Solution code:
n = int(input())
x_n = list(map(int, input().split()))
ave = sum(x_n)//n
res = 0
for x_i in x_n:
    res += x_i**2
for p in range(ave - 2, ave + 3):
    point = 0
    for x_i in x_n:
        point += (x_i - p)**2
    res = min(res, point)
print(res)

Submission status: Accepted

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

cost = 1e9
for pos in range(1, 101):
    tmp_cost = 0
    for xi in X:
        tmp_cost += (pos - xi)**2
    if tmp_cost < cost:
        cost = tmp_cost
print(cost)

Submission status: Accepted

Solution code:
n = int(input())
zahyou = list(map(int,input().split()))
loss = 0
ans = 0
minimum = min(zahyou)
maximum = max(zahyou)
for i in range(minimum, maximum+1):
    loss = 0
    for j in zahyou:
        loss += (j-i)**2
        
    if i == minimum:
        ans = loss
    if loss < ans:
        ans = loss
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
cost=0
for i in range(len(X)):
    cost=cost+X[i]**2

for i in range(1,101):
    cost2=0
    for j in range(len(X)):
        cost2=cost2+(X[j]-i)**2
    cost=min(cost,cost2)

print(cost)

Submission status: Accepted

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

k = round(sum(l) / n)
ans = 0
for i in l:
    ans += (k - i) ** 2

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
X = list(map(int, input().split()))
p1 = int(np.mean(X))
S1 = np.sum([(x-p1)**2 for x in X])
p2 = p1 + 1
S2 = np.sum([(x-p2)**2 for x in X])
print(min(S1, S2))

Submission status: Accepted

Solution code:
N=int(input())
X = list(map(int, input().split()))
E = 0
ans = 1000000000000
for P in range(1,101):
    E = 0
    for x in X:
        E += (x-P)**2
    ans = min(ans,E)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ANS = float("inf")

for i in range(0, 101):
    tmp = 0
    for j in X:
        tmp += abs(i - j) ** 2

    if tmp < ANS:
        ANS = tmp

print(ANS)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
p = sum(x) // n
a1 = sum((xi - p)**2 for xi in x)
a2 = sum((xi - -~p)**2 for xi in x)
print(min(a1, a2))

Submission status: Accepted

Solution code:
num = int(input())
member = list(map(int, input().split()))
min_num = min(member)
max_num = max(member)
min_hp = 10000000
for i in range(min_num, max_num + 1):
    hp = 0
    for j in member:
        hp += (j - i) ** 2
    
    if hp < min_hp:
        min_hp = hp
print(min_hp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    a = int(input())
    n = list(map(int, input().split()))
    sum_dists = []
    for i in range(1, 101):
        sum_dists.append(sum([(d - i)**2 for d in n]))

    print(min(sum_dists))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N=int(input())
lst=list(map(int, input().split()))
total_sum=[]
for i in range(min(lst), max(lst)+1):
    total_sum.append(sum([(house-i)**2 for house in lst]))
print(min(total_sum))

Submission status: Accepted

Solution code:
n=int(input())
X=list(map(int,input().split()))
l=[]
for j in range(1,101):
    s=sum([(X[i]-j)**2 for i in range(n) ])
    l.append(s)
print(min(l))

Submission status: Accepted

Solution code:
# 初期入力
N = int(input())
X = list(map(int, input().split()))
X_max =max(X)
X_min = min(X)

tairyoku =[]
# Pで集会を開く
for P in range(X_min,X_max + 1): #住んでいるところで端から端まで確認
    tairyoku.append([(x_j - P)**2 for x_j in X ])
tairyoku_sum = [sum(i) for i in tairyoku ]
# print(tairyoku)
#print(tairyoku_sum)
print(min(tairyoku_sum))

Submission status: Accepted

Solution code:
N = int(input())

X = input().split()
#import pdb; pdb.set_trace()
i = 0
sum = 0

while i < N:
  x = int(X[i])
  sum += x
  i += 1

P = round(sum / N)

dis = 0
i = 0


while i < N:
  z = int(X[i])
  dis += (P - z) ** 2
  i += 1

print(dis)

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
P = round(sum(X)/N)
ans = 0
for i in range(N):
    ans += (X[i]-P)**2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
L, R = min(X), max(X)

ans = 10**1000
for i in range(L, R+1):
    box = 0
    for j in range(N):
        box += (X[j] - i)**2
    if ans > box:
        ans = box

print(ans)

Submission status: Accepted

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

sum=0
for i in range(n):
  sum=sum+x[i]

if (sum/n)%1<=0.5:
  p=int((sum/n))
else:
  p=int((sum/n))+1
  
answer=0
for i in range(n):
  answer=answer+(x[i]-p)**2

print(answer)

Submission status: Accepted

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

p=round(sum(a)/n)
dis=0
for i in range(n):
    dis+=(a[i]-p)**2
print(dis)

Submission status: Accepted

Solution code:
n = int(input())
d = list(map(int,input().split()))
ret = 1145141919
for i in range(101):
  minid = 0
  for x in d: minid += (x-i)**2
  ret = min(ret,minid)
print(ret)

Submission status: Accepted

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

min_ans = 1e9
for i in range(100):
    ans = sum([(i + 1 - j) ** 2 for j in x])
    min_ans = min(ans, min_ans)

print(min_ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    X = list(map(int, input().split()))
    r = min(sum((x - p) ** 2 for x in X) for p in range(1, 101))
    print(r)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
if sum(X)//N <= sum(X)/N <= sum(X)//N+0.5:
  A = sum(X)//N
else:
  A = sum(X)//N+1
B = []
for i in range(N):
  B.append((X[i]-A)**2)
print(sum(B))

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
x=list(map(int,input().split()))
m=int(round(np.mean(x),0))
x_mean=[(y-m)**2 for y in x]
print(sum(x_mean))

Submission status: Accepted

Solution code:
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
n = int(input())
x = list(map(int, input().split()))
# 体力総和最小値となる座標Pを求める
p = Decimal(str(sum(x)/n)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
# 座標Pの時の体力の総和を求める
ans = 0
for i in range(n):
    ans += (x[i - 1] - p) ** 2
print(ans)

Submission status: Accepted

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

# 体力総和最小値となる座標Pを求める
ave = int(sum(x) / n * 10)
round = ave / 10 - int(ave / 10)
if round - int(round) < 0.5:
    p = int(ave / 10)
else:
    p = int(ave / 10) + 1

# 座標Pの時の体力の総和を求める
ans = 0
for i in range(n):
    ans += (x[i - 1] - p) ** 2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())
xi = list(map(int, input().split()))
def f(xi, i):
    e = 0
    for x in xi:
        e += abs(x - i) ** 2
    return e
minxi = min(xi)
mine = f(xi, minxi)
for i in range(minxi + 1, max(xi) + 1):
    e = f(xi, i)
    if mine > e : mine = e
    else: break
print(mine)

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())

m = int(sum(A)/N+0.5)
cost = sum([(a-m)**2 for a in A])
print(cost)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().split()))
min_num = min(lst)
max_num = max(lst)
cost = float('inf')
for i in range(min_num, max_num + 1):
    tmp = 0
    for x in lst:
        tmp += (i - x) ** 2
    if tmp < cost:
        cost = tmp

print(cost)

Submission status: Accepted

Solution code:
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+= (i - x)**2
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

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

A = []

for i in range(1,101,1):
  a = 0
  for j in range(N):
    a += (i-X[j])**2
  A.append(a)

print(min(A))

Submission status: Accepted

Solution code:
N = int(input())
x = tuple(map(int, input().split()))
mid = (max(x) + min(x)) // 2
curr_sum = 0
dp = [10**9] * 101
for i in range(1, 101):
  dp[i] = 0
  for num in x:
    dp[i] += (num - i) ** 2
print(min(dp))

Submission status: Accepted

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

ans = 100*100*100

for P in range(100):
    power = 0
    for i in range(N):
        power += (X[i] - P)**2
    ans = min(ans, power)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(min)

Submission status: Accepted

Solution code:
N = int(input())
li = list(map(int,input().split()))	
Sum = 0
for i in range(len(li)):
    Sum += li[i]
ave = int((Sum / len(li)) + 0.5)

S = 0
for i in range(len(li)):
    S += (li[i] - ave) ** 2
print(S)

Submission status: Accepted

Solution code:
n = int(input())
*l, = map(int,input().split())
suml = sum(l)
suml2 = sum([i**2 for i in l])
ave1 = suml//n 
ave2 = -(-suml//n)
ans1 = suml2 - 2*suml*ave1 + n*ave1*ave1
ans2 = suml2 - 2*suml*ave2 + n*ave2*ave2
print(min([ans1,ans2]))

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
x=[]
maxx=max(X)
sum=0
for p in range(maxx+10):
  for j in X:
    sum+=(j-p)**2
  x.append(sum)
  sum=0
ans=min(x)
print(ans)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input())
    x = list(map(int, input().split()))
    p1 = int(sum(x)/n)
    p2 = p1 + 1

    ans1 = [(x_-p1)**2 for x_ in x]
    ans2 = [(x_-p2)**2 for x_ in x]

    print(min(sum(ans1), sum(ans2)))
    


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
1 4"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7
14 14 2 13 56 2 37"""
        output = """2354"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

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

def min_energy(N,X):
    min_e=100000000
    for l in range(max(X)+1):
        e=0
        for n in range(N):
            e+=(X[n]-l)**2
        if min_e>=e:
            min_e=e
    return min_e

print(min_energy(N,X))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, X: "List[int]"):
    ans = INF
    for i in range(1, 101):
        cost = sum([(i-X[j])**2 for j in range(N)])
        ans = min(ans, cost)

    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))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
Xlist = list(map(int, input().split()))
ans = 10**9
for p in range(min(Xlist), max(Xlist)+1):
    cost = 0
    for x in Xlist:
        cost += (x - p)**2
    ans = min(ans, cost)
print(ans)

Submission status: Accepted

Solution code:
a=int(input())
x=input().split()
x=list(map(int,x))
x=sorted(x)
l=[]
for i in range(x[0]-1,x[-1]+1):
    d = 0
    for j in x:
        c=(j-i)**2
        d=d+c
    l.append(d)
print(sorted(l)[0])

Submission status: Accepted

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

m = 10 ** 6
for p in range(1,100):
    s = 0
    for i in range(N):
        s += (p-X[i])**2
    m = min(m,s)

print(m)

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
X=np.array(list(map(int,input().split())))
ans=sum(X**2)
for i in range(min(X)-1,max(X)+1):
    Z=sum(X**2)-sum(2*X*i)+N*i**2
    ans=min(Z,ans)
print(ans)

Submission status: Accepted

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

mina, maxa = X[0], X[N-1]

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

Submission status: Accepted

Solution code:
n = int(input())
x_li = list(map(int, input().split()))
x_li.sort()
hp_min = -1

for i in range(x_li[0], x_li[n-1] + 1):
    hp = sum((x - i)**2 for x in x_li)
    if hp < hp_min or hp_min == -1:
        hp_min = hp

print(hp_min)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

l = min(xs)
r = max(xs)

costs = []
for i in range(l-1, r+1):
    cost = 0
    for j in xs:
        cost += (j - i) * (j - i)
    costs.append(cost)

print(min(costs))

Submission status: Accepted

Solution code:
n = int(input())

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

l = min(xs)
r = max(xs)

costs = []
for i in range(1, 100):
    cost = 0
    for j in xs:
        cost += (j - i) * (j - i)
    costs.append(cost)

print(min(costs))

Submission status: Accepted

Solution code:
input()
xs = list(map(int,input().split()))
x_min = min(xs)
x_max = max(xs)
diss = []
for p in range(x_min,x_max+1):
    diss.append(sum([(p-x)**2 for x in xs]))
print(min(diss))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = float('inf')
for i in range(1, 101):
    cnt = 0
    for j in range(n):
        cnt += abs(a[j] - i)**2
    ans = min(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
import math
n = int(input())
x = list(map(int, input().split()))
p = 0
ans = 0

s = sum(x)/n
a = math.floor(s)
b = math.ceil(s)

if (a-s)**2 > (b-s)**2:
    p = b
else:
    p = a

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

print(ans)

Submission status: Accepted

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

result = 10**6

for p in range(min(add),max(add)+1):
    sum = 0
    for i in range(n):
            sum += (p - add[i])**2
    if sum <= result:
        result = sum

print(result)

Submission status: Accepted

Solution code:
N = int(input())
K = sorted(map(int, input().split()))

for i in range(1,101):
  data1 = map(lambda x: (i-x)**2, K)
  sum_dis = sum(list(data1))
  if i == 1:
    min_min = sum_dis
  if min_min > sum_dis:
    min_min = sum_dis
print(min_min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
ans = float("inf")
for p in range(1, max(X)+1):
    x_sum=0
    for x in X:
        x_sum+=(x-p)**2
    ans = min(ans, x_sum)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

P = round(sum(X) / N)

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

print(ans)

Submission status: Accepted

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

def f(i,X):
  sumf=0
  for j in X:
    sumf+=(j-i)**2
  return sumf

for i in range(min(X),max(X)+1):
  sum=min(sum,f(i,X))

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,*X=map(int,open(0).read().split());print(sum(map(lambda x:(round(sum(X)/N)-x)**2,X)))

Submission status: Accepted

Solution code:
N,*X=map(int,open(0).read().split());print(int(sum(map(lambda x:(round(sum(X)/N,0)-x)**2,X))))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
s = 0
for i in range(n):
    s += x[i]
g = int(s/n + 0.5)
ans = 0
for i in range(n):
    ans += (g-x[i])**2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
coordinate = list(map(int, input().split()))
result = 0
resultl = 0
 
for j in range(N):
    result += (1-coordinate[j])**2
    
for i in range(1,101):
    for k in range(N):
        resultl += (i-coordinate[k])**2
 
    if resultl < result:
        result = resultl
    resultl = 0
    
print(result)

Submission status: Accepted

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

chk = []
hp = 0
#i->集会の座標, j->体力
for i in range(min(x),max(x)+1):
    for j in range(len(x)):
        hp +=(x[j]-i)**2
    chk.append(hp)
    hp = 0
print(min(chk))

Submission status: Accepted

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

p = int(round(sum(X) / N) )

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
P=round(sum(X)/N)
#四捨五入
print(sum((x-P)**2 for x in X))
#listに入っているものを一つずつ取り出して、合計する

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
ans=float('inf')
p=0
for i in range(1,100):
    for k in range(N):
        p+=((X[k]-i)**2)
    ans=min(ans,p)
    p=0
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
X = [int(_) for _ in stdin.readline().rstrip().split()]
ans = float('inf')
for i in range(1, 100):
    a = 0
    for x in X:
        a += (x-i)*(x-i)
    ans = min(ans, a)
print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8

n = int(input())
xl = input().split()

listx = []
for i in xl:
  yy = int(i)
  listx.append(yy)
  
def hp(a,b):
  goh = 0
  for i in a:
    hp = (i - b)**2
    goh += hp
    
  return goh

xmax = max(listx)
xmin = min(listx)
listhp = []
for p in range(xmin,xmax + 1):
  hq = hp(listx,p)
  listhp.append(hq)
  
ans = min(listhp)
print("{}".format(ans))

Submission status: Accepted

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

ans = float('inf')

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Xi = list(map(int,input().split()))
tairyoku = 10000000
for p in range(1,100+1,1):
  tmp = 0
  for x in Xi:tmp = tmp + (p-x)*(p-x)
  if tmp < tairyoku:
    tairyoku = tmp
print(tairyoku)

Submission status: Accepted

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

p = round(sum(x) / n)

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

print(cost)

Submission status: Accepted

Solution code:
n=input()
l=list(map(int,input().split()))
ans=99999999
for a in range(100):
    s=0
    for b in l:
       s+=(b-a)**2
    if ans>s:
        ans=s
print(ans)

Submission status: Accepted

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

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 x in X:
        tmp += (x-i)**2
    ans = min(ans,tmp)
print(ans)

Submission status: Accepted

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

def calc_cost(p):
    cost = 0
    for i in range(N):
        cost += (x_list[i] - p)**2
    return cost

ans = 9999999999
for x in range(101):
    ans = min(ans, calc_cost(x))
print(ans)

Submission status: Accepted

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

sum = 0
numList = []
p = 0
for pi in range(100):
    for xi in range(len(x)):
        sum += (x[xi] - pi ) ** 2
    numList.append(sum)
    sum = 0
print(min(numList))

Submission status: Accepted

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

Submission status: Accepted

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

ans = []
P = 100
while P > 0:
    a = 0
    for x in X:
        a += (x - P) ** 2
    ans.append(a)
    P -= 1
print(min(ans))

Submission status: Accepted

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

# X = sorted(X)
# X_undupe = list(set(X))
stamina = []
for i in range(1, 100):
    s = 0
    for ii in X:
        s = s + ((ii - i) ** 2)
    stamina.append(s)

print(min(stamina))

Submission status: Accepted

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

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

print(min_ans)

Submission status: Accepted

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

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

for i in x:
    i -= p
    i *= i
    count += i
    

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = tuple(sorted(map(int, input().split())))
print(min(sum((x - p)**2 for x in X) for p in range(X[0], X[-1]+1)))

Submission status: Accepted

Solution code:
N = int(input())
List_X = list(map(int, input().split()))
min = 9999999
for i in range(1, 101):
    sum = 0
    for j in range(N):
        sum += (List_X[j] - i) ** 2
    if sum < min:
        min = sum
print(min)

Submission status: Accepted

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

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

print(minV)

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int, input().split()))
res = 1e9
j = 1
while j <= 100:
    r = 0
    for i in li:
        r += (i - j)**2
    res = min(res, r)
    j += 1
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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


ans = 100*100*100
for i in range(101):
    sum = 0
    for x in xl:
        sum += (i-x)*(i-x)
    ans = min(ans, sum)

print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
x = na()
minx = min(x)
maxx = max(x)
ans = 10 ** 9 + 7
for i in range(minx, maxx+1):
    tmp = 0
    for j in range(n):
        tmp += (i-x[j])**2
    ans = min(tmp, ans)
print(ans)

Submission status: Accepted

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

# print(N)
# print(X)

minX, maxX = min(X), max(X)
min_cost = 1e10

for p in range(minX, maxX + 1):
    cost = sum([(x - p) ** 2 for x in X])
    min_cost = min(min_cost, cost)

print(min_cost)