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, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
X = LIST()

a = sum(X) / N
ans1 = 0
ans2 = 0

big = int(a) + 1
small = int(a)
for i in range(N):
    ans1 += (X[i] - big) ** 2
    ans2 += (X[i] - small) ** 2
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
N=int(input())

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

minn=1e99
a=max(x_list)

for i in range(1,a+1):
    sumn=0
    for x in x_list:
        sumn+=(x-i)**2
    
    if sumn < minn :
        minn=sumn


print(minn)

Submission status: Accepted

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

ansm = 10 ** 7

for i in range(1, 101):
    s = 0
    for j in range(n):
        s += (x[j] - i) ** 2
    if s < ansm:
        ansm = s

print(ansm)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()


def main():
  n=I()
  l=LI()

  l.sort()
  # center1=(l[0]+l[-1]+1)//2
  # center2=(l[0]+l[-1]-1)//2

  avg=sum(l)/len(l)
  center1=-(-avg//1)
  center2=int(avg)

  ans1=0
  ans2=0
  for x in l:
    ans1+=(x-center1)**2
    ans2+=(x-center2)**2

  # print(center1,center2,ans1,ans2)
  return int(min(ans1,ans2))

# main()
print(main())

Submission status: Accepted

Solution code:
inputs = open(0).readlines()
n = int(inputs[0])
*X, = map(int, inputs[1].split())
p = round(sum(X) / n)
print(sum((x-p)**2 for x in X))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    xs = list(map(int, input().split()))
    min_score = 10000000000000000000000000000
    for p in range(1, 101):
        score = 0
        for x in xs:
            score += (x - p)**2
        min_score = min(score, min_score)

    print(min_score)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

for x in xarr:
  X += x
  
mean = X//n

ans1 = 0
ans2 = 0

for x in xarr:
  ans1 += (x - mean) * (x - mean)
  ans2 += (x - mean - 1) * (x - mean - 1)

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
N=int(input())
List=list(map(int,input().split())) # 1行N列・・・Nは任意


List.sort()
sumList = [] # List初期化

for i in range(1,100):
	sumList.append(0)
	for j in List:
		sumList[i - 1] += (j - i)**2

sumList.sort()

print(sumList[0])

Submission status: Accepted

Solution code:
import numpy as np


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


def calc(x):
    return x**2


ans = float('inf')
for P in range(max(X)+1):
    ans = min(ans, sum(map(calc, X - np.array([P] * N))))
print(ans)

Submission status: Accepted

Solution code:
import math

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

sum_x = sum(x)
avg_x = sum_x / n

p = math.floor(avg_x + 0.5)

ans = sum((xi - p) ** 2  for xi in x)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = sorted(map(int, input().split()))
answer = float('inf')
for i in range(X[0], X[-1]+1):
    cost = 0
    for Xn in X:
        cost += (Xn - i)**2
    if answer > cost:
        answer = cost

print(answer)

Submission status: Accepted

Solution code:
import sys


def main(S):
    pass


if __name__ == '__main__':
    #n, r = map(int, input().split())
    n = int(input())
    x = list(map(int, input().split()))

    m = int(sum(x) / n)

    ans = 10000000000
    for i in range(4):
        tmp = 0
        for j in range(n):
            tmp += pow((x[j] - (m - 1 + i)), 2)
        ans = min(ans, tmp)

    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):
    tmp = 0
    for j in x:
        tmp += (j - i) ** 2
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

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


def solve(N: int, X: "List[int]"):
    result = 10 ** 9
    for p in range(1, 100 + 1):
        cost = 0
        for i in range(N):
            cost += (X[i] - p) ** 2

        result = min(result, cost)
    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

X.sort()
temp = 10**10
a = 0
for i in range(X[0], X[N-1]+1):
    a = 0
    for j in X:
        a += (j - i) ** 2
    if a < temp:
        temp = a

