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:
import sys
from io import StringIO
import unittest


def resolve():
    n = int(input())
    # a, b = map(int, input().split())
    x = list(map(int, input().split()))
    ans = []

    for i in range(1, 101, 1):
        ans.append(
            sum([(i - xx) ** 2 for xx in x])
        )

    print(min(ans))

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

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

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


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

Submission status: Accepted

Solution code:
import math

def main():
  N = int(input())
 # X = [int(input().split()) for _ in range(N)]
  X = list(map(int,input().split()))
  
  #住民がいる座標の最小値から最大値までで検討する
  start = min(X) 
  end = max(X)
  
  
  power = list()
  ans = 10000000000
  
  for i in range(start, end + 1):
    for n in X:
      power.append((i - n)**2)
    if ans > sum(power):
      ans = sum(power)
      
    power.clear()
    
  print(ans)
  
main()

Submission status: Accepted

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

out = 10000 * n
for i in range(max(X) + 1):
    c = 0
    for j in range(n):
        c += (X[j] - i) ** 2
    out = min(out, c)
print(out)

Submission status: Accepted

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

best = 10 ** 9
minx, maxx = min(X), max(X)
for p in range(minx, maxx + 1):
    tmp = 0
    for i in range(N):
        tmp += (X[i] - p) ** 2
    best = min(best, tmp)

print(best)

Submission status: Accepted

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

ans = 10 ** 9
for P in range(X[0], X[N - 1] + 1):
  cons_pow = sum(map(lambda x: pow(x - P, 2), X))
  if cons_pow < ans:
    ans = cons_pow
    
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
X = np.array(list(map(int,input().split())))
ans_sum = float('inf')
for i in range(1,101):
    ans_sum=min(ans_sum,sum((X-i)**2))
print(ans_sum)

Submission status: Accepted

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

dis = [0] * 101
point = X[0]

for i in range(101):
  for j in range(N):
    dis[i] += (X[j] - i) ** 2

print(min(dis))

Submission status: Accepted

Solution code:
# c-Rally
N = int(input())
X = list(map(int,input().split()))
sum = 0
stamina = 0
xmin = min(X)
xmax = max(X)
for i in range(xmin,xmax+1):
    for j in range(N):
        sum += (X[j]-i)**2
    if i == xmin:
        stamina = sum
    if stamina > sum:
        stamina = sum
    sum = 0
print(stamina)

Submission status: Accepted

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

center = sum(x)//n


ans1 = 0
ans2 = 0

for i in range(n):
    ans1 += (x[i]-center)**2
    ans2 += (x[i]-center-1)**2

print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

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

X_mean=sum(X)//N
a=b=0
for i in X:
    a+=(i-X_mean)**2
    b+=(i-(X_mean+1))**2

if a>b:
    print(b)
else:
    print(a)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

result = min([sum((x-p)**2 for x in X) for p in range(1, 101)])
print(result)

Submission status: Accepted

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re


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

ans = 1000000
for i in range(1,100+1):
    sum = 0
    for j in range(len(X)):
        sum += ( X[j] - i ) ** 2

    if sum < ans:
        ans = sum

print(ans)

Submission status: Accepted

Solution code:
from decimal import Decimal, ROUND_HALF_UP
N = int(input())
Xlist = list(map(int, input().split()))
sumX = 0
for x in Xlist:
  sumX += x
average = Decimal(sumX/N).quantize(Decimal('1'),ROUND_HALF_UP)
answer = 0
for x in Xlist:
  answer += (x-average)**2
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

t= n* 10000

for i in range(1, 101):
    a = sum([(j-i)**2 for j in xn])

    if t > a:
        t=a


print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
result=[]       
for i in range(0,102):
  count=0
  for j in range(n):
    count+=(a[j]-i)**2
  result.append(count)
print(min(result))

Submission status: Accepted

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

lst = []
for i in range(1,101):
    wa = 0
    for x in xl:
        wa += (x-i)**2
    lst.append(wa)

print(min(lst))

Submission status: Accepted

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

