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())
a=list(map(int,input().split()))
ans=pow(10,12)
for i in range(0,101):
    cnt=0
    for x in a:
        cnt += pow(x-i,2)
    ans=min(cnt,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


tairyoku = []

for i in range(100):
    temp = 0
    for j in range(n):

        temp = (x[j]-(i+1))**2 + temp

    tairyoku.append(temp)

print(min(tairyoku))

Submission status: Accepted

Solution code:
N=int(input())
if N==1:
    print(0)
else:
    X=[int(x) for x in input().split(" ")]
    cons=lambda P:sum([(x-P)**2 for x in X])
    print(min([cons(P) for P in range(0,102)]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
X_sum=[]
for P in range(100):
    count=0
    for i in range(N):
        count=(X[i]-P)**2+count
    X_sum.append(count)
print(min(X_sum))

Submission status: Accepted

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

def calc_sum_of_power(N, coord):
    spot = round(sum(coord)/N)
    return sum([(x - spot)**2 for x in coord])

def main():
    N = int(input())
    coord = list(map(int, input().split()))
    print(calc_sum_of_power(N, coord))

if __name__ == "__main__":
    try:
        assert calc_sum_of_power(2, [1, 4]) == 5
        assert calc_sum_of_power(7, [14, 14, 2, 13, 56, 2, 37]) == 2354
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()

Submission status: Accepted

Solution code:
N = int(input())
X = [int(x) for x in input().split()]
result = -1
for i in range(min(X),max(X)+1):
  total = 0
  for n in range(N):
    total += (X[n]-i)**2
  if result==-1:
    result=total
  if total<result:
    result=total
print(result)

Submission status: Accepted

Solution code:
import math
N = int(input())
X = list(map(int,input().split()))
mean = round(sum(X)/N)
var = sum([(x - mean) ** 2 for x in X])
print(var)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
min = 1000000
for a in range(1,101):
    sum = 0
    for i in range(n):
        sum += (x[i]-a)**2
    if min > sum:
        min = sum
print(min)

Submission status: Accepted

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

for p in range(1, 101):
    phy = 0
    for xi in x:
        phy += (xi - p) ** 2
    phy_list.append(phy)

print(min(phy_list))

Submission status: Accepted

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

x_mean = sum(x)/n
p1 = int(x_mean)
p2 = p1 + 1

if abs(x_mean - p1) > abs(x_mean - p2):
    p = p2
else:
    p = p1

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

Submission status: Accepted

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

f = 10**100

for p in range(min(x), max(x) + 1):
    l = [(x[i] - p)**2 for i in range(n)]
    f1 = sum(l)
    f = min(f, f1)

print(f)

Submission status: Accepted

Solution code:
n=int(input())
jumin=list(map(int,input().split()))
#print(jumin)
sum=0
energy=[]
#print(jumin)

for i in range(1,101):
    for j in jumin:
        sum+=(j-i)**2
        #print(j-i)
        #print(sum)
    energy.append(sum)
    sum=0
    #print(energy)
#print(min(energy))
min=min(energy)
print(min)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    X = list(map(int, input().split()))
    ans = float('inf')
    for p in range(1, 100 + 1):
        tmp = 0
        for x in X:
            tmp += (x-p)**2
        ans = min(ans, tmp)
    return ans

print(solve())

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
x = np.array(list(map(int,input().split())))
mi = 99999999
for i in range(1,max(x)+1):
    d = (x - i)**2
    mi = min(mi,sum(d))
print(mi)

Submission status: Accepted

Solution code:
import numpy as np

def calc(X, p):
  ans = 0
  for x in X:
    ans += (x-p)**2   
  print(int(ans))
  
n = int(input())
X = list(map(int, input().split()))

p = np.mean(X)
p1 = np.floor(p)
p2 = np.ceil(p)

if p <= p1 + 0.5:
  calc(X, p1)
else:
  calc(X, p2)

Submission status: Accepted

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

X=[int(n) for n in X]

S=0
for x in X:
    S+=x

P=round(S/N)

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

print(V)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
 
a = 10**10
for i in range(1, 101):
    b = 0
    for x in X:
        b += (x - i) ** 2
    if a > b:
        a = b
print(a)

Submission status: Accepted

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

ans_li=list()
ans=0
for i in range(101):
  for p in range(n):
    x=(li[p]-i)**2
    ans+=x
    if p==n-1:
      ans_li+=[ans]
      ans=0
    
  
  
  
print(min(ans_li))

Submission status: Accepted

Solution code:
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))
from functools import reduce;gcd=lambda*x:reduce(math.gcd,x);lcm=lambda*x:reduce(lambda x,y:(x*y)//gcd(x,y),x,1)
from collections import deque
Yes=lambda b:print("Yes"if b else"No");YES=lambda b:print("YES"if b else"NO")
is_even=lambda x:True if x%2==0 else False

def is_palindrome(s):
  n=len(s);b=True
  for i in range(int(0.5*n)):
    if s[i]!=s[n-i-1]:b=False
  return b

def main():
  n=aint();x=ints();p=sum(x)//n
  l1=[(x[i]-p)**2for i in range(n)];l2=[(x[i]-p-1)**2for i in range(n)];print(min(sum(l1),sum(l2)))
if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 1000000
for i in range(max(x)+1):
  l = 0
  for j in range(n):
    l += (x[j]-i)**2
  if ans > l:
    ans = l
    
print(ans)

Submission status: Accepted

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

a = 10**10
for i in range(1, 101):
    b = 0
    for x in X:
        b += (x - i) ** 2
    if a > b:
        a = b
print(a)

Submission status: Accepted

Solution code:
N = int (input())
X = list(map(int,input().split()))
S = [0] * 100
A = 10000 * N
for i in range(100):
    for j in range(N):
        S[i] += ((X[j]) - i)**2
    A = min(A,S[i])
print(A)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 1000000000
for i in range(1,101):
    cnt = 0
    for j in a:
        cnt += (j - i) * (j - i)
    if ans > cnt:
        ans = cnt
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
Xsorted = sorted(X)
Xmax = max(X)
Xmin = min(X)
cnt = 0
l = list()

for i in range(Xmin, Xmax + 1):
  for j in range(N):
    cnt += (i - X[j]) ** 2
  l.append(cnt)
  cnt = 0
print(min(l))

Submission status: Accepted

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

m = round(sum(x)/n)
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

X = input().split()
X2 = [0 for _ in range(N)]
for i in range(N):
    X[i]=int(X[i])
    X2[i]=int(X[i])**2
sigma_X = sum(X)
sigma_X2 = sum(X2)
ans = []
    
for P in range(101):
    ans.append(sigma_X2 + N*P**2 - 2*P*sigma_X)
    
print(min(ans))

Submission status: Accepted

Solution code:
n = int(input())
X = sorted(map(int,input().split()))
ans = 10**6

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

Submission status: Accepted

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

Submission status: Accepted

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

ave = sum(X) // len(X)

ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += (X[i] - ave)**2
ave += 1
for i in range(N):
    ans2 += (X[i] - ave)**2

print(min(ans1, ans2))

Submission status: Accepted

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

X.sort()
tairyoku = 0
HP = []
for p in range(100):
    
    for i in range(N):
        tairyoku += (X[i] - p)**2

    HP.append(tairyoku)
    tairyoku = 0

print(min(HP))

Submission status: Accepted

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

def main():
    *N, = map(int, open(0).read().split())
    X = N[1:]
    N = N[0]

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


main()

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
X = np.array(lr())
# Brute Force Attack
answer = 10 ** 6
for x in range(101):
    temp = ((X-x) ** 2).sum()
    if temp < answer:
        answer = temp

print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

cost = []
for p in range(-1000,1001):
    tmp = 0
    for i in xi:
        tmp += pow((p - i), 2)
    cost.append(tmp)

print(min(cost))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in range(max(x)):
    a = 0
    for j in range(n):
        a += (x[j]-i-1)**2
    if i == 0:
        ans += a
    else:
        ans = min(a, ans)

print(ans)

Submission status: Accepted

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

for i in range(100):
    sum = 0
    for j in range(len(x)):
        sum += (x[j] - i)**2
    if i == 0:
        ans = sum
    else:
        ans = min(ans, sum)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
xlist=list(map(int,input().split(" ")))
count=100000000000

for kaisai in range(101):
    sum=0
    for hito in xlist:
        sum+=(hito-kaisai)**2
    #print(sum)
    if sum<count:
        count=sum
print(count)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
s=[]
for i in range(max(a)+1):
  m=0  
  for j in range(0,len(a)):
    m+=(a[j]-i)**2
  s.append(m)
print(min(s))

Submission status: Accepted

Solution code:
def II(): return int(input())
def MI(): return map(int,input().split())
def LMI(): return list(map(int,input().split()))
def LIIN(n): return list(int(input()) for _ in range(n))
def LMIN(n): return [list(map(int, input().split())) for _ in range(n)]
def IS(): return input()
def MS(): return map(str,input().split())
def LMS(): return list(map(str,input().split()))
def LISN(n): return list(input() for _ in range(n))
def LMSN(n): return [input().split() for _ in range(n)]
MOD = 10**9+7
INF = 10**18

def main():
    n = II()
    x = LMI()
    a = sum(x) // len(x)
    a2 = a + 1
    print(min(sum([(i-a)**2 for i in x]),sum([(i-a2)**2 for i in x])))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
x=list(map(int, input().split()))
p=sum(x)/N
P=round(p)

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
X_min = min(X)
X_max = max(X)
min_sum = float('inf')
for i in range(X_min, X_max+1):
    sum = 0
    for j in X:
        sum += (j-i)**2
    min_sum = min(min_sum, sum)
print(min_sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(x) for x in input().rstrip().split()]
ave=sum(A)//len(A)
ans=0

if N/2<(sum(A)%len(A)):
  ave+=1

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

Submission status: Accepted

Solution code:
N = int(input())

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

ans = float('inf')

for i in range(100):
  tmp = 0
  for x in X:
    tmp += (x-i) ** 2

  ans = min(ans,tmp)

print(ans)

Submission status: Accepted

Solution code:
#-*- coding: utf-8 -*-
n = int(input())
a = list(map(int,input().split()))
ans = 100**3
for i in range(-1000,1001):
    sum = 0
    for j in range(n):
        sum += (a[j]-i)**2
    if ans > sum:
        ans = sum

print(ans)

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 x:
        temp+=(j-i)**2
    ans=min(ans,temp)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
s = sum(l)
middle = int(s/n + 0.5)
ans = 0
for i in range(n):
	ans += (l[i] - middle) * (l[i] - middle)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = input().split()
sumd = 0
for i in x:
  sumd += int(i)
p = int(sumd/n)+(sumd%n>=n/2)
sums = 0
for i in x:
  sums += (int(i)-p)*(int(i)-p)
print(sums)

Submission status: Accepted

Solution code:
import numpy as np

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

dis = 10000000
for p in range(1,101):
    total = 0
    for x in X:
        total += (x-p) ** 2
    dis = min(dis,total)

print(dis)

Submission status: Accepted

Solution code:
import numpy as np

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

sumlist = []
for i in range(1, max(X)+1):
    minus = np.array([i] * N)
    res = X - minus
    vlist = map(lambda x: x**2, res)
    sumlist.append(sum(vlist))

print(min(sumlist))

Submission status: Accepted

Solution code:
n = int(input())

x = [0] * n

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

x.sort()
sum = 0
min_sum = 100 * 10000
for i in list(range(x[0], x[-1] + 1)):
    sum = 0
    for j in x:
        sum += (j - i) * (j - i)
    if sum < min_sum:
        min_sum = sum
print(min_sum)

Submission status: Accepted

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

ans_list = [0] * (max(x_list)+1)

for j in range(1, max(x_list)+1):
    ans = 0
    for i in range(0, n):
        ans += (x_list[i] - j) ** 2
    ans_list[j] = ans

ans_list.remove(0)
print(min(ans_list))

Submission status: Accepted

Solution code:

def main():
  n = int(input())
  X = tuple(map(int, input().split(" ")))

  mx = max(X)
  mn = min(X)

  ans = float("inf")

  for p in range(mn, mx + 1):
    ans = min(ans, sum([(x - p) ** 2 for x in X]))

  print(ans)


main()

Submission status: Accepted

Solution code:
n,*x=map(int,open(0).read().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=min(ans,tmp)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

# check
ans = 0
for i in range(1, 101, 1):
    sub_life = sum([(j - i) ** 2 for j in X])

    if i == 1 or ans > sub_life:
        ans = sub_life

print(ans)

Submission status: Accepted

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

X.sort()
X_min = X[0]
X_max = X[N-1]

result = -1
total = 0
for P in range(X_min, X_max+1):
    for x in X:
        total = total + (x-P)**2
    if (total < result or result < 0):
        result = total
    elif (total > result):
        break
    total = 0
print(result)

Submission status: Accepted

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

cost_list = []

for p in range(min(zyunin_list), max(zyunin_list) + 1):
    cost = 0
    for zahyo in zyunin_list:
        cost += (zahyo - p) ** 2
    cost_list.append(cost)

print(min(cost_list))

Submission status: Accepted

Solution code:
n, *a = map(int,open(0).read().split())
x=sum(a)//n
b=0
for i in range(n):
  b += (a[i]-x)**2
c=0
for l in range(n):
  c+= (a[l]-(x+1))**2
print(min(b,c))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
x = list(map(int, input().split()))
t = []
for p in range(1, 101):
    q = 0
    for j in x:
        q += (j-p)**2
    t.append(q)
print(min(t))

Submission status: Accepted

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

tairyoku = []
for i in range(1, 101, 1):
  all_tairyoku = 0
  for j in range(N):
    all_tairyoku += (X[j] - i) ** 2
  else:
    tairyoku.append(all_tairyoku)
else:
  print(min(tairyoku))

Submission status: Accepted

Solution code:
N = int(input()) 
x = list(map(int, input().split()))
sumx = 0
ans = 0
ans1 = 0
ans2 = 0
for i in x:
  sumx += i

if sumx % N == 0:
  for i in x:
    ans += (i-sumx//N)**2
else:
  for i in x:
    ans1 += (i-sumx//N)**2
    ans2 += (i-sumx//N-1)**2
  ans = min(ans1, ans2)
    
print(ans)

Submission status: Accepted

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

tmp_m = 10 ** 10
for i in range(1, max(X)+1):
    tmp = 0
    for j in range(N):
        tmp += (X[j] - i) ** 2

    tmp_m = min(tmp_m, tmp)

print(tmp_m)

Submission status: Accepted

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

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

print(min(answers))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from statistics import mean 
from math import ceil,floor 
n=int(input())
arr=[int(x) for x in input().split()]
a1=ceil(mean(arr))
a2=floor(mean(arr))
s1=0
s2=0
for i in range(n):
    s1+=((arr[i]-a1)**2)
    s2+=((arr[i]-a2)**2)

print(min(s1,s2))

Submission status: Accepted

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

Submission status: Accepted

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

def calc_energy(i, X):
    X = np.array(X)
    return sum((X-i)**2)

min_energy = 1000000000
min_ind = min(X)
max_ind = max(X)
for i in range(min_ind, max_ind+1):
   energy = calc_energy(i, X) 
   if energy < min_energy:
       min_energy = energy
print(min_energy)

Submission status: Accepted

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

ans = 0

ave = round(sum(x)/n)

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

print(ans)

Submission status: Accepted

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

ave=round(sum(X_)/N)
ans=[]
for x_ in X_:
  ans.append((x_-ave)**2)

  
print(sum(ans))

Submission status: Accepted

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

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
    N = II()
    X = LI()
    min = 10**9


    for p in range(1,100):
        S = 0
        for i in range(N):
            S = S + (X[i]-p)**2
        
        if min > S:
            min = S


    print(min)



if __name__ == "__main__":
	main()

Submission status: Accepted

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

for i in range(min(X), max(X) + 1):
  hp.append(dis)
  dis = 0
  for j in X:
    dis += (i - j) ** 2
if len(hp) == 1:
  print(0)
else:
  hp.remove(0)
  print(min(hp))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input().split()
s_int = sorted([int(a) for a in s])
total = 0
for num in s_int:
  total += num
a = round(total/n)
ans = 0
for num1 in s_int:
  ans += (num1 - a)**2
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
m=int(sum(a)/n)
m1=m-1
m2=m+1
s=0
s1=0
s2=0
for i in range(n):
    s+=(a[i]-m)**2
    s1+=(a[i]-m1)**2
    s2+=(a[i]-m2)**2
print(min(s,s1,s2))

Submission status: Accepted

Solution code:
import math

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

mean = math.ceil(sum(x) / n)

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

if sum(x) % n != 0:
	mean -= 1
	ans2 = 0
	for i in range(n):
		ans2 += (x[i]-mean) ** 2

	print(min(ans1,ans2))
else:
	print(ans1)

Submission status: Accepted

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

syukai = sum(x)//n
ans=0
ans1=0
ans2=0
for i in range(n):
    ans += pow(x[i]-syukai-1,2)
    ans1 += pow(x[i]-syukai,2)
    ans2 += pow(x[i]-syukai+1,2)
print(min(ans,ans1,ans2))

Submission status: Accepted

Solution code:
import math
def I():
  return input()
def II():
  return int(input())
def MII():
  return map(int, input().split())
def LMII():
  return list(map(int, input().split()))

n = II()
a = LMII()
ans = 99999999999999999
for i in range(1, 101):
  count = 0
  for j in range(n):
    count += (i-a[j])**2
  if count < ans:
    ans = count
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    X = [int(x) for x in input().split()]
    ans = []
    mini = min(X)
    maxi = max(X)
    if mini != maxi:
        for i in range(mini, maxi):
            a = map(lambda x: (x-i)**2, X)
            ans.append(sum(a))
    else:
        ans.append(0)
    return print(min(ans))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int,input().split()))
p.sort()
min = -1
sum = -1

for i in range(p[0], p[-1] + 1):
    tmp_sum = 0
    for j in range(len(p)):
        tmp_sum += (p[j] - i)** 2
    if sum == -1 or sum > tmp_sum:
        sum = tmp_sum

print(sum)

Submission status: Accepted

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

l=[]

for p in range(1,101):
  sum=0
  
  for i in range(N):
    sum += (x[i]-p)**2
  
  l.append(sum)
  
print(sorted(l)[0])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    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 numpy as np
N=int(input())
X=list(map(int, input().split()))
X.sort()
Y=sum(X)/N
if Y-int(Y)>0.5:
    Y=int(Y)+1
else:
    Y=int(Y)
X=[(i-Y)**2 for i in X]
print(sum(X))

Submission status: Accepted

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

Submission status: Accepted

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

res = 10 ** 15
for p in range(1, 100):
    cnt = 0
    for i in range(N):
        cnt += (X[i] - p) ** 2
    res = min(res, cnt)

print(res)

Submission status: Accepted

Solution code:
N=int(input())
x=list(map(int, input().split()))
a=0
b=0
for i in range(N):
  a+=x[i]**2
for j in range(N):
  b+=x[j]
def func(p):
  return a-2*p*b+(p**2)*N

q=b//N

print(min(func(q),func(q+1)))

Submission status: Accepted

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
N = int(input())
x = readints()
ans = INF
for i in range(1, 101):
    tmp = 0
    for j in range(N):
        tmp += (x[j]-i)*(x[j]-i)
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

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


from decimal import Decimal, ROUND_HALF_UP

y = Decimal(str(sum(Xlist)/N))
#四捨五入
P = y.quantize(Decimal('0'), rounding=ROUND_HALF_UP)


num=0
for i in range(len(Xlist)):
    num += (Xlist[i]-P)**2

print(num)

Submission status: Accepted

Solution code:
import numpy as np
import math


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

X_s = np.array(X_s)
P=np.sum(X_s)/N

P_floor = math.floor(P)
P_ceil = math.ceil(P)

A=np.sum((X_s-P_floor)**2)
B=np.sum((X_s-P_ceil)**2)

print(min(A,B))

Submission status: Accepted

Solution code:
#入力
N = int(input())
X = list(map(int,input().split()))
#座標Pは平均値に近いほど良いので平均値を求める
s = sum(X)
l = len(X)
ave = s/l
#実際にPとしてとれるのは整数の座標。本当の平均値に近い整数値座標をP(ここではavei)とする。
if ave - float(int(ave)) <= 0.5:
  avei = int(s/l)
else:
  avei = int(s/l) + 1
#与えられた式に従って消費体力を求める
ans = 0
for i in range(N):
  ans += (X[i] - avei)**2
#結果
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
s = sum(X)
l = len(X)
ave = s/l
if ave - float(int(ave)) <= 0.5:
  avei = int(s/l)
else:
  avei = int(s/l) + 1
ans = 0
for i in range(N):
  ans += (X[i] - avei)**2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
s = []
for i in range(1,101):
    b = sum((a[j]-i)**2 for j in range(N))
    s.append(b) 
print(min(s))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
ans = 10**6
for i in range(1,101):
    b = sum((a[j]-i)**2 for j in range(0,N))
    ans = min(ans,b)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
ans = 0
#xをすべて足した値をnで割った値を四捨五入
p = round(sum(x)/n) 

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

print(ans)

Submission status: Accepted

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

if average%1<=0.5:
  average=int(average)
else:
  average=int(average)+1

ans=0

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

print(ans)

Submission status: Accepted

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

def sg(li):
    be = sum(li) / len(li)
    if be >= int(be) + 0.5:
        return int(be) + 1
    else:
        return int(be)

P = sg(X)
cnt = 0
for x in X:
    cnt += (x - P)**2
    
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
hp = list(map(int,input().split()))
a = []
for i in range(0,101):
  s = sum((hp[j]-i-1)**2 for j in range(0,n))
  a.append(s)

print(min(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline())
li = list(map(int, sys.stdin.readline().split()))
min = 0
for k in li:
    min += (k-1) ** 2
i = 2
while i <= 100:
  s = 0
  for k in li:
    s += (k-i) ** 2
  if s < min:
    min = s
  i += 1
print(min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

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

hp_sum = []
for i in range(1, 101):
  tmp = abs(coordinate - i)
  hp_sum.append(sum(tmp ** 2))

print(min(hp_sum))

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int,input().split(" ")))
sum_st = 10000000000
for p in range(1,max(s)+1):
  sum_sti = 0
  for x in s:
    sum_sti += (x-p)**2
  if sum_sti < sum_st:
    sum_st = sum_sti
print(sum_st)

Submission status: Accepted

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

candidates = []
for p in range(min(X), max(X)+1):
    #x=pで開催するとき
    #print(p)
    c = sum([(x - p)**2 for x in X])
    candidates.append(c)

print(min(candidates))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
mi = min(X)
ma = max(X)
A = []
for i in range(mi,ma+1):
  B = 0
  for j in X:
    B += (j - i)**2
  A.append(B)
print(min(A))

Submission status: Accepted

Solution code:
N = int(input())
X = []
X = list(map(int,input().split()))	
#print(X)
M = max(X)
A = []
ans = 0
for j in reversed(range(1,M+1)):    
    for i in X:
        #print(j,i)
        #print((i-j)*(i-j))
        ans += (i-j)*(i-j)
        #print(ans)
    #print(ans)
    A.append(ans)
    ans = 0
print(min(A))