print(temp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

avg = 0
for i in x:
    avg += i
avg = round(avg/n)

result = 0
for i in x:
    result += math.pow(avg-i, 2)

print(int(result))

Submission status: Accepted

Solution code:
n = int(input())

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


total_ = 0
m = 100000000000000000000000000000000000

for i in range(100):
    for j in A:
        total_ += (j - i)**2
    if total_ < m:
        m = total_
    total_ = 0
print(m)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
x = np.array([int(i) for i in input().split(" ")])
a = np.mean(x)
if a % 1 >0.5:
    a = int(a//1) + 1
else:
    a = int(a//1)
print(np.sum((x-a)**2))

Submission status: Accepted

Solution code:
import collections

N=int(input())
X=list(map(int,input().split()))
X.sort(reverse=True)
max=X[0]
min=X[len(X)-1]
power=0
minpower=float("inf")
for i in range(min,max+1,1):
    for j in range(N):
        power=power+(i-X[j])*(i-X[j])

    if minpower>power:
        minpower=power
    power=0
print(minpower)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
mean1 = sum(x)//len(x)
mean2 = mean1+1
ans1 = 0
ans2 = 0
for num in x:
    ans1 += (num - mean1)**2
    ans2 += (num - mean2)**2
print(min(ans1,ans2))

Submission status: Accepted

Solution code:


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

def resolve():
    N=int(input())
    X=[int(i) for i in input().split()]
    mns=10**9
    for i in range(100):
        mns=min(mns,sum([cost(i,j) for j in X]))
    print(mns)






if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

mn = 1234567890

for i in range(111):
	res = 0;
	for e in a:
		res = res + (e - i)*(e - i)
	mn = min(mn, res)

print(mn)

Submission status: Accepted

Solution code:
n = int(input())

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

l.sort()

# print(max(l))
ans = 1001001001
for i in range(1, 101):
    tmp = 0
    for j in l:
        tmp += (j-i)**2
    ans = min(tmp, ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int,input().split()))
a = min(lis)
b = max(lis)
all_lis = []

for i in range(a,b+1):
    tmp = 0
    for l in lis:
        tmp += (l-i)**2
    all_lis.append(tmp)
print(min(all_lis))

Submission status: Accepted

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

def solve(N: int, X: "List[int]"):
    cost = []
    X = np.asarray(X)
    for p in range(101):
        cost.append(np.sum((X-p)**2))
    print(min(cost))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
X = read_int()

def solve():
    ans = float('INF')
    m = max(X)
    for i in range(1, m + 1):
        res = 0
        for x in X:
            res += (i - x) ** 2
        ans = min(res, ans)
    return ans

if __name__ == "__main__":
    print(solve())

Submission status: Accepted

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

ans = 1000000

for i in range(1, 101):
  cnt = 0
  for j in range(len(x)):
    cnt += (x[j]-i)**2
  if cnt < ans:
    ans = cnt
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

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

print(ans)

Submission status: Accepted

Solution code:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
X=many_int()

X_min=min(X)
X_max=max(X)

ans=0
mins=10**8
for i in range(X_min, X_max+1):
    now_min=0
    for x in X:
        now_min += (x-i)**2
    
    if now_min < mins:
        mins = now_min
        ans = i

print(mins)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X):
    ans = INF
    for i in range(1, 100):
        t = 0
        for x in X:
            t += (x-i)**2
        ans = min(ans, t)
    return ans


def main():
    N = read_int()
    X = read_int_n()
    print(slv(N, X))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = float("inf")
for i in range(100):
    temp = 0
    for xx in x:
        temp += (xx - i) ** 2

    ans = min(ans, temp)

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = 10**20

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
import numpy as np

# A = input()
# A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()

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

ans = 9999999999999
for p in range(1, max(X)+1):
    sum_ = 0
    for i, x in enumerate(X):
        sum_ += (x - p) ** 2

    if ans > sum_:
        ans = sum_

print(ans)

Submission status: Accepted

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

p = sum(lst)/n
p1 = int(p)
p2 = math.floor(p)
p3 = math.ceil(p)

res = []
tmp = 0
for i in range(n):
    tmp += (lst[i] - p1)**2
res.append(tmp)
tmp = 0
for i in range(n):
    tmp += (lst[i] - p2)**2
res.append(tmp)
tmp = 0
for i in range(n):
    tmp += (lst[i] - p3)**2
res.append(tmp)
print(min(res))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N=int(input())
X=list(map(int, input().split()))
ans=sum(X)/N
p1=math.ceil(ans)
p2=math.floor(ans)
s1=0
s2=0
for i in range(N):
    s1+=(X[i]-p1)**2
    s2+=(X[i]-p2)**2
print(min(s1, s2))

Submission status: Accepted

Solution code:
N = int(input())
X = sorted(list(map(int,input().split())))
ans = float("inf")
for e in range(min(X),max(X)+1):
    temp = 0
    for f in X:
        temp += (f-e)**2
    ans = min(ans,temp)
print(ans)

Submission status: Accepted

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

p_ave1 = sum(positions) // n
p_ave2 = sum(positions) // n + 1

stamina1 = sum([(p - p_ave1) * (p - p_ave1) for p in positions])
stamina2 = sum([(p - p_ave2) * (p - p_ave2) for p in positions])

print(min(stamina1, stamina2))

Submission status: Accepted

Solution code:
N = input()
n = int(N)
X = input().split()

wa = 0
wa2 = 0
for i in range(n):
    X[i] = int(X[i])
    wa = wa + X[i]
    wa2 = wa2 + X[i]*X[i]
    
y = round(wa/n)

print( wa2 - 2*y*wa + n*y*y )

Submission status: Accepted

Solution code:
#s = input()
n = int(input())
#n,m = map(int,input().split())
lst1 = list(map(int,input().split()))
ans = 10**9
for i in range(1,101):
    res = 0
    for j in lst1:
        res += (j-i)**2
    ans = min(res,ans)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

ans = 10 ** 18 + 100
for p in range(1, 101):
    ans = min(ans, sum((X - p) ** 2))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
xs = [int(x) for x in input().split()]
mn,mx = min(xs), max(xs)
mv = n * (mx - mn) ** 2
for i in range(mn, mx + 1):
    mv = min(mv, sum((xs[j] - i) ** 2 for j in range(n)))
print(mv)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
cost = 10**9
for i in range(100):
  t = sum([(j-i)**2 for j in x])
  if t < cost:
    cost = t
print(cost)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
ans = 0
num = sum(X) // N
if (sum(X) / N - sum(X) // N >= 0.5): num += 1
for i in range(len(X)):
    ans += (X[i] - num) ** 2
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
m = min(x)
M = max(x)
ans=10000000000
for i in range(m,M+1):
    sum=0
    for j in x:
        sum+=(j-i)**2
    if sum < ans:
        ans = sum
print(ans)

Submission status: Accepted

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

avg1=sum(x)//n
avg2=avg1+1

cnt1=0
cnt2=0
for i in range(n):
    cnt1+=(x[i]-avg1)**2
    cnt2+=(x[i]-avg2)**2
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int, input().split()))
if sum(l)%n==0:
  ct=0
  a=sum(l)//n
  for i in l:
      ct+=(i-a)**2
  print(ct)
