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 = list(map(int,input().split()))
ans = 1000**1000
for P in range(0,101):
    for i in range(1,N+1):
        if i == 1:
            c = (X[0]-P)**2
        else:
            c += (X[i-1] - P)**2
    if c < ans:
        ans = c
print(ans)

Submission status: Accepted

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

ans = 1000000
for i in range(1, 101):
    tmp=0
    for x in Xn:
        tmp += (x-i)**2
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:

def experiment(xlist, coordinate):
    return sum( (xi-coordinate)**2 for xi in xlist)

N = input()
xlist = sorted([int(i) for i in input().split()])
s, l = xlist[0], xlist[-1]

min_stamina = float("inf")

for cord in range(s, l+1):
    min_stamina = min(min_stamina, experiment(xlist, cord))

print(min_stamina)

Submission status: Accepted

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

import numpy as np
x = np.array(x)
a = np.floor(np.mean(x))
b = a + 1

print(min(int(((x - a) ** 2).sum()), int(((x - b) ** 2).sum())))

Submission status: Accepted

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

Submission status: Accepted

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

import math
p = round(sum(x)/n)

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

Submission status: Accepted

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

'''
7
14 14 2 13 56 2 37
'''

import sys

# 再起回数上限変更
sys.setrecursionlimit(1000000)

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

P = sum(x) / N
P = int(P)

res1 = sum([(x[i] - P)**2 for i in range(N)])
if P + 1 <= 100:
    res2 = sum([(x[i] - (P+1))**2 for i in range(N)])
else:
    res2 = float('inf')

print(min(res1, res2))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
L=min(A)
R=max(A)
MIN=1000000000000000
for i in range(L, R+1):
    length=0
    for j in range(N):
        length+=(A[j]-i)**2
    if length<=MIN:
        MIN=length

print(MIN)

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int, input().split()))
ans = 0
ave = round(sum(l)/N)

for i in l:
    ans += (i-ave)**2

print(ans)

Submission status: Accepted

Solution code:
import math


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


mi_stamina = 1000000000
for i in range(-1000, 1000):
    def _distance(x):
        return (x-i)**2
    double_list = list(map(_distance, x_list))
    stamina = sum(double_list)
    if mi_stamina > stamina:
        mi_stamina = stamina

print(mi_stamina)

Submission status: Accepted

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

l = min(X)
r = max(X)
ans = 100000000000
for i in range(l, r+1):
    now = 0
    for j in range(N):
        now += (X[j]-i)*(X[j]-i)
    ans = min(now, ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

minx = min(xs)
maxx = max(xs)

cnt = 10**9
for i in range(minx, maxx + 1):
    all = 0
    for x in xs:
        all += (x - i)**2
    if cnt > all:
        cnt = all


print(cnt)

Submission status: Accepted

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

n = load()
X = load_list()


mn = 2**100
for i in range(1, max(X)+1):
    power = sum([(x-i) * (x-i) for x in X])
    mn = min(power, mn)

print(mn)

Submission status: Accepted

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
x=n1()
ans=999999999
for y in range(min(x),max(x)+1):
    s=0
    for i in range(n):
        s+=(x[i]-y)**2
    ans=min(ans,s)
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):
    ans.append(sum((x-i)**2 for x in X))

print(min(ans))

Submission status: Accepted

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

"""
    min(X) 以上、 max(X) 以下の整数を全探索
    1 <= X[i] <= 100 なので時間計算量は O(N(Xmax - Xmin)) <= O(N^2)
"""

X.sort()
ans = 10 ** 12
# for p in range(X[0], X[N - 1] + 1):
for p in range(1, 101):
    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()))

"""
    min(X) 以上、 max(X) 以下の整数を全探索
    1 <= X[i] <= 100 なので時間計算量は O(N(Xmax - Xmin)) <= O(N^2)
"""

X.sort()
ans = 10 ** 12
for p in range(X[0], X[N - 1] + 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()))
sum = 0
ans = 1000000
for i in range(1, 101):
    for j in range(n):
        sum += (x[j] - i)**2
    if sum < ans:
        ans = sum
    sum = 0

print(ans)

Submission status: Accepted

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

p = sum(x)//n
pa = p + 1

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

ans1 = ans + n*(pa**2)
ans1 -= 2*pa*sum(x)