M=10**10
for x in range(1,101):
    T=0
    for a in A:
        T+=(x-a)*(x-a)
    M=min(T,M)
print(M)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
m=10000000000
for p in range(1,100):
    total=0
    for i in range(n):
        total+=(x[i]-p)**2
    if total<m:
        m=total
print(m)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
X.sort()
p = X[0]
Cost = 0
MinCost = 0
for k in X:
    MinCost += (k-p)**2
while p <= X[N-1]:
    Cost = 0
    for i in X:
        Cost += (i-p)**2
    if Cost < MinCost:
        MinCost = Cost
    p += 1
    
print(MinCost)

Submission status: Accepted

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

# list_n = list(map(int , inpuut().split()))<Paste>

#n = input()
# list = [input() for i in range(N)

#list = [[i for i in range(N)] for _ in range(M)]

ans = float('inf')
N = int(input())
list_x = list(map(int, input().split()))

for x in range(1, 101):
    temp = 0
    for xi in list_x:
        temp += (x - xi) ** 2
    ans = min(ans, temp)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

N = int(input())
X = list(map(int, input().split()))
mean = sum(X) // N
res = min(calc(mean), calc(mean+1))
print(res)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    xn = list(map(int, input().split()))
    p = round(sum(xn) / len(xn))
    s = sum([(x - p) ** 2 for x in xn])
    print(s)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:

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

minX = min(X)
maxX = max(X)
if minX==maxX:
    print(0)
    quit()

HP = []
for p in range(minX, maxX):
    hp = 0
    for x in X:
        hp += (x-p)**2
    HP.append(hp)

print(min(HP))

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

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

n = ni()
x = na()

z = sum(x)
Z = z/n

p = round(Z)

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

Submission status: Accepted

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

Submission status: Accepted

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

X.sort()
Max = X[len(X)-1]

res=100000000
for i in range(Max+1):
    SUM=0
    for j in range(len(X)):
        SUM += (X[j] - i) ** 2
    res = min(res, SUM)

print(res)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    inlis = list(map(int, input().split()))
    inlis.sort()

    ans = 100 ** 6
    for i in range(1, 101):
        tmp = 0
        for j in range(len(inlis)):
            tmp += (inlis[j] - i ) ** 2
            if tmp > ans:
                break
        if tmp < ans:
            ans = tmp
    print(ans)
    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
x = list(map(int , input().split()))
m = sum(x)/n
m = round(m)
ans = sum((num-m)**2 for num in x)
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):
    dis_total = 0
    for x in X:
        dis = 0
        dis = (x-i)**2
        dis_total += dis
    if dis_total < ans:
        ans = dis_total
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 1000100010001
for i in range(100):
    dist = 0
    for j in x:
        dist += (j-i)**2
        
    ans = min(ans,dist)
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
X.sort()
L = X[0]
R = X[len(X) - 1]
# print(max)
sum = 0
s = []
for i in range(L, R + 1):
    for x in X:
        sum += (x - i) ** 2

    s.append(sum)
    sum = 0

print(min(s))

Submission status: Accepted

Solution code:
import numpy as np
import math

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

mean_num_1 = int(np.mean(X))
mean_num_2 = math.ceil(np.mean(X))

result_1 = 0
result_2 = 0
for i in X:
    result_1 += abs(mean_num_1 - i) ** 2
    result_2 += abs(mean_num_2 - i) ** 2
    
print(min(result_1, result_2))

Submission status: Accepted

Solution code:
n=int(input())
k=list(map(int,input().split()))
ap=float('inf')
for i in range(min(k),max(k)+1):
    ans=0
    for j in k:
        a=(j-i)**2
        ans+=a
    if ans<ap:
        ap=ans
print(ap)

Submission status: Accepted

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

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

min_hp = float("inf")
for i in range(min_x, max_x):
    hp = 0
    for x in X:
        hp += (x - i) ** 2
    if hp < min_hp:
        min_hp = hp

print(min_hp)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
M = max(X)
m = min(X)
ans = 10**6
for i in range(m,M+1) :
    p = list(map(lambda x : (x - i)**2 ,X))
    s = sum(p)
    ans = min(ans,s)