else:
  ct1,ct2=0,0
  a=sum(l)//n
  b=sum(l)//n +1
  for i in l:
      ct1+=(i-a)**2
      ct2+=(i-b)**2
  print(min(ct1,ct2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
ans=100000000
for i in range(-100,101):
    cnt=0
    for j in X:
        cnt+=pow(j-i,2)
    ans=min(cnt,ans)
print(ans)

Submission status: Accepted

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

ans = float("inf")

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
ans=100000000000000
for i in range(1,101):
    temp=0
    for j in range(len(arr)):
        xx=(arr[j]-i)
        yy=xx*xx 
        temp+=yy 
    ans=min(ans,temp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)

# from collections import defaultdict
# d = defaultdict(list)

# from itertools import combinations
# comb = combinations(range(N), 2)

# 累積和
# from itertools import accumulate
# _list = list(accumulate(a_list)

# from functools import lru_cache
# @lru_cache(maxsize=None)
# def setUp(self):
#     dp.cache_clear()


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    x_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    _min = 10**10
    for p in range(min(x_list), max(x_list) + 1):
        _min = min(_min, sum([(x - p)**2 for x in x_list]))

    print(_min)


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


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)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 10**10
for i in range(1, l + 1):
    temp = 0
    for x in X:
        temp += (x - i)**2
    ans = min(ans, temp)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
li = []
for i in range(101):
    count = 0
    for j in range(len(X)):
        count += abs(X[j] - i) ** 2
    li.append(count)
print(min(li))

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

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

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

print(ans)

Submission status: Accepted

Solution code:
from statistics import mean
def main():
    N = int(input())
    X = list(map(int, input().split()))
    P = int(mean(X) + 0.5)
    d = 0
    for n in range(N):
        d += (X[n] - P)**2
    print(d)
 
main()

Submission status: Accepted

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

ans = 10 ** 8

for i in range(1, 101):
    tmp = 0
    for j in range(len(x)):
        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()))

