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())
line = list(map(int, input().split()))
min_dist = 10**9
for i in range(max(line)+1):
  sum_dist = 0
  for j in range(n):
    sum_dist += (line[j] - i)**2
  if sum_dist < min_dist:
    min_dist = sum_dist
print(min_dist)

Submission status: Accepted

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

costs = [0] * 100
for x in X:
    for i in range(100):
        costs[i] += (x - (i + 1)) * (x - (i + 1))
print(min(costs))

Submission status: Accepted

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

power_min = 1e8
for P in range(1,101):
    power = 0
    for i in range(N):
        power += (X[i]-P)**2
    if power < power_min:
        power_min = power

print(power_min)

Submission status: Accepted

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

ans=10**9
for p in range(-200, 200):
  ref=0
  for x in X:
    ref+=(x-p)**2
  #print(ref)
  ans=min(ans, ref)
  
print(ans)

Submission status: Accepted

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


avg = sum(X) / N
avgi = int(avg + 0.5)

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
k = []
def kyori(p):
  m = 0
  for i in range(n):
    m += (p-x[i])**2
  return m
for i in range(1,101):
  k.append(kyori(i))

print(min(k))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
N_List = list(map(int,input().split()))
ans = (100**2)*100
for i in range(1,101):
    ca = sum(map(lambda x:(x-i)**2,N_List))
    if ca < ans:
        ans = ca

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
res=10**10
for i in range(1,101):
  sum = 0
  for j in range(n):
    sum+=(x[j]-i)**2
  if sum < res:
    res=sum
print(res)

Submission status: Accepted

Solution code:
import math

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

min_hp = math.inf

for i in range(1, 101):
	hp = sum(map(lambda x: (x - i) ** 2, address))
	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=round(sum(X)/N)
Y=[]
for i in X:
    Y.append((i-a)**2)
print(sum(Y))

Submission status: Accepted

Solution code:
a=int(input())
b=list(map(int,input().split()))
c=int(sum(b)/len(b)+0.5)
total=0
for i in range(a):
    total+=(b[i]-c)**2
print(total)

Submission status: Accepted

Solution code:
import statistics

n=int(input())
x=list(map(int,input().split()))
p1 = int(statistics.mean(x))
p2=p1+1
s1=0
s2=0
for i in range(n):
    s1+=(x[i]-p1)**2
    s2+=(x[i]-p2)**2
print(min(s1,s2))

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
x_list = list(map(lambda x: int(x), input().split(" ")))
M = np.sum(x_list)
L = np.sum(list(map(lambda x: int(x)**2, x_list)))

if M % N == 0:
    print(int(L - M**2 / N))
else:
    rest = M % N
    if rest <= N / 2:
        print(int(rest**2 / N - M**2 / N + L))
    else:
        print(int(N * (1 - rest / N)**2 - M**2 / N + L))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
a = int(sum(X) / N)
b = a + 1
A, B = 0, 0
for x in X:
    A += (x - a) ** 2
    B += (x - b) ** 2
ans = min(A, B)
print(ans)

Submission status: Accepted

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

ans = 10 ** 19
for i in range(101):
  ans = min(ans, sum((x - i) ** 2 for x in X))
  
print(ans)

Submission status: Accepted

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

print(str(ans))

Submission status: Accepted

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

min_n = min(lst)
max_n = max(lst)
min_count = 1000000000
for i in range(min_n, max_n + 1):
  count = 0
  for j in range(n):
    count += (lst[j] - i) ** 2
  if count < min_count:
    min_count = count
print(min_count)

Submission status: Accepted

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

X.sort()

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

print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
ans = float('inf')
for i in range(1,101):
    diff = 0
    for j in range(n):
        diff += pow(A[j]-i,2)
    ans = min(ans,diff)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
X = sorted(X)
avg = sum(X)//N
aa = []
for i in range(2):
  avg = avg + i
  a = 0
  for j in range(N):
    a += (X[j] - avg)**2
  aa.append(a)
print(min(aa))

Submission status: Accepted

Solution code:
N, *X = map(int, open(0).read().split())
ans = float("inf")
for x in range(min(X), max(X) + 1):
    cur = 0
    for j in range(N):
        cur += (X[j] - x) ** 2
    ans = min(ans, cur)
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+=(i-x[j])*(i-x[j])
  ans=min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
ans = 10**9
for k in range(min(X),max(X)+1):
    temp = 0
    for e in X:
        temp += (k-e)**2
    ans = min(temp,ans)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
