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())
X = [int(i) for i in input().split()]

x_max = max(X)
x_min = min(X)
x_mid = (x_max + x_min)//2

def get_dist(X, a):
    ans = 0
    for xi in X:
        ans += (xi - a)**2
    return ans


direction = 1 #1 => right, -1 => left

x = x_mid
dist1 = get_dist(X, x)
dist2 = get_dist(X, x + 1)

if dist1 > dist2:
    direction = 1
else:
    direction = -1


ans = 0
while True:
    dist2 = get_dist(X, x + direction)

    if dist1 <= dist2:
        ans = dist1
        break

    dist1 = dist2
    x = x + direction
print(ans)

Submission status: Accepted

Solution code:
def A():
    N, R = map(int, input().split())
    if N >= 10:
        print(R)
    else:
        print(R + 100*(10-N))

def B():
    N, K = map(int, input().split())
    n = N
    ans = 1
    while n >= K:
        q, r = divmod(n, K)
        ans += 1
        n = q
    print(ans)

import math
def C():
    N = int(input())
    X = [int(i) for i in input().split()]
    X.sort()
    l = 1
    r = 100
    ans = float('-inf')
    while l<r:
        #print(l, r)
        temp_l = 0
        temp_r = 0
        for i in X:
            temp_l += (i-l)**2
            temp_r += (i-r)**2
        ans = min(temp_l, temp_r)
        if temp_l < temp_r:
            r = int(math.floor((l+r)/2.0))
        else:
            l = int(math.ceil((l+r)/2.0))
    
    print(ans)
C()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    x = list(map(int, input().split()))
    result = 0
    for x_i in x:
        result += (x_i - 1) ** 2
    for i in range(2, 100):
        tmp_result = 0
        for x_i in x:
            tmp_result += (x_i - i) ** 2
        result = min(result, tmp_result)
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

sowa=0
ans=[]
for p in range(1,101):
    for x in X:
        tmp=(x-p)**2
        sowa+=tmp
    ans.append(sowa)
    sowa=0
print(min(ans))

Submission status: Accepted

