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:
# coding: utf-8
import sys

N = int(input())
Xi = list(map(int, input().split()))
Xi.sort()
min = Xi[0]
max = Xi[N-1]
tmp = 0
result = sys.maxsize
for i in range(min,max+1):
    for j in range(0,N):
        tmp += (Xi[j] - i)**2
    if tmp <= result:
        result = tmp
    tmp = 0

print(result)

Submission status: Accepted

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
M = max(L)
A = min(L)
Z_L = list()
for i in range(A, M + 1):
  ZZ = 0
  for j in range(N):
    Z =  pow(L[j] - i, 2)
    ZZ += Z
  Z_L.append(ZZ)
print(min(Z_L))

Submission status: Accepted

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

avg = sum(X)/len(X)
avg=round(avg,0)

sum=0
for i in range(N):
    sum+=int((avg-X[i])*(avg-X[i]))
print(sum)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
X.sort()
x_min=X[0]
x_max=X[N-1]
Min=10**10
for i in range(x_min,x_max+1):
    p=0
    for j in range(N):
        p+=(X[j]-i)**2
    if Min>p:
        Min=p
print(Min)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
p = int(sum(x)/len(x))
ans1 = sum(map(lambda a:(a-p)**2, x))
ans2 = sum(map(lambda a:(a-p-1)**2, x))

if ans1 > ans2:
    print(ans2)
else:
    print(ans1)

Submission status: Accepted

Solution code:
_=input()
a=list(map(int,input().split()))
b=round(sum(a)/len(a))
res=0
for i in a:
    res+=(i-b)**2
print(res)

Submission status: Accepted

Solution code:
def rally(n , xl):

    ans = 0

    aaa = round(sum(xl) / n)

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

    return ans

def main():
    n = int(input())
    xl = list(map(int , input().split()))
    print(rally(n , xl))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
sum = 0
min_sum = 100000000
P = 1
while P <= 100:
  for n in X:
    sum = sum +(n-P)**2
  if sum <= min_sum:
    min_sum = sum
  P = P + 1
  sum = 0
print(min_sum)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
def P(n):
    return sum([(X[i]-n)**2 for i in range(0,N)])
l=[P(i) for i in range(1,101)]
print(min(l))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 10**10
for i in range(min(X),max(X)+1):
    total = 0
    for l in range(N):
        total += (X[l] - i)**2
    if total <= ans:
        ans = total
print(ans)

Submission status: Accepted

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

for i in range(max(X) + 1):
    for a in X:
        b = b + pow((a - i),2)
    Z.append(b)
    b = 0

print(min(Z))

Submission status: Accepted

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

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

if N%n ==0:
	print(ans)