cmin = 10**6+10
for i in range(101):
    cnt = 0
    for j in range(N):
        cnt += (i-X[j])**2
    cmin = min(cmin,cnt)
print(cmin)

Submission status: Accepted

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

Submission status: Accepted

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

print(sum([abs(i-y)**2 for i in x]))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())    
xl = list(map(int, input().split()))   
ans = 10**10 
for i in range(1,101):
    v = 0
    for x in xl:
        v += (x-i)**2
    ans = min(ans,v)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
num = 10**10
for p in range(100):
    cnt = 0
    for i in range(n):
        cnt += (x[i] - p)**2
    num = min(num, cnt)
print(num)

Submission status: Accepted

Solution code:
n, *x = map(int, open(0).read().split())
print(min([sum([(a - i) ** 2 for a in x]) for i in range(1, 101)]))

Submission status: Accepted

Solution code:
N = int(input())

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

ans = 10000000000000000

for i in range(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 = list(map(int,input().split()))
cmin = 10**6
for i in range(1,101):
    cnt = 0
    for j in range(N):
        cnt += (i-X[j])**2
    cmin = min(cmin,cnt)
print(cmin)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
ans = float("inf")
for loc in range(-100,101):
  temp = 0
  for x in X:
    temp += (loc-x)**2
  ans = min(temp,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#C-rally
N = int(input())
A = list(map(int, input().split()))
ans_min = 10**8
 
for i in range(min(A), max(A)+1):
    ans = 0
    for j in range(N):
        ans += (A[j] - i) ** 2
    
    if ans < ans_min:
        ans_min = ans
 
print(ans_min)

Submission status: Accepted

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

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

m = sum(X) // N
print(min(cost(m), cost(m+1)))

Submission status: Accepted

Solution code:
import math
import statistics
from decimal import Decimal, ROUND_HALF_UP
a = int(input())
b = list(map(int, input().split()))
c = statistics.mean(b)
d = Decimal(c).quantize(Decimal('1'), ROUND_HALF_UP)
ans = 0
for i in range(a):
  ans += (d - b[i])**2
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
lis=list(map(int,input().split()))
       
f_ans=100000000000000
for i in range(min(lis),max(lis)+1):
  ans=0
  for l in lis:
    ans+=(i-l)**2
  f_ans=min(ans,f_ans)
    
print(f_ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 10**18
ans_ = 0

for P in range(1, max(X) + 1):
    ans_ = 0
    for x in X:
        ans_ += (x - P) ** 2
    ans = min(ans, ans_)

print(ans)

Submission status: Accepted

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

for i in range(x[0],x[-1]+1):
  for j in x:
    count+=(j-i)**2
    
  ans.append(count)
  count=0
  
print(min(ans))

Submission status: Accepted

Solution code:
import statistics

N = int(input())
X = list(map(int,input().split()))
P = round( statistics.mean(X) )

ans = sum([(i-P)**2 for i in X])
print(ans)

Submission status: Accepted

Solution code:
"""Boot-camp-for-Beginners_002_C_Rally_19-August-2020.py"""
import numpy as np
import sys

N=int(input())
X = list(map(int,input().split()))
s=0
for i in range(len(X)):
    s+=X[i]
P=int(s/N)

Sum_round_down=0
Sum_round_up=0
for i in range(len(X)):
    Sum_round_down+=(P-X[i])**2
    Sum_round_up+=(P+1-X[i])**2
if(Sum_round_down>=Sum_round_up):
    Sum=Sum_round_up
else:
    Sum=Sum=Sum_round_down
print(int(Sum))

Submission status: Accepted

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

health = 10**9
p_min = min(x)
p_max = max(x)
for p in range(p_min,p_max+1):
  tmp = 0
  for i in range(n):
    tmp += (x[i]-p)**2
    
  health = min(health, tmp)
print(health)

Submission status: Accepted

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

ave = sum(X) / float(N)
my_round_int = lambda x: int((x * 2 + 1) // 2)
t = my_round_int(ave)
val = 0
for x in X:
  val += (t - x)**2
print(val)

Submission status: Accepted

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

for p in range(min(x),max(x)+1):
    hp = []
    for i in x:
        hp.append((i - p)**2)
    if hp_total > sum(hp):
        hp_total = sum(hp)
        
print(hp_total)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
m = 10**9
for i in range(min(x),max(x)+1):
    t = 0
    for h in x:
        t += (h-i)**2
    if t < m:
        m = t
print(m)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

minimum = math.inf
for i in range(101):
    stamina = 0
    for j in range(N):
        stamina += (x[j]-i)**2
    minimum = min(minimum,stamina)

print(minimum)

Submission status: Accepted

Solution code:
import math
n = int(input())
arr = list(map(int, input().split()))
ans = float('inf')
for i in range(1, 100):
    temp = 0
    for j in arr:
        temp += (j-i)**2
    ans = min(ans, temp)
print(ans)

Submission status: Accepted

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

av = sum(l)/n
af = math.floor(av)
ac = math.ceil(av)

sf = 0
sc = 0

for i in l:
    sf += (abs(i-af))**2
    sc += (abs(i-ac))**2

print(min(sf,sc))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
sum_min = 10**8

for i in range(min(X), max(X)+1):
    s = 0
    for j in range(N):
        s += (X[j] - i)**2
    
    if s < sum_min:
        sum_min = s

print(sum_min)

Submission status: Accepted

Solution code:
n=int(input())
x=[int(i)for i in input().split()]
p=[sum([(j-i)**2 for j in x]) for i in range(101)]
print(min(p))

Submission status: Accepted

Solution code:
n=int(input())
x=[int(i)for i in input().split()]
p=[0 for i in range(101)]
for i in range(101):
    p[i]=sum([(j-i)**2 for j in x])
print(min(p))

Submission status: Accepted

Solution code:
import sys
import math
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
x = sum(a) // n
ans = 0
for i in a:
    ans += (i - x) * (i - x)
x = math.ceil(sum(a) / n)
ans2 = 0
for i in a:
    ans2 += (i - x) * (i - x)
print(min(ans, ans2))

Submission status: Accepted

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

cnt = 0
mini = float('inf')

P = max(X) + 1

for i in range(P):
    for j in range(len(X)):
        cnt += (X[j] - i)**2
    if cnt < mini:
        mini = cnt
    cnt = 0

print(mini)

Submission status: Accepted

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

costs = []
for p in range(100):
  costs.append(sum(map(lambda x: (x - p)**2, X)))

print(min(costs))

Submission status: Accepted

Solution code:
N = int(input())
cc = list(map(int,input().split()))
min_sum = float('inf')
for i in range(1,101):
  count = 0
  for j in cc:
    count += (i-j)**2
  min_sum = min(min_sum,count)
print(min_sum)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
avex=sum(x)//n
ansl=0
ansr=0
for i in x:
  ansl+=(avex-i)**2
  ansr+=(avex+1-i)**2

  
print(min(ansl,ansr))

Submission status: Accepted

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

sum = 0
for i in points:
  sum += i

mean = sum/len(points)
if mean%2 != 0:
    mean = int(round(mean,0))

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

print(ans)

Submission status: Accepted

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

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

mix_x = min(x)
max_x = max(x)

ans = 10000000000000
for i in range(mix_x, max_x+1):
    power = 0
    for j in range(n):
        power += (x[j] - i)**2
    ans = min(ans, power)
print(ans)

Submission status: Accepted

Solution code:
def resolve():
  N = int(input())
  X = [int(x) for x in input().split(" ")]
  min_X = min(X)
  max_X = max(X)
  # sigma(Xi-P) = X**2 - 2*Xi*P + P**2
  sum_of_x = sum(X)

  sum_of_squared = 0
  for x in X:
    sum_of_squared += x**2

  temp_sum_of_cost = sum_of_squared - 2 * min_X * sum_of_x + N * min_X**2
  for p in range(min_X, max_X+1):
    sum_of_cost = sum_of_squared - 2 * p * sum_of_x + N * p**2
    if sum_of_cost < temp_sum_of_cost:
      temp_sum_of_cost = sum_of_cost

  print(temp_sum_of_cost)

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
import math

# inpult
# 人数　n
n = input();
# i番目の人が住んでいる座標x
x_list = list(map(int, input().split()));

#座標Pを求める（座標の合計の平均を算出）
sum_p = 0;
for i in x_list:
    sum_p = sum_p + i;

# 平均を算出する関数roundを作成
round_ave = lambda x:(x*2+1)//2;

p = round_ave(sum_p/len(x_list));

# 各要素からpを引いて2乗した数の和を算出する
result = 0;
for i in x_list:
    result = result + (i - p)**2

# 小数点以下を削除して表示
print(math.floor(result))

Submission status: Accepted

Solution code:
number = int(input())
score = list(map(int,input().split()))
kiroku = 10**10
for i in range(100):
    answer = 0
    for j in range(number):
        answer += (score[j] - i-1)**2
    if answer < kiroku:
        kiroku = answer
print(kiroku)

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
x1=list(map(int,input().split()))
ans=1000000000000000000000
for i in np.arange(1,101):
    hp=0
    for j in x1:
        hp+=(j-i)*(j-i)
    if hp<=ans:
        ans=hp
print(ans)

Submission status: Accepted

Solution code:
def mapt(fn, *args):
    return tuple(map(fn, *args))

def main():
    n = int(input())
    x = mapt(int, input().split(" "))
    ans = float("inf")
    for p in range(1, 101):
        r = 0
        for xj in x:
            r += (xj-(p))**2
        ans = min(ans, r)
    print(ans)

main()

Submission status: Accepted

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

heikin=(sum(x)/n)

if abs(int(heikin)-heikin)<abs(int(heikin+1)-heikin):
    kaisai=int(heikin)
else:
    kaisai=int(heikin+1)

ans=0

for i in x:
    ans+=(i-kaisai)**2

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
X = list(map(int, input().split()))

min_x = X[0]
max_x = X[0]
for i in range(N):
  if X[i] > max_x: max_x = X[i]
  if X[i] < min_x: min_x = X[i]

ans = 10000000
for p in range(min_x, max_x+1):
  ans_p = 0
  for x in X:
    ans_p += (x-p)**2
  if ans > ans_p: ans = ans_p

print(ans)

Submission status: Accepted

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

min_=min(x)
max_=max(x)
ans=list()
for xy in range(min_, max_+1):
  life=0
  for xx in x:
    life+=(xx-xy)**2
  ans.append(life)
print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def nearest_int(f):
  if f - int(f) < 0.5:
    return int(f)
  else:
    return int(f) + 1

N = int(input())
X = list(map(lambda x: int(x), input().split(" ")))
ave = sum(X) / N
avei = nearest_int(ave)

print(sum([(x - avei) ** 2 for x in X]))

Submission status: Accepted

Solution code:
import math
a = int(input())
answer = 100000000
b = list(map(int,input().split()))
for i in range(1,101):
    cost = 0
    for j in b:
        cost+=(j-i)**2
    answer = min(answer,cost)
print(answer)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 10**6

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

print(ans)

Submission status: Accepted

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

X_g = sum(X)/N

if X_g%1<0.5:
    P = int(X_g)
else:
    P = int(X_g)+1
ans = 0
for i in range(N):
    ans += (X[i]-P)**2

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
ans = 1<<60
for center in range(101):
    a = 0
    for x in X:
        a += (x - center) ** 2
    if a < ans:
        ans = a
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    X = list(map(int, input().split()))
    av = sum(X)/N
    def _round(x, d=0):
        import math
        p = 10 ** d
        return math.floor(x*p)/p if (x*p)%1 < 0.5 else math.ceil(x*p)/p
    P = round(av)
    ans = 0
    for x in X:
        ans += (x-P)**2
    print(ans)

if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

ans = []
for p in range(100+1):
    phys = 0
    for x in X:
        phys += (x-p)**2
    ans.append(phys)

print(min(ans))

Submission status: Accepted

Solution code:
import sys

def main():

    N = int(sys.stdin.readline().rstrip())
    X = [int(x) for x in sys.stdin.readline().rstrip().split()]

    m = 100**2 * 100
    for p in range(101):
        tmp = 0
        for x in X:
            tmp += (x - p)**2
        m = min(tmp,m)

    print(m)


main()

Submission status: Accepted

Solution code:
n = input()
s = list(map(int,input().split()))
m = 10000000
for p in range(0,101):
  t = 0
  for x in s:
    t+=(x-p)**2
  m = min(t,m)
print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
ans = 10 ** 8
for p in range(x[0],x[-1]+1):
    m = 0
    z = 0
    for i in range(n):
        z = x[i] - p
        m += (z ** 2)
    ans = min(ans,m)
print(ans)

Submission status: Accepted

Solution code:
import math
N=int(input())
C=list(map(int,input().split()))
ave = sum(C) / len(C)
X=math.floor(ave)
Y=X+1
Xsum,Ysum=0,0
for i in range(len(C)):
  Xsum += (C[i]-X)**2
  Ysum += (C[i]-Y)**2
print(min([Xsum,Ysum]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l = [int(x) for x in input().split()]
p = int(sum(l)/n + 0.5)
ans = 0
for i in range(n):
    ans += (p-l[i])**2
    
print(ans)

Submission status: Accepted

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

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

print(min(total_list))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

N = next(sys.stdin.buffer)
X = tuple(map(int, next(sys.stdin.buffer).split()))

min_x = min(X)
max_x = max(X)

stamina = min(sum((p - x) ** 2 for x in X) for p in range(min_x, max_x + 1))

print(stamina)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
ans = 50 ** 2 * 100
for P in range(1,101):
    sum = 0
    for i in range(N):
        sum += (X[i] - P) ** 2
    if sum < ans:
        ans = sum
print(ans)

Submission status: Accepted

Solution code:
import math
n = int(input())
x = list(map(int,input().split(" ")))
a=math.ceil(sum(x)/n)
s = sum((xx - a)**2 for xx in x)
tmp = s
a = a-1
s = sum((xx - a)**2 for xx in x)
if s > tmp:
    print(tmp)
else:
    print(s)

Submission status: Accepted

Solution code:
N=int(input())
X=sorted(list(map(int, input().split())))
 
ans =100000000000
tmp=0
cnt=0
 
for i in range(X[0],X[-1]+1):
    for j in range(len(X)):
        tmp += (X[j]-i)**2
    if ans > tmp:
        ans =tmp
    tmp=0
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
ans=1000000000000
for p in range(100):
    a=0
    for i in range(n):
        a+=(x[i]-p)**2 
    if a < ans:
        ans = a

print(ans)

Submission status: Accepted

Solution code:
from numpy import average
from decimal import Decimal, ROUND_HALF_UP
 
n=int(input())
x=list(map(int,input().split()))
 
p=Decimal(str(average(x))).quantize(Decimal('1'),rounding=ROUND_HALF_UP)
 
ans=0
for i in x:
	ans+=((i-p)**2)

print(ans)

Submission status: Accepted

Solution code:
from numpy import average
from decimal import Decimal, ROUND_HALF_UP

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

p=Decimal(str(average(x))).quantize(Decimal('0'),rounding=ROUND_HALF_UP)

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
loc = round(sum(a) / N)
print(sum(map(lambda x: (x - loc) ** 2,a)))

Submission status: Accepted

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

Submission status: Accepted

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

for p in range(1,101):
  A+=[sum((x-p)**2 for x in X)]

print(min(A))

Submission status: Accepted

Solution code:
def getDis(X,p):
    res = 0
    for x in X:
        res += (x-p)**2
    return res

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

p = sum(X)//n

for i in range(n):
    d = getDis(X,p)
    if d>getDis(X,p+1):
        p+=1
    elif d>getDis(X,p-1):
        p-=1
    else:
        break

print(d)

Submission status: Accepted

Solution code:
N = int(input())
X = tuple(map(int, input().split()))
ans = 10 ** 7
for p in range(min(X), max(X) + 1):
    total = 0
    for x in X:
        total += (x - p) ** 2
    ans = min(ans, total)
print(ans)

Submission status: Accepted

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

print(min(al))

Submission status: Accepted

Solution code:
def rally(arr):
	p = max(arr)
	summ = 0
	best = float('inf')
	for i in range(1, p+1):
		summ = 0
		for j in arr:
			summ += (j - i) ** 2
		best = min(best, summ)
	return best
n = int(input())
arr = list(map(int, input().split()))
print(rally(arr))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
ans = []
for i in range(min(X),max(X)+1):
    cnt = 0
    for j in X:
        cnt += (j-i)**2
    ans.append(cnt)#少なくとも1回は追加させるためこの位置にかく
        
print(min(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    X = [int(i) for i in input().split()]
    from decimal import Decimal, ROUND_HALF_UP
    target = int(Decimal(sum(X)/float(N)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
    ans = 0
    for x in X:
        ans += (x-target)**2
    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a = sorted(a)
k = 10**6

for i in range(a[0],a[-1]+1):
  total = 0
  for s in a:
    total +=(i-s)**2
  #print(total)
  k = min(k,total)
print(k)

Submission status: Accepted

Solution code:
n = int(input())
x_list = list(map(int, input().split()))
m = int(sum(x_list)/n + 0.5)
print(sum((x - m)**2 for x in x_list))

Submission status: Accepted

Solution code:
N = int(input())
X = [int(x) for x in list(input().split())]
max_x = max(X)
min_x = min(X)
d = max_x - min_x
middle = (d//2)
P = middle + min_x
ans = 0
for i in range(N):
  ans += (max_x-X[i])**2
for i in range(d):
  n_ans = 0
  P = min_x + i
  for j in range(N):
    n_ans += (P-X[j])**2
  if (n_ans < ans):
    ans = n_ans
print(int(ans))