S_min = float("inf")

for i in range(1, 101):
    S = 0
    for j in range(n):
        S += (x[j] - i) ** 2
    if S < S_min:
        S_min = S

print(S_min)

Submission status: Accepted

Solution code:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    x = list(map(int, input().split()))
    ans = 0
    t = sum(x) // n
    for i in range(n):
        ans += (x[i] - t) * (x[i] - t)
    a = ans
    ans = 0
    t += 1
    for i in range(n):
        ans += (x[i] - t) * (x[i] - t)
    print(min(ans, a))

        
   

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

ans = INF
for x in range(1, 101):
    cur = 0
    for a in A:
        cur += abs(a - x)**2
    ans = min(ans, cur)
print(ans)

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    x=list(map(int,input().split()))
    ans = [0] * 100
    m=10**8
    for i in range(1,101):
        for j,aa in enumerate(x):
            ans[i-1] += (aa-i)**2
        m=min(m,ans[i-1])
    print(m)
if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

val_min = 10000000000000000000000

for i in range(1, 101):
    val = 0
    for item in x_list:
        val += (item - i) ** 2
    if val < val_min:
        val_min = val

print(val_min)

Submission status: Accepted

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

for i in range(0,102):
    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(raw_input())
X = map(float, raw_input().split())

P = 0.0
for item in X:
    P = P + item
P = P/N

P1 = int(P)
P2 = int(P)+1

ans1 = 0.0
for item in X:
    ans1 = ans1 + (P1-item)**2

ans2 = 0.0
for item in X:
    ans2 = ans2 + (P2-item)**2


print int(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
inf = 1000000000

def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    num_list.sort()

    ans = inf

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
l=1000000
for i in range(1,101):
    s=0
    for j in a:
        s+=(j-i)**2
    if s<l:
        l=s
print(l)

Submission status: Accepted

Solution code:
import math

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

s = sum(x)

ans = 0
a = round(s/n)

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

print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8

n = int(input())

data = list(map(int, input().split()))
minv = 100000000000000000
for x in range(0, 101):
    sumv = 0
    for v in data:
        sumv += (v - x) ** 2
    minv = min(minv, sumv)
    
print(minv)

Submission status: Accepted

Solution code:
import sys
import math
import collections
n = int(input())
#n, k = map(int, input().split())
#s = input()
x = list(map(int, input().split()))

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

  if p < ans:
    ans = p

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

mini = 10**18
for i in range(1, 101):
    current = 0
    for j in range(n):
        current += (i - x[j])**2
    mini = min(mini, current)

print(mini)

Submission status: Accepted

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

ans=float('inf')

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


def main():
    n = int(input())
    x = list(map(int, input().split()))
    ans = float('inf')

    for p in range(-100, 201):
        summed = 0

        for xi in x:
            summed += (xi - p) ** 2

        ans = min(ans, summed)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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