else:
	print(min(ans,ans+n-2*N+2*(N//n)*n))

Submission status: Accepted

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

mini, maxi = min(x), max(x)
min2, max2 = mini**2*n, maxi**2*n
ans = max2 if max2 > min2 else min2

for p in range(mini, maxi+1):
  suma = 0
  for z in x:
    suma += (z-p)**2
  if ans > suma:
    ans = suma
    
print(ans)

Submission status: Accepted

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

X.sort()

ans = 0

for i in range(X[-1] - X[0] + 1):
    tmp = 0
    for j in X:
        tmp += (j - (X[0] + i))**2
    
    if i == 0:
        ans = tmp
    else:
        if ans > tmp:
            ans = tmp

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
s = 0
for i in range(1,101):
    temp = 0
    for j in range(N):
        temp += (i - X[j])**2
    if i == 1:
        s = temp
    elif s < temp:
        pass
    elif s >= temp:
        s = temp
print(s)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
X = [int(i) for i in input().split()]
X = np.array(X)
res = 100**100
for i in range(max(X+1)):
    tmp = sum((abs(X-i))**2)
    #print(tmp)
    if res > tmp:
        res = tmp
print(res)

Submission status: Accepted

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

def answer(n,l):
    ans = 10000000
    tmp = 0
    for i in range(min(l),max(l)+1):
        tmp = 0
        tmp_L = map(lambda x:(x-i)**2,l)
        tmp = sum(tmp_L)
        if ans >= tmp:
            ans = tmp
    return(ans)        
print(answer(N,L_X))

Submission status: Accepted

Solution code:
import sys
l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip()
nums = list(map(int, l.split()))
a = sum(nums) / len(nums)
a1 = int(a)
a2 = int(a) + 1
def count(p):
    d = 0
    for n in nums:
        d += (n-p)**2
    return d
print(min(count(a1), count(a2)))

Submission status: Accepted

Solution code:
import sys
l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip()
nums = map(int, l.split())
nums = sorted(nums)
start = nums[0]
end = nums[-1] + 1
mi = float("INF")
def compute_dist(p):
  dist = 0
  for n in nums:
    dist += (n-p) ** 2
  return dist
for i in range(start, end):
  d = compute_dist(i)
  if d < mi:
    mi = d
print(mi)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
s = 0
for i in range(1,101):
    temp = 0
    for j in range(N):
        temp += (i - X[j])**2
    if i == 1:
        s = temp
    elif s < temp:
        pass
    elif s >= temp:
        s = temp
print(s)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  x = list(int(i) for i in input().split())
  ans = 10**15
  for i in range(1,101):
    score = 0
    for j in range(n):
      score += (x[j]-i)**2
    ans = min(ans,score)    
  print(ans)
solve()

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
n = np.array([int(i) for i in input().split()])
n=n-int(round(np.sum(n)/N))
print(np.sum(n*n))

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
n = np.array([int(i) for i in input().split()])
n=n-int(round(sum(n)/N))
print(sum(n*n))

Submission status: Accepted

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

s=float("inf")
for i in range(min(X),max(X)+1):
   d=0
   for j in X:
      d+=(j-i)**2
   s=min(s,d)
print(s)

Submission status: Accepted

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

ans = 1000000
for p in range(X[0], X[-1]+1):
    health = 0
    for i in X:
        health += (p-i)**2

    ans = min(ans, health)

print(ans)

Submission status: Accepted

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

p = sum(x)/N

q = int(p)

ans1 = 0
ans2 = 0
for i in range(N):
	ans1 += (x[i]-q)*(x[i]-q)
	ans2 += (x[i]-q-1)*(x[i]-q-1)
print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INF = 10**10

def solve(n, x):
    best = INF
    for p in range(min(x), max(x)+1):
        cost = sum((xi-p)**2 for xi in x)
        best = min(best, cost)
    return best

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

Submission status: Accepted

Solution code:
a=int(input())
lis=sorted(list(map(int , input().split())))
ans=float('inf')
ans2=0
for i in range(lis[-1]):
  for j in lis:
    ans2+=(j-(i+1))**2
  if ans>ans2:
    ans=ans2
  ans2=0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def calc(center):
    ret = 0
    for a in A:
        ret += (a - center)**2
    return ret

ans = 10**10
for c in range(min(A), max(A) + 1):
    ans = min(ans, calc(c))

print(ans)

Submission status: Accepted

Solution code:
def main():
	k = int(input())
	a = list(map(int,input().split()))
	
	minans = []
	minlist = []
	for i in range(100):
		for s in range(k):
			minans.append((a[s] - i)**2)
		minlist.append(int(sum(minans)))
		minans = []
	print(min(minlist))
		
	
	
 
if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
ans = 10**7
for p in range(1,101):
    res = 0
    for x in X:
        res += (x-p) ** 2
    ans = min(ans, res)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int,input().split()))
aprx = round(sum(arr)/n)
ans = 0

for i in arr:
  ans+= ((i-aprx)**2)
  
  #ans+=q
  
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
x=np.fromstring(input(),int,sep=' ')
p=0
hoge=np.inf
for i in range(1,np.max(x)+1):
    sux=sum((x-i)**2)
    if sux<hoge:
        p=i
        hoge=sux
print(hoge)

Submission status: Accepted

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

Submission status: Accepted

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

    P = sum(X) // N
    ans1 = 0
    for x in X:
        ans1 += (x - P) ** 2
    ans2 = 0
    for x in X:
        ans2 += (x - (P + 1)) ** 2
    print(min(ans1, ans2))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
min_tairyoku_sum = float("inf")
for i in range(1,101):
    tairyoku_sum = 0
    for x in X:
        tairyoku_sum += (x - i) ** 2
    min_tairyoku_sum = min(tairyoku_sum, min_tairyoku_sum)
print(min_tairyoku_sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
k=0
h=max(a)
s=9999999999999999999999999999
for i in range(1,h+1):
  k=0
  for j in range(n):
    k+=(a[j]-i)**2
  s=min(s,k)
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

ave = sum(x)/n
y0 = int(ave)
z0 = sum([(i-y0)**2 for i in x])
y1 = y0+1
z1 = sum([(i-y1)**2 for i in x])

print(min(z0, z1))

Submission status: Accepted

Solution code:
n=int(input())
X=list(map(int,input().split()))
ans=float('inf')
for i in range(min(X),max(X)+1):
  now=0
  for x in X:
    now+=(i-x)*(i-x)
  ans=min(now,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
ans = 1000000000000000000000000000000000
for i in range(100):
    d = 0
    for j in l:
        d += (j-(i+1))**2
    if ans > d:
        ans = d
print(ans)

Submission status: Accepted

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

for p in range(1, 101):
    for i in range(N):
        num += (X[i] - p) ** 2
    if num < ans:
        ans = num
        num = 0

print(ans)

Submission status: Accepted

Solution code:
def calc_sum_energy(p, x_list) -> int:
    return sum([(p - x) ** 2 for x in x_list])


def main(n, x_list):
    print(min([calc_sum_energy(p, x_list) for p in range(1, 101)]))


if __name__ == "__main__":
    n = int(input())
    x_list = [int(i) for i in input().split()]

    main(n, x_list)

Submission status: Accepted

Solution code:
n = int(input())
*x, = map(int, input().split())
ans = float('inf')

for i in range(min(x), max(x)+1):
    tmp = 0
    for j in x:
        tmp += (j - i)*(j - i)
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)


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


def read_index():
    return map(lambda x: x - 1, map(int, input().split()))


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def main():
    N = int(input())
    X = read_list()
    res = 10 ** 10
    for y in range(1, 101):
        res = min(res, sum((x - y) ** 2 for x in X))
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

center = round(sum(l) / N)
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(int(x) for x in input().split())
p = round(sum(X)/len(X))
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
X = np.array(list(int(x) for x in input().split()))
m = round(np.mean(X))

print(int(sum((X-m)**2)))

Submission status: Accepted

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

m = min(X)
M = max(X)

min_val = 100 * 100 * 100
for p in range(m, M+1):
    score = 0
    for x in X:
         score += (x-p)*(x-p)
    if score < min_val: min_val = score
print(min_val)

Submission status: Accepted

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

m = min(X)
M = max(X)

cost = [1000000009 for _ in range(101)]
for p in range(1,101):
    c = 0
    for x in X:
        c += (x-p)**2
    cost[p] = c

print(min(cost))

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
l = np.array([int(i) for i in input().split()])
mean = np.mean(l)

ans = 10 ** 9

for i in [int(mean),int(mean)-1,int(mean)+1]:
    ans = min(ans, np.sum(((l-i)*(l-i))))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
mini = 980100
for i in range(1, 101):
    l_sum = sum(list(map(lambda x: (x - i)**2, l)))
    if mini > l_sum:
        mini = l_sum
print(mini)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
import numpy as np
P = np.average(X)
P = round(P)
d = [(x - P)**2 for x in X]
ans = int(np.sum(d))
print(ans)

Submission status: Accepted

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

import sys

def solve(xs):
    xs.sort()
    ans = float('inf')
    for p in range(xs[0], xs[-1] + 1):
        distance = 0
        for x in xs:
            distance += (p - x)**2
        if distance < ans:
            ans = distance
    return ans


def read_int_list():
    return [int(s) for s in sys.stdin.readline().rstrip().split(" ")]


def dprint(*args, **kwargs):
    return
    print(*args, **kwargs)


def main():
    n = int(sys.stdin.readline().rstrip())
    print(solve(read_int_list()))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

mpow = 100*100*100*100*100

for P in range(100):
    temp = 0
    for Xi in X:
        temp += (Xi-P)*(Xi-P)
        if temp > mpow:
            break 
    if temp < mpow:
        mpow = temp

print(mpow)

Submission status: Accepted

Solution code:
e = 0.0001
N = int(input())
X = list(map(int, input().split()))
ave = sum(X) / N
loc = round(ave + e)
ans = 0
for i in range(N):
    ans += (X[i] - loc) ** 2
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
Xs = np.array(input().split(), dtype=int)


scales = np.arange(-100, 100) ** 2

res = np.zeros(100)
for x in Xs:
    res += scales[100 - x: 200 - x]

print(res.min().astype(int))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
k = sum(X) / N - 1 / 2
P = int(k) + 1

X = list(map(lambda x: (x - P)**2 ,X))
ans = sum(X)
print(ans)

Submission status: Accepted

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

minimum = 1e17
coor = 1
for i in range(1, 101):
    s = sum((x-i)**2 for x in l)
    if s < minimum:
        minimum = s
        coor = i

print(minimum)

Submission status: Accepted

Solution code:
n = int(input())
x_arr = [i for i in map(int,input().split())]
ans = 999999999
for i in range(1,100):
  temp = 0
  for j in range(len(x_arr)):
    temp += (x_arr[j] - i)**2
  if temp < ans:
    ans = temp
    
print(ans)

Submission status: Accepted

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

l = x[0]
r = x[-1]
S = 10 ** 9

for i in range(l, r+1):
    s = sum([(p-i)**2 for p in x])
    S = min(s, S)
print(S)

Submission status: Accepted

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

s = 0
for xi in X:
    s += xi
si = round(s / N)
ps = 0
for xi in X:
    ps += int(math.pow(xi-si, 2))
print(ps)

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
mi = 10**10
for i in range(100):
    point = 0
    for j in li:
        point += (j-i)**2
    mi = min(mi,point)
print(mi)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')

def main():
	N = inputInt()
	X = inputList()

	ans = inf
	for i in range(1,101):
		total = 0
		for j,val in enumerate(X):
			tmp = (val-i)**2
			total += tmp
		#print(total)
		if ans > total:
			ans = total

	print(ans)


if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 10000000000
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())
Xs = list(map(int, input().split()))

min_cost = float('inf')
for i in range(min(Xs), max(Xs)+1):
    cost = 0
    for x in Xs:
        cost += (x-i)**2
    if cost < min_cost:
        min_cost = cost

print(min_cost)

Submission status: Accepted

Solution code:
n = int(input())

r = list(map(int,input().split(' ')))

res = []
for i in range(min(r),max(r) + 1):
  k = 0
  for j in r:
    k = k + (j - i) ** 2
  res.append(k)
print(min(res))

Submission status: Accepted

Solution code:
import sys

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

for i in range(1, 100):
    hp = 0    
    for j in range(n):
        hp += (x[j] - i) * (x[j] - i)

    
    min_hp = min(hp, min_hp)
    
print(min_hp)

Submission status: Accepted

Solution code:
import sys

INF = 1000000000

def resolve():
  n = int(input())
  x = list(map(int, input().split()))
  ans = INF
  for i in range(1, 100):
    t = x
    tmp = 0
    for j in x:
      tmp += abs(i - j) ** 2
    ans = min(ans, tmp)
  print(ans)
  return

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
*x, = map(int, input().split())
x.sort()
ans = float('inf')

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

X.sort()

sumx = sum(X)
lenx = len(X)

point = round(sumx / lenx)

totalcost = 0
for Xi in X:
    totalcost += pow((Xi - point), 2)

print(totalcost)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
A=sum(X)
y=N*((round(A/N)-A/N)**2)-(A**2)/N
B=sum([i**2 for i in X])
print(int(y+B))

Submission status: Accepted

Solution code:
import numpy as np


n = int(input())
X = np.array(list(map(int, input().split())), dtype=np.int64)

ans = []
for pos in range(1, 101):
    cost = ((X - pos) ** 2).sum()
    ans.append(cost)

print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

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

ans = float("inf")

for i in range(min(x), max(x)+1):
    power = 0
    for j in range(len(x)):
        power += (x[j] - i) ** 2
    ans = min(ans, power)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

m = sum(X)//len(X)
S = min(sum([(x-m)**2 for x in X]),sum([(x-m-1)**2 for x in X]))
print(S)

Submission status: Accepted

Solution code:
n = int(input())
 
x = input().split()
x = [int(_x) for _x in x]
 
_p = sum(x) // n
 
_p_value = sum([(_x - _p) ** 2 for _x in x])
__p_value = sum([(_x - _p + 1) ** 2 for _x in x])
___p_value = sum([(_x - _p - 1) ** 2 for _x in x])
 
print(min(_p_value, min(__p_value, ___p_value)))

Submission status: Accepted

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

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

for i in range(x_min + 1, x_max + 1):
    tmp = 0
    for k in x:
        tmp = tmp + (k - i) ** 2
    
    if ans == 0:
        ans = tmp
    elif ans > tmp:
        ans = tmp
        
print(ans)

Submission status: Accepted

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

ans = x[-1]**2 *n
for _n in range(x[0], x[-1]+1):
    _ans = sum([(_x - _n)**2 for _x in x])
    ans = min(_ans, ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
s = sum(x)
p = (s+0.5*n)//n
r = 0
for y in x:
    r += (y - p)**2
print(int(r))

Submission status: Accepted

Solution code:
N = int(input())
Xs = list(map(int, input().split()))
L,R = min(Xs), max(Xs)
cost = 0 if L==R else float("inf")
for p in range(L+1,R):
  cost_p = sum([(xi-p)**2 for xi in Xs])
  cost = cost_p if cost_p < cost else cost
print(cost)

Submission status: Accepted

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

y = []
for p in range(100):
    y.append(sum([(p-x)**2 for x in xs]))
print(min(y))

Submission status: Accepted

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

x = [int(i) for i in x]
x = sorted(x)

s =round(sum(x)/n)
l = 0

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

print(l)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
Sum = 0
Min = float("inf")
for i in range(100):
    Sum = 0
    for j in x:
        Sum += (j - i)**2
    if Sum < Min:
        Min = Sum
print(Min)

Submission status: Accepted

Solution code:
import math

n=int(input())
l = list(map(int, input().split()))
ave=sum(l)/n
ave2=round(ave)
min=0
for i in range(n):
    min+=(l[i]-ave2)**2
print(min)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
Sum = 0
Min = 9999999999
for i in range(100):
    Sum = 0
    for j in x:
        Sum += (j - i)**2
    if Sum < Min:
        Min = Sum
print(Min)

Submission status: Accepted

Solution code:
from decimal import Decimal, ROUND_HALF_UP
import numpy as np
n = int(input())
x = np.array(input().split(), int)

m = Decimal(np.sum(x) / n)
mq = int(m.quantize(0, rounding=ROUND_HALF_UP))

s = np.sum((x-mq)**2)
print(s)

Submission status: Accepted

Solution code:
import math

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

a = sum(lst)//len(lst)
b = -(-sum(lst)//len(lst))

ans_a=0
ans_b=0
for i in lst:
    ans_a += (i-a)**2
    ans_b += (i-b)**2

print(min(ans_a,ans_b))

Submission status: Accepted

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


ans = 10**18
def rally(p):
    n = 0
    for a in range(N):
        n += (int(p)-List[a])**2
    return n

for i in range(1,101):
    ans = min(rally(i),ans)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
import numpy as np

def main():
	n=int(input())
	X=list(map(int,input().split()))
	X=np.array(X)
	X.sort()
	ans=10**10
	
	for i in range(X[0],X[-1]+1,1):
		ans=min(ans,sum((X-i)**2))
	print(ans)
	
	
	
	
	
	
	
	
	
	
	
	
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

a = sum(x*x for x in X)
b = sum(X)

print(min(a - 2 * p * b + N * p * p for p in [b//N, b//N+1]))

Submission status: Accepted

Solution code:
N = int(input())
 
X = list(map(int, input().split()))
 
a = round((sum(X) / N), 3)
integer = int(a)
f = a - integer
 
if f < 0.5:
    P = integer
else:
    P = integer + 1
 
total = 0
for i in X:
    total += (i - P) ** 2
 
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

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

    ans = float('inf')
    for i in range(1,101):
        tmp = 0
        for x in X:
            tmp += (x - i)**2
        
        if tmp < ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()