ans += n*(p**2)
ans -= 2*p*sum(x)

print(min(ans, ans1))

Submission status: Accepted

Solution code:
# import n as integer
n = int(input())
# obtain list
l = list(map(int, input().split()))

# take avg. of where person is
avg = sum(l)/n
sum = 0

if abs(avg//1 - avg) < abs(avg//1+1 - avg):
	for i in range(0,n):
		sum+=(l[i]-avg//1)**2
else:
	for i in range(0,n):
		sum+=(l[i]-avg//1-1)**2

print(int(sum))

Submission status: Accepted

Solution code:
N=int(input())
ls=[int(s) for s in input().split()]
b=sum(ls)
x=b//N
y=x+1
sumx=0
sumy=0
for e in ls:
  sumx+=(x-e)*(x-e)
  sumy+=(y-e)*(y-e)
print(min([sumx,sumy]))

Submission status: Accepted

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

Submission status: Accepted

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

mi=min(a)
ma=max(a)

result=10**10
for i in range(mi,ma+1):
  temp=0
  for item in a:
    temp+=(item-i)**2
  result=min(result,temp)
  
print(result)

Submission status: Accepted

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

X_max = X[0]
X_min = X[0]

for i in range(N):
    if X_max < X[i]:
        X_max = X[i]
    if X_min > X[i]:
        X_min = X[i]

min = 0
count = 0
for p in range(X_min, X_max+1, 1):
    total = 0
    for i in range(N):
        total += (X[i]-p)**2
    count += 1
    if count == 1:
        min = total
    elif  min > total:
        min = total

print(min)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int,input().split()))
s.sort()
ans = 10**9
for i in range(101):
  sum = 0
  for j in s:
    sum += (i-j)**2
  if sum < ans: ans = sum
  else: break  

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
inp=list(map(int,input().strip().split()))[:n]
min1=99999999
for i in range(max(inp)):
    sum1=0
    l=i+1
    for j in inp:
        sum1+=(j-l)**2
    min1=min(min1,sum1)
print(min1)

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
p = int(sum(b) / len(b))
ans1 = ans2 = 0
for x in b:
    ans1 += (x - p) ** 2
    ans2 += (x - 1 - p) ** 2
if ans1 > ans2:
    print(ans2)
else:
    print(ans1)

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
p = min(b)
saveans = 0
ans = 0
for x in b:
    ans += (x - p) ** 2

while p <= max(b):
    saveans = 0
    for x in b:
        saveans += (x - p) ** 2
    if saveans < ans:
        ans = saveans
    p += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x_list = list(map(int, input().split()))
ans = 10**8
for p in range(1,101):
    d = 0
    for i in x_list:
        d += (i-p)**2
    ans = min(ans, d)
print(ans)

Submission status: Accepted

Solution code:
n = int(input());

v = [int(i) for i in input().split()];

res = 1000000;
for p in range(101):
    curr = 0;
    for x in v:
        curr += (x - p)**2;
    res = min(res, curr);

print(res);

Submission status: Accepted

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

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

Submission status: Accepted

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

lists_ave = round(sum(lists)/len(lists))
a = 0
for i in range(len(lists)):
    a += (lists[i] - lists_ave)**2

print(a)

Submission status: Accepted

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

P = round(sum(X) / len(X))
consume_HP = sum([(x-P)**2 for x in X])
print(consume_HP)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
m = int(sum(a)/n)
power1 = 0
power2 = 0
for ind in range(n):
    power1 += (a[ind]-m)**2
    power2 += (a[ind]-m-1)**2
print(min(power1,power2))

Submission status: Accepted

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

Submission status: Accepted

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

P = round(sum(X)/N)
print(int(sum([(x-P)**2 for x in X])))

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
X = np.array(list(map(int,input().split())))
mean = np.mean(X)
koho1 = int(mean)
koho2 = int(mean+1)
ans1 = np.sum((X - koho1)**2)
ans2 = np.sum((X - koho2)**2)
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
import sys
import math

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

ans = 10000000
for p in range(1, max(X) + 1 ):
    cost = 0
    for x in X:
        cost += (x-p)**2
    ans = min( cost ,  ans )

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
dist = float("inf")
d = 0
xmin = min(X)
xmax = max(X)
for i in range(xmin, xmax + 1):
	d = 0
	for x in X:
		d += (x - i) ** 2
	if d < dist:
		dist = d
print(dist)

Submission status: Accepted

Solution code:
n = int(input())
xs = list(map(int, input().split()))
xs_min = min(xs)
xs_max = max(xs)

fatigue_min = float("inf")

for i in range(xs_min, xs_max + 1):
  fatigue = 0
  for x in xs:
    fatigue += (x - i) ** 2
  if fatigue < fatigue_min:
    fatigue_min = fatigue
  else:
    print(fatigue_min)
    exit()
else:
  print("0")

Submission status: Accepted

Solution code:
#template
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
X = inputlist()
ans = 10**9+7
for i in range(110):
    k = 0
    for j in range(N):
        k += (X[j] - i)**2
    ans = min(ans,k)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

solution()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

p = [int(np.mean(x)), int(np.mean(x)) + 1]
xnp = np.array(x)

min_xp = -1
for pi in p:
    if min_xp == -1:
        min_xp = np.square(xnp - pi).sum()
    elif min_xp > np.square(xnp - pi).sum():
        min_xp = np.square(xnp - pi).sum()
print(min_xp)

Submission status: Accepted

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

Submission status: Accepted

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

HP = [0] * 100

for k in range(1, 101):
    for i in range(N):
        HP[k-1] += (X[i] - k) ** 2

print(min(HP))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  x = list(map(int, readline().split()))
  ave = int(sum(x)/n+0.5)
  ans = 0
  for i in range(n):
    ans += (x[i]-ave)**2
  print(ans)
  
if __name__ == '__main__':
  main()

Submission status: Accepted

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

ans = 10 ** 9

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

print(ans)

Submission status: Accepted

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

zahyo = 10**15

for i in range(101):
    tmp = 0
    for j in range(N):
        tmp += (X[j]-i)**2
    zahyo = min(zahyo, tmp)
print(zahyo)

Submission status: Accepted

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

# print(sum(x)/len(x))
mean = math.floor(sum(x)/len(x))
mean2 = mean + 1
ans = 0
ans2 = 0
for i in x:
    ans += (i - mean) ** 2
    ans2 += (i - mean2) ** 2

if ans <= ans2:
    print(ans)
    exit()
else:
    print(ans2)
    exit()

Submission status: Accepted

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

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

point = round(sum/n)

cost = 0
for j in range(len(x)):
    cost = cost + (x[j] - point) ** 2

print(cost)

Submission status: Accepted

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

	ans = 10000000

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

		if ans > s:
			ans = s

	print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
x=input().split()
x=[int(s) for s in x]
b=sum(x)/N
if b>int(b)+0.5:
    b=int(b)+1
else:
    b=int(b)
d=0
for i in x:
    c=(i-b)**2
    d+=c
print(d)

Submission status: Accepted

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

Submission status: Accepted

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

x.sort()
cnt = 0
minimum = 0
for i in range(x[0], x[-1] + 1):
    for j in range(n):
        cnt += (x[j] - i) ** 2

    if i == x[0]:
        minimum = cnt

    minimum = min([minimum, cnt])
    cnt = 0

print(minimum)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
X = np.array(input().split(),np.int64)
ls = []
for i in range(101):
    ls.append(np.sum((X - i) ** 2))

print(min(ls))

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
t=sum(x)/n
s=int(t)
a=min(t-s,s+1-t)
b=0
if a==t-s:
  b=s
else:
  b=s+1
p=0
for i in range(n):
  p+=(x[i]-b)**2
print(p)

Submission status: Accepted

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

x.sort()
cnt = 0
minimum = 0
for i in range(x[0], x[-1] + 1):
    for j in range(n):
        cnt += (x[j] - i) ** 2
    
    if i == x[0]:
        minimum = cnt
        
    minimum = min([minimum, cnt]) 
    cnt = 0

print(minimum)

Submission status: Accepted

Solution code:
n = int(input())
l  = list(map(int,input().split()))
ave=  sum(l)//n
tol = 0
toa = 0
for i in l:
  tol += (i-ave)**2
for i in l:
  toa += (i-(ave+1))**2
print(min(tol,toa))

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
X = iil()
ti = 100*100*100
for i in range(1,101):
    cal = 0
    for item in X:
        cal += (item-i)**2
    ti = min(cal,ti)

print(ti)

Submission status: Accepted

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

for p in range(1,101):
    total = 0
    for i in range(N):
        total += (X[i] - p) ** 2
    if p == 1:
        result = total
    elif total < result:
        result = total
print(result)

Submission status: Accepted

Solution code:
N = int(input())
X = [0]*N
sum = 0
P = 0
P1 = 0
T = 0
T1 = 0
X = [int(N) for N in input().split()]
for i in range(N):
    sum +=X[i]
P = int(sum/N)
P1 = int((sum/N)+1)
for i in range(N):
    T += (X[i]-P)*(X[i]-P)
    T1 += (X[i]-P1)*(X[i]-P1)
if T>T1:
    print(T1)
else:
    print(T)

Submission status: Accepted

Solution code:
n = int(input())
x = [int(a) for a in input().split()]
l = max(x) - min(x)

sho = []
for i in range(min(x), min(x)+l+1):
    something = 0
    for k in range(n):
        something += (abs(i - x[k]))**2
    sho.append(something)
print(min(sho))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
minLoss = 1e6
for i in range(1, 100):
  minLoss = min(minLoss, sum([(x - i)**2 for x in X]))
print(minLoss)

Submission status: Accepted

Solution code:
import math

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

sX = sum(X)
kouho1 = math.ceil(sX / N)
kouho2 = sX // N
kouho3 = math.floor(sX / N)


ans1, ans2, ans3 = 0, 0, 0
for p in X:
    ans1 += (p - kouho1) ** 2
    ans2 += (p - kouho2) ** 2
    ans3 += (p - kouho3) ** 2

print(min(ans1, ans2, ans3))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
x = [int(i) for i in input().split()]
m = sys.maxsize
for i in range(min(x), max(x) + 1):
    sum = 0
    for j in x: sum += (j - i) ** 2
    if sum < m: m = sum
print(m)

Submission status: Accepted

Solution code:
N = input()
Xi = list(map(int,input().split()))
num = 0
temp = []
for P in range(min(Xi),max(Xi)+1):
    num = 0
    for X in Xi:
        num += (X - P)**2
    temp.append(num)
print(min(temp))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
total = 0
mini = 100**9
for p in range(1,101):
  for i in A:
    total += (i-p)**2
  if total < mini:
    mini = total
  total = 0
print(mini)

Submission status: Accepted

Solution code:
n,*x=map(int,open(0).read().split());print(sum((i-round(sum(x)/n))**2for i in x))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
p = 10000000
for i in range(100):
    pi = 0
    for j in range(n):
        pi += (x[j] - (i + 1))**2
    if pi < p:
        p = pi
    else:
        break
        # p[i] += (x[j]-(i+1))**2
print(p)

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
p = 10000000
for i in range(100):
    pi = 0
    for j in range(n):
        pi += (x[j] - (i + 1))**2
    if pi < p:
        p = pi
    # else:
    #     break
        # p[i] += (x[j]-(i+1))**2
print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def solve():
    readline=sys.stdin.buffer.readline
    int(readline())
    x=list(map(int,readline().split()))
    x.sort()
    mt=10**10
    for i in range(x[0],x[-1]+1):
        t=0
        for v in x:
            t+=(v-i)**2
        mt=min(mt,t)
    print(mt)
if __name__ == '__main__':
    solve()

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

mn=10**18
#for p in range(min(X),max(X)+1):
for p in range(1,101):
    sm=0
    for x in X:
        sm+=(x-p)**2
    #print(p,sm)
    mn=min(sm,mn)
print(mn)
'''

Submission status: Accepted

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

mn=10**18
#for p in range(min(X),max(X)+1):
for p in range(1,101):
    sm=0
    for x in X:
        sm+=(x-p)**2
    #print(p,sm)
    mn=min(sm,mn)
print(mn)

Submission status: Accepted

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

mn=10**18
#for p in range(min(X),max(X)+1):
for p in range(1,101):
    sm=0
    for x in X:
        sm+=((x-p)**2)
    #print(p,sm)
    mn=min(sm,mn)
print(mn)

Submission status: Accepted

Solution code:
N=int(input())
X=[int(i) for i in input().split(" ")]
sp=lambda P:sum([(Xi-P)**2 for Xi in X])
print(min([sp(p) for p in range(0,102)]))

Submission status: Accepted

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

ave = sum(x)/n
ans1 = sum([(i - int(ave))**2 for i in x])
ans2 = sum([(i - int(ave + 1))**2 for i in x])

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
n=int(input())
M=list(map(int,input().split()))
m=sorted(M)
l=[]
for p in range(m[0],m[n-1]+1):
  L=0
  for i in range(n):
    L+=(m[i]-p)**2
  l.append(L)
print(min(l))

Submission status: Accepted

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

d = [0] * 100

for i in range(100):
  for j in x:
    d[i] += ( j - ( i + 1 )) ** 2

print( min( d ) )

Submission status: Accepted

Solution code:
import sys

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


def cal(number):
    an = 0
    for X in Xn:
        an += (X - number)**2
    return an

ans = sys.maxsize
for i in range(min(Xn), max(Xn)+1, 1):
    ans = min(ans, cal(i))

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

mins = x.min()
maxs = x.max()

dis = np.inf
for p in range(mins, maxs+1):
  temp = np.sum((x - p) ** 2)
  if dis > temp:
    dis = temp
    
print(dis)

Submission status: Accepted

Solution code:
N = int(input())

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

X.sort()
min_cost = float('inf')
sum_cost = 0
m = X[N-1]
for i  in range(m):
  i += 1
  for xi in X:
    sum_cost +=  (i-xi)**2
  if min_cost > sum_cost:
    min_cost = sum_cost
  sum_cost = 0
    
print(int(min_cost))

Submission status: Accepted

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

l = []

for i in range(min(x),max(x)+1):
    element = 0
    for j in range(n):
        element += (x[j] - i) * (x[j] - i)
    l.append(element)

print(min(l))

Submission status: Accepted

Solution code:

import math


def calc_energy_sum(x_list, p):
    energy_list = [(x - p) ** 2 for x in x_list]
    energy_sum = sum(energy_list)
    return energy_sum


N = int(input())
X_list = [int(s) for s in input().split()]

p = sum(X_list) / len(X_list)
# print(p)

p_l = math.floor(p)
# print(p_l)
energy_sum_l = calc_energy_sum(X_list, p_l)
# print(energy_sum_l)

p_u = math.ceil(p)
# print(p_u)
energy_sum_u = calc_energy_sum(X_list, p_u)
# print(energy_sum_u)

energy_sum = min([energy_sum_l, energy_sum_u])
print(energy_sum)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ls =list(map(int, input().split()))
t = len(ls)
a=[]
b=[]
for i in range(1,101):
    for j in range(t):
        p = (ls[j]-i)**2
        a.append(p)
    b.append(sum(a))
    a=[]
b.sort()
print(b[0])

Submission status: Accepted

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

ans = float("inf")
for P in range(1, 100+1):
  power_sum = 0
  for i in range(N):
    power_sum += (X[i]-P)**2
  if power_sum < ans:
    ans = power_sum

print(ans)

Submission status: Accepted

Solution code:
min_hp = 10 ** 7
n = int(input())
xs = list(map(int, input().split()))
for i in range(1, 101):
    min_hp = min(sum((x-i)**2 for x in xs), min_hp)
print(min_hp)

Submission status: Accepted

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

min_dis = 1e10
for p in range(min(x),max(x)+1):
    dis = 0
    for y in x:
        dis += (p-y)*(p-y)
    min_dis = min(dis, min_dis)
print(min_dis)

Submission status: Accepted

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

for i in range(100):
    s = 0
    for j in range(N):
        s += (X[j] - (i + 1)) ** 2
    ans = min(ans, s)
    
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
x = list(map(int, input().split()))
p = round(sum(x) / len(x))
x_arr = np.array(x)
print(sum((x_arr - p) ** 2))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
HP1 = 0
HP2 = 0
P1 = sum(X) // N
P2 = sum(X) // N + 1
# s = round(sum(X)/len(X))
for Xi in X:
    HP1 = HP1 + (Xi - P1) ** 2
    HP2 = HP2 + (Xi - P2) ** 2

print(min(HP1, HP2))

Submission status: Accepted

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

mn = 1000000
for p in range(1, 100):
  sum = 0
  for q in x:
    sum += (q-p)**2
  mn = min(mn, sum)

print(mn)