print(ans)

Submission status: Accepted

Solution code:
n, *d = map(int, open(0).read().split())

m = round(sum(d)/n)

print(sum(map(lambda x: (x-m)**2, d)))

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
ans=10**18 #最小値を求めるので初期化しておく
for i in range(1,101): #1<=P<=100の範囲について消費する体力の総和を計算
 tmp=0
 for num in arr:
   tmp+=(i-num)**2
 ans=min(ans,tmp) #消費する体力の総和の最小値が答えとなる
print(ans)

Submission status: Accepted

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

x.sort()

mean = sum(x)/n
med = int(n / 2)

if mean - int(mean) < 0.5:
    mean = int(mean)
elif mean - int(mean) > 0.5:
    mean = int(mean) + 1
else:
    if n % 2 == 0:
        if (x[med-1] + x[med])/2 <= mean:
            mean = int(mean)
        else:
            mean = int(mean) + 1
    else:
        if x[med] <= mean:
            mean = int(mean)
        else:
            mean = int(mean) + 1
sum = 0

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

print(sum)

Submission status: Accepted

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

X_mean = round(mean(X))
length = 0
for iter in range(len(X)):
    length += (X_mean - X[iter])**2

print(length)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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


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

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

print(sum((x-P)**2 for x in X))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
	N = int(input())
	X = list(map(int, input().split()))
	P = [p for p in range(min(X),max(X)+1)]
	m_list = [sum([(x-p)**2 for x in X]) for p in P] 
	print(min(m_list))
  
if __name__=="__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

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

minP=float('inf')

for p in range(min(X),max(X)+1):
    P=0
    for x in X:
        P+=(x-p)**2
        if minP<P:
            break
    if P<minP:
        minP=P

print(minP)

Submission status: Accepted

Solution code:
N= int(input())
input_data = [int(x) for x in input().split()]
mini = min(input_data)
length=max(input_data)-mini
zahyo = [n-mini for n in input_data]
energy=[0 for i in range(length+1)]
for i in range(length+1):
    for j in range(N):
        energy[i]=energy[i]+(i-zahyo[j])**2
print(min(energy))

Submission status: Accepted

Solution code:
N = int(input())

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


ans = 100**100

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

mi = min(X)
ma = max(X)
for i in range(mi, ma+1):
  temp = 0
  for j in X:
    temp += (j-i) ** 2
  l.append(temp)
  
print(min(l))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
def main():
    n, *x = map(int, read().split())
    r = float('inf')
    for i1 in range(1, 101):
        rt = 0
        for xe in x:
            rt += (xe - i1)**2
        r = min(r, rt)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

hp = [0 for i in range(101)]
for i in range(101):
    for j, x in enumerate(X):
        hp[i] = hp[i] + (x-(i+1))**2

print(min(hp))

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())

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

q = np.round(np.sum(xs) / n)

ans = np.sum((xs - q)**2, dtype=np.int32)

print(ans)

Submission status: Accepted

Solution code:
import math

N = input()
xs = [int(i) for i in input().split()]
p = round(sum(xs)/len(xs))