Solution code:
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
n=int(input())
list = list(map(int,input().split()))
ave=sum(list)/len(list)
k=(Decimal(str(ave)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
sum=0
for i in range(n):
	sum+=(k-list[i])**2
print(sum)

Submission status: Accepted

Solution code:
import math

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

mean1 = math.floor(sum(x)/n)
mean2 = math.ceil(sum(x)/n)

ans1 = 0
ans2 = 0
for i in range(n):
    ans1 += (x[i] - mean1)**2
    ans2 += (x[i] - mean2)**2

print(min(ans1, ans2))

Submission status: Accepted

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

def vital(P,Xi):
    return (Xi -P)**2

l.sort()
a, b = l[0],l[-1]
#print(a,b)

x = []
y = 0
for i in range(a,b+1):
    for j in range(n):
        y += (l[j] - i)**2
    x.append(y)
    y = 0
print(min(x))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

minv = min(a)
maxv = max(a)

val = minv

min_d = 100000000
for i in range(maxv-minv+1):
  d=0
  val = minv + i
  for j in range(len(a)):
    d += (a[j] - val)**2
  if d<min_d:
    mindv = val
    min_d = d

print(min_d)

Submission status: Accepted

Solution code:
n_regident = int(input())
address = list(map(int, input().split()))

min_total_dis = 100000000
for i in range(min(address), max(address)+1):
    total_dis = sum(map(lambda x:(x-i)**2, address))
    min_total_dis = min(min_total_dis, total_dis)

print(min_total_dis)

Submission status: Accepted

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

ans = float("inf")
for pos in range(x[0], x[-1]+1):
    tmp = 0
    for elm in x:
        tmp += (elm - pos) ** 2
    ans = min(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
L=list(map(int,input().split()))
r=0
for i in range(2*max(L)):
    b=0
    for j in range(n):
        b+=(L[j]-i)**2
    if i==0 or b<r:
        r=b
print(r)

Submission status: Accepted

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

y = max(x)
z = min(x)

s = 10**6
for test in range(z,y+1):
  case = list(map(lambda ex: (ex - test) ** 2 , x))
  t = sum(case)
  if t <= s:
    s = t
print(s)

Submission status: Accepted

Solution code:
#!/use/bin/env python3

from collections import defaultdict

n = int(input())
x_n = [int(s) for s in input().split()]

s = sorted(x_n)

ans = 1e18
for p in range(1, 101):
    l = sum([pow(x - p, 2) for x in s])

    if l < ans:
        ans = l

print(ans)

Submission status: Accepted

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

ave = sum(X)//N
sum0 = 0
sum1 = 0

for i in range(N):
  sum0 += (X[i]-ave-1)**2
  sum1 += (X[i]-ave)**2
  
print(min(sum0,sum1))

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
m=10**10
ll=list(set(X))
for P in range(min(ll),max(ll)+1):
    ans=[(x-P)**2 for x in X]
    s=sum(ans)
    if m>s:
        m=s
print(m)

Submission status: Accepted

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

y=sum(X)/len(X)
y=Decimal(str(y)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
ans=0
for x in X:
    ans+=(x-y)**2
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import statistics
n = int(input())
x = [int(i) for i in input().split()]
p = round(statistics.mean(x))
ans = 0
for i in x:
    ans += (i - p)**2
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N =int(input())

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

co_min = min(X)
co_max = max(X)

Y =np.ones(co_max-co_min)

for i in range(len(Y)):
    start = co_min + i
    Y[i] = sum((X-start)**2)
if co_min != co_max:    
    ans = int(min(Y))
elif co_min == co_max:
    ans =0
print(ans)

Submission status: Accepted

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

point = round(sum(list)/N)

ans_list = []
for item in list:
  ans_list.append((point - item)**2)

print(sum(ans_list))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
cost_b = 1000000
for n in range(1,101):
  cost = 0
  for x in X:
    cost += (x-n)**2
  if cost_b > cost:
    cost_b = cost
print(cost_b)

Submission status: Accepted

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

L = min(X)
R = max(X)

ans = 10000000
for P in range(L, R + 1):
    tmp = 0
    for Xi in X:
        tmp += (Xi - P) ** 2
    ans = min(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===
n = getInputInt()
data = getInputListInt()

data.sort()
min_num = sys.float_info.max

for i in range(data[0], data[len(data)-1]+1, 1):
    tmp_dis = 0
    for x in data:
        tmp_dis += float(pow(i - x, 2))
    min_num = min(min_num, tmp_dis)

print(int(min_num))

Submission status: Accepted

Solution code:
n=int(input())
import numpy as np
npi = np.array(list(map(int,input().split())))
if npi.mean()%1>0.5:
  p=npi.mean()//1 +1
else:
  p=npi.mean()//1
print(int(np.sum((npi-p)**2)))

Submission status: Accepted

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

ave = round(sum(X)/len(X))
count = 0
for i in range(len(X)):
    count += ((X[i]-ave)**2)
print(count)

Submission status: Accepted

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

ave_low = int(sum(x)/len(x))
ave_upp = int(sum(x)/len(x))+1

cout_low = 0
cout_upp = 0

for i in range(len(x)):
    cout_low = cout_low + (ave_low-x[i])*(ave_low-x[i])
    cout_upp = cout_upp + (ave_upp-x[i])*(ave_upp-x[i])

if cout_low <= cout_upp:
    print(cout_low)
else:
    print(cout_upp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
X.sort()
min_pw = 10**30

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

print(min_pw)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    x = list(map(int, input().split()))
    l = []
    for p in range(1, 101):
        r = 0
        for i in range(n):
            r += (x[i] - p) ** 2
        l.append(r)
    print(min(l))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = []

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

Submission status: Accepted

Solution code:
import math
N = int(input())
X = list(map(int,input().split()))
a = 100
l = []
ans = min([sum([(X[j]-(i+1))**2 for j in range(N)]) for i in range(100)])
print(ans)

Submission status: Accepted

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

sumXSq = sum([x*x for x in X])
sumX = sum(X)

# NP^2 - 2*SumX*P + sumXSq の最小値
# 微分して0 -> 2NP -2*SumX = 0
# P = sumX / N

P = int(sumX / N)
P2 = P + 1

ans = min(N*P*P - 2*sumX*P + sumXSq, N*P2*P2 - 2*sumX*P2 + sumXSq)

print(ans)

Submission status: Accepted

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

s = sum(x)
N = len(x)
mean = s / N
a = math.floor(mean)
b = math.ceil(mean)
ra = 0
rb = 0

for i in range(n):
    ra = ra + (x[i] - a) * (x[i] - a)

for i in range(n):
    rb = rb + (x[i] - b) * (x[i] - b)

if ra < rb:
    print(ra)
else:
    print(rb)

Submission status: Accepted

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

nowMinPoint = 9999999999
for chkp in range(1,100):
    tmpP = 0
    for xi in range(1,n+1):
        tmpP += abs(chkp-xList[xi-1])*abs(chkp-xList[xi-1])
    if nowMinPoint > tmpP:
        nowMinPoint = tmpP

print(nowMinPoint)

Submission status: Accepted

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

s=min(x)
b=max(x)

ans=100100100

for i in range(s,b+1):
    hp=0
    for j in x:
        hp+=(i-j)**2
    if hp<ans:
        ans=hp
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

def solve(N: int, X: "List[int]"):
    p = round(sum(X) / N)
    print(sum([(x-p)**2 for x in X]))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
import math
N = int(input())
l=[int(x) for x in input().rstrip().split()]
su=sum(l)
su=su/N
su = round(su)
ans=0

for i in l:
    ans+=(i-su)*(i-su)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
X = list(map(int,input().split()))
p = round(sum(X)/N)
s = 0
for i in X:
    s += (i - p) ** 2

print (s)

Submission status: Accepted

Solution code:
import sys

N = int(input())

line = input().split(" ")
X = []

for e in line:
	X.append(int(e))

ans = sys.maxsize
for P in range(101):
	curr = 0

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

	ans = min(ans, curr)


print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
ans = 10**9+7
for i in range(100):
  point = 0
  for j in X:
    point += ((j-i)**2)
  if point <= ans:
    ans = point
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
mid1=sum(X)//N+1
mid2=sum(X)//N


ans=0
ans2=0

for i in range(N):
    ans+=(X[i]-mid1)**2
    
for i in range(N):
    ans2+=(X[i]-mid2)**2
    
print(min(ans,ans2))

Submission status: Accepted

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

ans = float("inf")

for x in range(1, 101):
    temp = 0

    for i in range(N):
        temp += (X[i]-x)**2
    
    ans = min(temp, ans)

print(ans)

Submission status: Accepted

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

s=sum(L)

s1=s//len(L)
s2=math.ceil(s/len(L))

a=0
b=0
for i in L:
    a+=(s1-i)**2
    b+=(s2-i)**2

print(min(a,b))

Submission status: Accepted

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

INF = 10**7

def cost(x,p):
    return (x-p)**2

X.sort()
ans = INF
for p in range(X[0],X[N-1]+1):
    sum = 0
    for i in range(N):
        sum += cost(X[i],p)
    ans = min(ans,sum)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array(input().split(), np.int)
a.sort()

ans = []
for x in range(a[0], a[-1]+1):
    ans.append(np.sum((a - x) ** 2))

print(min(ans))

Submission status: Accepted

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

lhp = 100000000
for i in range(1, 100+1, 1):
    hp = 0
    for j in range(N):
        hp += (X[j] - i)**2
    if lhp >= hp:
        lhp = hp

print(lhp)

Submission status: Accepted

Solution code:
import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools

mod = int(1e9+7)
INF = 1<<29

def main():
    n = int(input())
    x = list(map(int,input().split()))
    ans = [INF] * 105
    for i in range(105):
        p = 0
        for j in range(n):
            p += (x[j]-(i+1))**2
        ans[i] = min(ans[i],p)
    print(min(ans))
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
X_min = min(X)
X_max = max(X)
S = []
for base_point in range(X_min, X_max+1):
    sum_X = 0
    for X_i in X:
        sum_X += (X_i-base_point)**2
    S.append(sum_X)
print(min(S))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
re = float('Inf')
for x in range(min(X),max(X)+1):
    tmp = 0
    for xx in X:
        tmp += (x - xx)**2
    re = min(re,tmp)
print(re)

Submission status: Accepted

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

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

Submission status: Accepted

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

ave = sum(x) / len(x)
ave_x = round(ave)
count = 0
for i in x:
    count += (i - ave_x) ** 2
print(count)

Submission status: Accepted

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

P1 = sum(X) // len(X)
P2 = -(-sum(X) // len(X))
ans1 = 0
ans2 = 0
for i in X:
    ans1 += (i - P1) ** 2
    ans2 += (i - P2) ** 2
print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input()) 
L = list(map(int, input().split()))
c = round(sum(L)/N)
ans = 0
for i in L:
  ans += (c - i) * (c - i)
print(ans)

Submission status: Accepted

Solution code:


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

#print(X_List)


Power_list = []
SUM = 0
for i in range(N):
    SUM += X_List[i]

Ave = round(SUM / N)


Consume = 0
for j in range(N):
    diff = (X_List[j] - Ave)
    Consume += diff * diff
    

print(Consume)

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

def main():
	N = II()
	X = LI()
	X.sort()
	X = np.array(X)
	X2 = X ** 2
	m0 = np.sum(X) // N
	m1 = m0+1
	print(min(np.sum(X2) - 2*m0*np.sum(X) + N*m0**2, np.sum(X2) - 2*m1*np.sum(X) + N*m1**2))

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
n=int(input())
X=list(map(int,input().split()))
ave=sum(X)/n
a=float('inf')
d=a
for i in range(1,101):
    if abs(ave-i)<=d:
        a=i
        d=abs(ave-i)
ans=0
for x in X:
    ans+=(x-a)**2
print(ans)

Submission status: Accepted

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

min_d=100*10000
for P in range(1,101):
    sum_d=0
    for i in range(N):
        sum_d+=(X[i]-P)**2
    min_d=min(min_d,sum_d)

print(min_d)

Submission status: Accepted

Solution code:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
INF  = float("inf") # 正の無限大

N = int(input())						# 5
X =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

ans=INF

for b in range(102):
	a=0
	for x in X:
		a+=(x-b)**2
		
		#p("x,b,x-b,a ",x,b,x-b,a)
		
	ans=min(ans,a)
	#p(ans,a,b)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

# X の avg をとり、Xi と avg との差の二乗を足し合わせていくのでよいのでは?

avg1 = sum(X) // N
avg2 = avg1 + 1
print(min(
    sum([(x - avg1) * (x - avg1) for x in X]),
    sum([(x - avg2) * (x - avg2) for x in X])
))

Submission status: Accepted

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

for i in range(1, 101):
    p = i
    power = 0
    for j in range(n):
        power += (x[j] - p)*(x[j] - p)
    if power < ans:
        ans = power

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
X_max = max(X)
ans = float('inf')
for i in range(X_max + 1):
    tmp_ans = 0
    for x in X:
        tmp_ans += (x - i) ** 2
    if tmp_ans < ans:
        ans = tmp_ans
print(ans)

Submission status: Accepted

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

cost = []

def mt(p):
    c = 0
    for i in range(len(X)):
        c += (X[i]-p)**2
    return c

for j in range(100):
    cost.append(mt(j))

print(min(cost))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(sys.stdin.readline()) #整数出力
L = [int(s) for s in sys.stdin.read().split()] #リスト作成
S = sum(L)
x = S // N
A_1 = sum([(s-x)**2 for s in L])
A_2 = sum([(s-x-1)**2 for s in L])
print(min(A_1,A_2))

Submission status: Accepted

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

ave1 = sum(x) // n
ave2 = (sum(x) + n - 1) // n
print(min(sum((i - ave1)**2 for i in x), sum((i - ave2)**2 for i in x)))

Submission status: Accepted

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

results = []
for i in range(1, 101):
    sum = 0
    for person in x:
        sum += (person-i)**2
    results.append(sum)

print(min(results))

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
a=0
b=0
for i in x:
    a=a+i
a=a/n
if a%1 < 0.5:
    a=a//1
else:
    a=(a//1)+1
for i in x:
    b=b+(i-a)*(i-a)
b=int(b//1)
print(b)

Submission status: Accepted

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

center = round((sum(X) / N), 0)

ans = 0
for i in range(N):
    ans += (X[i] - int(center)) ** 2

print(ans)

Submission status: Accepted

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

min_goukei = 2500 * 100

for i in range(100):
    goukei = 0
    for j in range(n):
        goukei += (x_list[j] - i)**2
    if goukei < min_goukei:
        min_goukei = goukei

print(min_goukei)

Submission status: Accepted

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

ans = 1000*1000
for p_x in range(X[0],X[-1]+1):
    hp = 0
    for i in X:
        hp += (p_x - i)**2
    ans = min(ans,hp)
print(ans)

Submission status: Accepted

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

min_zyusho = min(zyusyo)
max_zyusyo = max(zyusyo)

ans = 10**9
for p in range(min_zyusho, max_zyusyo+1):
    sum = 0
    for z in zyusyo:
        sum += (z-p)**2
    if sum < ans:
        ans = sum

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = input().split()
X = [int(s) for s in X]
if N == 1 or len(list(set(X)))==1:
    print(0)
else:
    X = sorted(X)
    range_X = X[-1] - X [0]

    E_min = 10000000000000000000000
    for p in range(range_X):
        E = 0
        for x in X:
            E += (x-p)**2
        if E < E_min:
            E_min = E
    print(E_min)

Submission status: Accepted

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

Submission status: Accepted

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

mi = min(xi)
ma = max(xi)
ans = 1000000

for i in range(mi, ma+1):
    num = 0
    for j in range(n):
        num += (xi[j]-i)**2
    ans = min(ans, num)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

avg = round(sum(X) / N)

ans = 0

for i in X:
    a = (i - avg)**2
    ans += a
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
x.sort()
res=100000000
for i in range(x[0],x[-1]+1):
    f=0
    for j in x:
        f+=(j-i)**2
    if res>f:
        ind=i
        res=f
print(res)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))#各社の座標
average = float(sum(x)/n)
ans =0
for i in range(n):
    ans += (x[i]-round(average))**2
print(ans)

Submission status: Accepted

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

#print(xi)

minv = float('inf')
for p in range(0, 101):
  minv = min(minv, sum([
    (p - x) ** 2
  	for x in xi
  ]))
print(minv)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
import numpy as np

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

    minpower = np.inf
    for P in range(1, max(X)+1):
        minpower = min(sum([(x-P)**2 for x in X]), minpower)

    print(minpower)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

#P=int(sum(X)/N)


temp=[]
for p  in range(0,3*N):
    answer=0
    for i in X:
        answer+=((i-p)**2)
    temp.append(answer)

print(min(temp))

Submission status: Accepted

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

s = sum(X)
mean = round(s / N)

P = []
for i in range(N):
    P.append((X[i]-mean)**2)

print(sum(P))

Submission status: Accepted

Solution code:
import sys

INF = sys.maxsize

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

costs = [INF] * (200)

for p in range(1, 101):
  costs[p] = sum(abs(p - r) ** 2 for r in residents)

print(min(costs))

Submission status: Accepted

Solution code:
import math
n = int(input())
x_list = list(map(int,input().split()))
 
avg = sum(x_list)/ len(x_list)
avg_up = math.ceil(avg)
avg_down = math.floor(avg)
 
up_sum = 0
down_sum = 0
for i in x_list:
    up_sum += (i - avg_up)**2
    down_sum += (i - avg_down)**2
    
print(min(up_sum,down_sum))

Submission status: Accepted

Solution code:
# coding: utf-8
import math

n = input()
xs = map(int, raw_input().split())

#avg = 1.0 * sum(xs) / n
#mindist = math.ceil(sum((x - avg) ** 2 for x in xs))

p = round(1.0 * sum(xs) / n)
mindist = math.ceil(sum((x - p) ** 2 for x in xs))

print int(mindist)

Submission status: Accepted

Solution code:
N = int(input())
x = list(map(int, input().split()))
import numpy as np
x = np.array(x)
E = 10**9 #総和がこの値を超えることはない
for i in range(1, 101):
  e_tem = np.sum((x-i)**2)
  if e_tem < E:
    E = e_tem
print(E)

Submission status: Accepted

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

m1 = -(-sum(x) // len(x))
m2 = sum(x) // len(x)
ans1 = 0
ans2 = 0
for xi in x:
    ans1 += (xi - m1)**2
    ans2 += (xi - m2)**2

print(min(ans1, ans2))

Submission status: Accepted

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

sum = []
for i in range(1, 101):
    sums = 0
    for x in xs:
        s = (x-i) ** 2
        sums += s
    sum.append(sums)
print(min(sum))

Submission status: Accepted

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

p = round(sum(X) / len(X))

point = [0] * len(X)
for i in range(len(X)):
    point[i] = (X[i] - p)**2

print(sum(point))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import math

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

guess1 = math.floor(np.mean(X))
guess2 = math.ceil(np.mean(X))

value1 = 0
value2 = 0
for i in range(N):
    value1 += (X[i] - guess1)**2
    value2 += (X[i] - guess2)**2
if value1 <= value2:
    print(value1)
else:
    print(value2)

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()))
res = 100**100
for i in range(1, 101):
  tmp = 0
  for j in range(N):
    tmp += (i-X[j])**2
  if tmp < res:
    res = tmp

print(res)

Submission status: Accepted

Solution code:
import math

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

s = 0
for i in range(len(x)):
    s += x[i]

s /= len(x)

s = math.floor(s)

m1 = 0
m2 = 0

for i in range(len(x)):
    m1 += math.pow(x[i] - s,2)
    m2 += math.pow(x[i] - s - 1,2)

print(int(min(m1, m2)))

Submission status: Accepted

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

res = 10 ** 8

for p in range(1, 101):
    now = 0
    for x in Xs:
        now += (x - p)**2
    res = min(now, res)

print(res)

Submission status: Accepted

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

min_sum = 10000000000000000000000000000000000000

for j in range(0,100):
	tmp_sum = 0
	for i in range(N):
		tmp_sum += (X[i] - j) ** 2
	if tmp_sum < min_sum:
		min_sum = tmp_sum
	#print(tmp_sum)
print(min_sum)

Submission status: Accepted

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

for i in range(201):
    ans = sum([k ** 2 for k in X - i])
    if i > 0:
        ans_min = min(ans_min, ans)
    else:
        ans_min = ans
print(ans_min)

Submission status: Accepted

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

x = np.array(x)
ans = [0]*101

for i in range(101):
    y = np.full(n, i)
    z = x-y
    z = np.power(z, 2)
    ans[i] = np.sum(z)

print(int(min(ans)))