print(int(sum(math.pow(x-p, 2) for x in xs)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def calc_cost(arr, choice):
    ans = 0
    for num in arr:
        ans += (num - choice) * (num - choice)
    return ans

def main():
    N = int(raw_input())
    
    arr = [int(x) for x in raw_input().split()]
    
    avg = sum(arr) / N
    
    ans = min(calc_cost(arr, avg+1), calc_cost(arr, avg-1), calc_cost(arr, avg))
    
    print(ans)
    

main()


"""
#include <bits/stdc++.h>
using namespace std;

using ll = long long; 
/*

2
1 4


*/
int calc_cost(vector<int> arr, int choice) {
    int ans = 0;
    for (int num : arr) {
        ans += (num - choice) * (num - choice);
    }
    return ans;
}

int main() {
    int N;
    
    scanf("%d", &N);
    
    vector<int> arr(N);
    
    int total = 0;
    
    for (int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
        total += arr[i];
    }
    
    int avg = total / N;
    
    /*
    sort(arr.begin(), arr.end());
    
    int med = arr[N/2];
    
    cout << med << endl;
    
    int ans = 0;
    
    for (int n : arr) {
        ans += (n - med) * (n - med);
    }
    */
    
    int ans = min({calc_cost(arr, avg-1), calc_cost(arr, avg), calc_cost(arr, avg+1)});
    
    
    printf("%d\n", ans);
	
	return 0;
}
"""

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
P=[0]*100

for p in range(1,101):
  for i in range(N):
    P[p-1]+=(X[i]-p)**2
print(min(P))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys

n = int(input())
xs = list(map(int, input().split(' ')))
xs.sort()
x_min = xs[0]
x_max = xs[-1]
min_power = sys.maxsize

for i in range(x_min, x_max + 1):
    power = sum([(x - i) ** 2 for x in xs])
    min_power = min(min_power, power)

print(min_power)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = [list(map(int, input().split()))]
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())
    n = int(input())
    x = list(map(int, input().split()))

    ans = [0 for i in range(101)]

    for i in range(1, 101):
        for xin in x:
            ans[i] += pow(xin - i, 2)

    ans = ans[1:]
    print(min(ans))


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2
1 4"""
        output = """5"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """7
14 14 2 13 56 2 37"""
        output = """2354"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Accepted

Solution code:
import math
n = int(input())
x = list(map(int, input().split()))
mu_floor = math.floor(sum(x)/len(x))
mu_ceil = math.ceil(sum(x)/len(x))
x_floor = list(map(lambda i:(i-mu_floor)**2, x))
x_ceil = list(map(lambda i:(i-mu_ceil)**2, x))
ans = min(sum(x_floor),sum(x_ceil))
print(ans)

Submission status: Accepted

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

ans = 10**18
for i in range(0,101):
    curr_sum = 0
    for x in xl:
        curr_sum += (i-x)*(i-x)
    ans = min(ans,curr_sum)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
li=list(map(int,input().split()))
check=[]
for i in range(103):
  all=0
  for k in li:
    all+=(i-k)**2
  check.append(all)
  
print(min(check))

Submission status: Accepted

Solution code:
def main():
    num = int(input())
    l = list(map(int, input().split()))
    l.sort()

    ans_list = []

    for i in range(101):
        if i == 0:
            i = i + 1
        sum = 0
        for x in l:
            sum = sum + ((x - i) * (x - i))
        ans_list.append(sum)
    
    ans_list.sort()
    print(ans_list[0])


main()

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N = I()
    X = LI()
    energy = [0 for _ in range(1,100)]
    for p in range(1,100):
        for x in X:
            energy[p-1] += (x-p)**2
    print(min(energy))

main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy

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

ave = numpy.average(X)

if 0 <= (ave % 1) < 0.5:
    plot = int(ave)
else:
    plot = int(ave) + 1

ans = 0
for i in X:
    ans += (i - plot) ** 2

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
lists = list(input().split())
ave_sum = 0
for i in lists:
  ave_sum = ave_sum + int(i)
ave = round(ave_sum / N)
nijyo = 0
for i in lists:
  nijyo = nijyo + (int(i) - ave) ** 2
print(str(nijyo))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
ans = 10000000000000000000000
for i in range(1,101):
    tmp = 0
    for j in x:
        tmp += (i - j)**2
    if tmp < ans:
        ans = tmp

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

mn=10**7
for i in range(1,101):
    hp=0
    for k in range(n):
        hp+=(x[k]-i)**2
    if hp<mn:
        mn=hp

print(mn)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
#print(N)
#print(X)
ans = 10**10
for x in range(1,101):
  sum = 0
  for n in range(N):
    sum += (X[n]-x)**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):
    temp = 0
    for j in range(n):
        temp += (x[j]-i)**2
    ans = min(ans,temp)
if ans == 10**10:
        print(0)
        exit()
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
xmin = min(x)
xmax = max(x)
hp = 10e10
for p in range(xmin, xmax+1):
    temp = 0
    for xi in x:
        temp += (xi-p)*(xi-p)
    hp = min(temp, hp)
print(hp)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
def D(x,a):
	ans=0
	for i in range(len(a)):
		ans+=(x-a[i])**2
	return ans
for i in range(0,101):
	if D(i,X)<D(i+1,X):
		print(D(i,X))
		break

Submission status: Accepted

Solution code:
#156
def main():
    N = int(input())
    X = list(map(int,input().split()))
    sum_x = sum(X)
    sum_xsqrt = sum([x**2 for x in X])
    
    p = sum(X)//N
    candidate = [N*p**2-2*p*sum_x+sum_xsqrt,N*(p+1)**2-2*(p+1)*sum_x+sum_xsqrt]
    print(min(candidate))
main()

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
s = sum(X)
c = 1000000
P = 0
m = min(X)
M = max(X)
for i in range(m, M+1):
  a = abs(s - N*i)
  if a < c:
    c = a
    P = i
ans = 0
for i in range(N):
  ans += (X[i] - P)**2
print(ans)

Submission status: Accepted

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

MinL = min(L)
MaxL = max(L)

chobani = 10000000
set = 0

for i in range (MinL, MaxL+1):
	set = 0
	for j in range (0, N):
		set+=(L[j]-i)**2
	if set < chobani:
		chobani = set

print(chobani)

Submission status: Accepted

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

Submission status: Accepted

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

point = np.rint(np.average(X))
print(int(np.sum((point - X)**2)))

Submission status: Accepted

Solution code:
import numpy as np
N   = int(input())
X   = np.array([int(x) for x in input().split()])
Pos = np.around(np.mean(X))
Min = int(sum(pow(X-Pos,2)))
print(Min)

Submission status: Accepted

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

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

print(min(ans))

Submission status: Accepted

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

def get_dist(X,p):
    sum_=0
    for x in X:
        sum_+=(x-p)**(2)
        
    return sum_

dist_min=10**10
for p in range(0,101):
    dist=get_dist(X,p)
    if dist_min>dist:
        dist_min=dist
print(dist_min)

Submission status: Accepted

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

ans=10**9
i=1
while i<=100:
    j=0
    count=0
    while j<N:
        count+=(i-X[j])**2
        j+=1
    ans=min(ans,count)
    i+=1

print(ans)

Submission status: Accepted

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

import numpy as np

def main():
    n = int(input())
    l = list(map(int,input().split()))
    arr = np.array(l)

    suml = []
    for i in range(1, 101):
        gokei = sum((arr-i)**2)
        suml.append(int(gokei))
    
    print(min(suml))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Ans = []
for x in range(1,101):
    ans = 0
    for y in range(N):
        ans += (X[y]-x)**2
    Ans.append(ans)

print(min(Ans))

Submission status: Accepted

Solution code:
import heapq as hp
n = int(input())
X = list(map(int,input().split()))
min1=[]
a=min(X)
b=max(X)
for i in range(a,b+1):
    total=[]
    for j in X:
        total.append(abs(j-i)**2)
    else:
        ans=sum(total)
        hp.heappush(min1,ans)
print(hp.heappop(min1))

Submission status: Accepted

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

p = round(sum(X)/N)
result = 0
for x in X:
    result += (x - p)**2

print(result)

Submission status: Accepted

Solution code:
import statistics

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

a = round(statistics.mean(x))
sums = 0
for i in x:
    sums += (i - a) ** 2
print(sums)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input().strip())
    Xs = list(map(int, input().strip().split(' ')))
    p = 0
    ans = 0
    p = round(sum(Xs)/ N)
    for i in Xs:
        ans = ans + ((p - i) ** 2)
    print(ans)
resolve()

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

answer = np.inf
for p in range(100):
    a = 0
    for x in X:
        a += (x - p) ** 2
    if answer > a:
        answer = a
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N = int(input())
X = list(map(int, input().split()))
X = sorted(X)
ans = 10**9+7
for i in range(1,100):
    tmp = 0
    for j in X:
        tmp += (j-i)**2
    ans = min(ans,tmp)
print(ans)