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 numpy as np
n = int(input())
a = list( map(int, input().split()))

p = np.mean(a)

p1 = int(p)
p2 = p1 + 1

ans1 = 0
ans2 = 0
for i in range(n):
    ans1 += (a[i] - p1)**2
    ans2 += (a[i] - p2)**2



print(min(ans1, ans2))

Submission status: Accepted

Solution code:
import sys
N = int(input())
Xl = list(map(int, input().split()))
Xl.sort()
minx = Xl[0]
maxx = Xl[-1]
minsum = sys.maxsize
for i in range(minx, maxx+1):
    sumd = 0
    for x in Xl:
        sumd += (x - i)**2
    if sumd < minsum:
        minsum = sumd
print(minsum)

Submission status: Accepted

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

Submission status: Accepted

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

ave = round(sum(nums) / len(nums))

total = 0
for num in nums:
    total += abs((num-ave)**2)

print(total)

Submission status: Accepted

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

mh = 1000000000
for x in range(1,101):
    sh = 0
    for n in range(N):
        sh += (Xs[n] - x)*(Xs[n] - x)
    mh = min(mh, sh)

print(mh)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

n = input()
X = input().rstrip().split(' ')

n = int(n)
x = [0 for _ in range(n)]

for a in range(n):
    x[a] = int(X[a])
    
x.sort()

count = 1000000
tei = 0

for a in range(100):
    tei = 0
    for b in x:
        tei += (b-a)**2
    count = min(tei,count)
print(count)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
ll = len(l)
res = 0
ans = 10000000000
 
for i in range(1, 101):
    for j in range(ll):
        res += (l[j] - i)**2
    ans = min(ans, res)
    res = 0
 
print(ans)

Submission status: Accepted

Solution code:
N= int(input())
X = list(map(int,input().split()))
def calc(n):
  ans = 0
  for x in X:
    ans += (x-n)**2
  return ans
ans = 100000000
for n in range(100):
  ans = min(ans,calc(n))
print(ans)

Submission status: Accepted

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

def solve(N: int, X: "List[int]"):
    avg = round(sum(X) / len(X))
    ans = 0
    for i in range(N):
        ans = ans + ((X[i] - avg) ** 2)

    print(ans)

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_ls = list(map(int, input().split()))
x_ls.sort()
#print(x_ls)
sub_num = 10**10+7
for i in range(1,101):
    _max = 0
    #print(i)
    for j in range(n):
        #print(j)
        #print(x_ls[j])
        _max+=((i-x_ls[j])**2)
    sub_num = min(sub_num, _max)
print(sub_num)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
s=int(sum(x)/n+0.5)
#s=int((max(x)+min(x))/2)
a=0
for i in x:
    a+=(i-s)**2
print(a)

Submission status: Accepted

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

PP = sum(XL) / len(XL)
P = sum(XL) // len(XL)
R0= sum([(x - P - 1) ** 2 for x in XL])
R1= sum([(x - P) ** 2 for x in XL])
R2= sum([(x - P + 1) ** 2 for x in XL])

print(min(R0, R1, R2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
X = [int(x) for x in stdin.readline().rstrip().split()]

def solve(X, i):
    Y = [(x - i) ** 2 for x in X]
    return sum(Y)

minv = 10**9
bv = minv+1
i = 0
while minv < bv:
    bv = minv
    v = solve(X, i)
    i += 1
    if minv > v:
        minv = v
print(minv)

Submission status: Accepted

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

p = round(sum(x_list)/n)

power = sum([(x-p)**2 for x in x_list])

print(power)

Submission status: Accepted

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

A={}
s=sum(X)
for i in range(1,101):
    A[i]=N*i**2-2*i*s

min_i=min(A, key=A.get)

a=0
for j in range(N):
   a+=(X[j]-min_i)**2 

print(a)

Submission status: Accepted

Solution code:
n = int(input())
x = input().split(" ")
for i in range(n):
	x[i] = int(x[i])
b = 1000000
for i in range(1, 101):
	t = 0
	for j in range(n):
		t = t + (i - x[j]) * (i - x[j])
	if t < b:
		b = t
print(b)

Submission status: Accepted

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

if (len(set(x)) == 1):
  print(0)
else:
  ans = []
  for p in range(min(x), max(x)):
    sigma = 0
    for i in x:
      sigma += (p-i)**2
    ans.append(sigma)
  print(min(ans))

Submission status: Accepted

Solution code:
n=map(int,input().split())
x=list(map(int,input().split()))
ans=10**10
for i in range(0,200):
    chk=0
    for j in x:
        chk+=(j-i)**2
    if chk<ans:ans=chk
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
#import statistics
n=int(input())
a=list(map(int,input().split()))
mean=sum(a)/n
mean_one=math.ceil(mean)
mean_two=math.floor(mean)
#med=statistics.median(a)
#med=math.floor(med)
ans_one=0
for i in a:
    ans_one+=(i-mean_one)**2
ans_two=0
for i in a:
    ans_two+=(i-mean_two)**2
ans=min(ans_one,ans_two)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
x = list(map(int,input().split()))
x.sort()
a = sum(x)
b = []
for i in range(0,n):
    b.append(x[i]**2)
c = sum(b)
s = n -2 * a
for j in range(2,101):
    t = n * (j**2) -2 * j * a
    if t < s:
        s = t
print(s+c)

Submission status: Accepted

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

t = int(round(sum(A)/N,0))
c = 0

for i in A:
    c += ( i - t )**2

print(c)

Submission status: Accepted

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

s = sum(X)
s2 = sum(x*x for x in X)

ans = 10**15
X.sort()

for p in range(X[0], X[-1]+1):
    r = s2 - 2 * p * s + N * p * p
    ans = min(ans, r)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
x_li = list(map(int, input().split()))
ans = 10000000000000
for i in range(1, 101):
    d = 0
    for j in range(N):
        d += (x_li[j] - i) ** 2
    ans = min(ans, d)
print(ans)

Submission status: Accepted

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

mp = 10**9
for i in range(1, 101):
    s = 0
    for j in x:
        s += (i - j)**2
    if mp > s:
        mp = s

print(mp)

Submission status: Accepted

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

_list = [-1 for i in range(100)]
if min(x)==max(x):
    print(0)
else:
    for i in range(min(x), max(x), 1):
        a = 0
        for j in range(n):
            a += (x[j]-i)**2
        _list[i] = a
    _list = np.array(_list)
    print(min(_list[_list>=0]))

Submission status: Accepted

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


# score
anc = float('inf')
tmp = 0
for p in range(min(c),max(c)+1):
    for i in c:
        tmp += (i-p)**2
    if tmp < anc:
        anc = tmp
    tmp = 0
print(anc)

Submission status: Accepted

Solution code:
input()
li = list(map(int, input().split()))
ans = -1
for i in range(min(li), max(li)+1):
    hp = sum([(regi - i) ** 2 for regi in li])
    if ans < 0 or ans > hp: ans = hp
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 22 20:52:29 2020

@author: H_Hoshigi
"""

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

P = sum(X_list) // N

cost_list_1 = [(Xi-P)**2 for Xi in X_list]
cost_list_2 = [(Xi-(P+1))**2 for Xi in X_list]

print(min(sum(cost_list_1),sum(cost_list_2)))

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
X = sorted(map(int, input().split())) 
P = int(round(np.mean(X)))

a = 0
for x in X:
  a += abs(P-x)**2
print(a)

Submission status: Accepted

Solution code:
n = int(input())
x = [int(each) for each in input().split(' ')]
# 総当たりでやってみて、その結果をリストに入れておく
candidate = []
for i in range(min(x), max(x)+1):
    result = 0
    for person in x:
        result += (person-i)**2
    candidate.append(result)

print(min(candidate))

Submission status: Accepted

Solution code:
import sys
import math
import itertools as it
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
n = i()
x = intl()
m = []
s = 0
for i in range(-max(x),max(x)+1):
    for j in range(n):
        s += (x[j]-i)**2
    m.append(s)
    s = 0
print(min(m))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n = int(input())
arr = sorted([int(_) for _ in input().split()])
MAX = max(arr)
MIN = min(arr)
val = 99999999999999

for i in range(MIN, MAX+1):
  for j in range(len(arr)-n+1):
    if val > sum([math.pow(i-_, 2) for _ in arr[j:j+n]]):
      val = sum([math.pow(i-_, 2) for _ in arr[j:j+n]])
print(int(val))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
#N,K=map(int,input().split())
X=list(map(int,input().split()))
P=[]
for p in range(max(X)+1):
    a=0
    for x in X:
        a+=(p-x)**2

    P.append(a)

print(min(P))

Submission status: Accepted

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

ave = sum(A) // N
ave2 = sum(A) // N + 1

total = [0,0]

for i in range(N):
  total[0] += abs(A[i] - ave) ** 2
  total[1] += abs(A[i] - ave2) ** 2
  
print(min(total))

Submission status: Accepted

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

avex = round(sum(x)/n)

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

print(ans)

Submission status: Accepted

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

x_sum = 0
for i in range(a):
  x_sum += b[i]

p = round(x_sum / a)
#print(p)

h = 0
for i in range(a):
  h += (b[i]-p)**2
  
print(h)

Submission status: Accepted

Solution code:
import numpy as np

def main():
    N = int(input())
    X = list(map(int, input().split()))
    X = np.array(X)
    m = int(np.mean(X))
    n = m + 1

    print(min(np.sum((X - m) ** 2), np.sum((X - n) ** 2)))




    return 0


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

N=int(input())
X=np.array(input().split(),dtype=np.int32)

ave_point=np.average(X)

can_point=[int(ave_point),int(ave_point)+1]

s1=0
s2=0
for i in range(N):
    s1+=pow((X[i]-can_point[0]),2)
    s2+=pow((X[i]-can_point[1]),2)

if(s1>s2):
    print(s2)
else:
    print(s1)

Submission status: Accepted

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

powers = []
for i in range(min(points), max(points) + 1):
    power = 0
    for point in points:
        power += ((i - point) ** 2)
    powers.append(power)

print(min(powers))

Submission status: Accepted

Solution code:
import numpy as np

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

print(int(sum((l - round(l.mean())) ** 2)))

Submission status: Accepted

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

Submission status: Accepted

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

def calc(p):
    global x
    ans = 0
    for xx in x:
        ans += (xx - p) * (xx - p)
    return ans

answers = []
for i in range(1, 100):
    answers.append(calc(i))

print(min(answers))

Submission status: Accepted

Solution code:
#!python3.4.3
import statistics
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

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

mean = statistics.mean(x_list)
mean = Decimal(str(mean)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
result = 0


for x in x_list:
  result += (x - mean)**2
  
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
Xs = list(map(int, input().split()))
max_dis = 10**18
for i in range(max(Xs)+1):
  sum_dis = sum([(x-i)**2 for x in Xs])
  if sum_dis<max_dis:
    max_dis = sum_dis
print(max_dis)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
a = min(x) + (max(x) - min(x)) // 2
s = 1000000000000
for a in range(min(x), max(x)+1):
    s = min(s, sum(map(lambda x: (x - a) ** 2, x)))
print(s)

Submission status: Accepted

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

a = [None]*100
for i in range(1, 101):
    a[i-1] = sum((xi-i)**2 for xi in x)

print(min(a))

Submission status: Accepted

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

ans = max(x)**3
for i in range(1, max(x) + 1):
  temp = 0
  for j in x:
    temp += (i - j)**2
  ans = min(ans, temp)
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):
    sum_ = 0
    for x in X:
        sum_ += (x - i)** 2
    ans = min(ans,sum_)
print(ans)

Submission status: Accepted

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

del x[n:]

# print(x)

now = float('inf')
new = 0

for i in range(100):
  new = 0
  for j in range(len(x)):
    new += (x[j] - (i + 1))** 2
  if new < now:
    now = new

print(now)

Submission status: Accepted

Solution code:
import numpy as np
import collections
from sys import stdin


def get_result(data):
    N, X = data[0][0], data[1:][0]
    X = np.array(X)
    max_X = max(X)
    tmp = np.zeros(max_X + 1)
    for i in range(max_X + 1):
        tmp[i] = np.sum((X - i) ** 2)
    return int(min(tmp))

if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

Submission status: Accepted

Solution code:
from statistics import mean
import math
n = int(input())
citizen = list(map(int,input().split()))
hostF = math.floor(mean(citizen))
hostC = math.ceil(mean(citizen))
ansF = 0
ansC = 0
for i in citizen:
    ansF += (hostF-i)**2
    ansC += (hostC-i)**2
ans = ansF if ansF<ansC else ansC
print(int(ans))

Submission status: Accepted

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

def main(N, lst_X):
    
    min_P1 = sum(lst_X) // N
    sum_sutamina1 = 0
    for X in lst_X:
        sum_sutamina1 += (X - min_P1) ** 2

    min_P2 = min_P1 + 1
    sum_sutamina2 = 0
    for X in lst_X:
        sum_sutamina2 += (X - min_P2) ** 2

    return min(sum_sutamina1, sum_sutamina2)
        
if __name__ == "__main__":

    answer = main(N, lst_X)
    print(answer)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
X = np.array(list(map(int, input().split())))
a = int(np.mean(X))
sum1 = 0
sum2 = 0
for x in X:
    sum1 += (x - a) * (x - a)
    sum2 += (x - (a + 1)) * (x - (a + 1))
if sum1 < sum2:
    print(sum1)
else:
    print(sum2)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
xs = list(map(int, input().split()))
xs = np.array(xs, dtype = np.int64)

res = 10000000000
for pi in range(100):
    re = xs - pi
    re = np.power(re, 2)
    re = np.sum(re)
    res = min(re, res)
print(res)

Submission status: Accepted

Solution code:
from statistics import mean

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

p = round(mean(x_list))

total = 0
for i in x_list:
  strength = (i-p)**2
  total += strength
  
print(total)

Submission status: Accepted

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

a = sum(x)//n

y,z = 0,0
for i in range(n):
    y += (a-x[i])**2
    z += ((a+1)-x[i])**2
print(min(y,z))

Submission status: Accepted

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

Submission status: Accepted

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

p_1 = sum(x) // n
p_2 = p_1 + 1

ans_1 = 0
ans_2 = 0

for x_i in x:
  ans_1 += (x_i - p_1) ** 2
  ans_2 += (x_i - p_2) ** 2

print(min(ans_1, ans_2))

Submission status: Accepted

Solution code:
N = int(input())
x = list(map(int, input().split()))
hp_list = [sum([(xx-p)**2 for xx in x]) for p in range(min(x), max(x)+1)]
print(min(hp_list))

Submission status: Accepted

Solution code:
size = int(input())
positions = [int(pos_str) for pos_str in input().split(' ')]

opt_pos = round(sum(positions) / size)

power_sum = 0
for pos in positions:
  power_sum += (opt_pos - pos) ** 2

print(power_sum)

Submission status: Accepted

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

point1 = round(sum(people)/len(people) + 0.5)
point2 = point1 - 1
point3 = point1 + 1
cost1 = 0
cost2 = 0
cost3 = 0

for person in people:
    cost1 += (person - point1)**2
for person in people:
    cost2 += (person - point2)**2
for person in people:
    cost3 += (person - point3)**2
tmp = [cost1, cost2, cost3]
print(min(tmp))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
G = round(sum(A)/N)
HP = 0

for i in range(N):
	HP+=(A[i]-G)**2

print(HP)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n = int(input())
xs = list(map(int, sys.stdin.readline().split()))
center = round(sum(xs) / n)
distances = [(center - x)**2 for x in xs]
ans = sum(distances)
print(ans)

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
N = int(input())
X = inpl()
S = sum(X)
T = sum(x*x for x in X)
P = round(S/N)
ans = ((N*P-S)**2 - S*S)//N + T
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
zahyo = list(map(int, input().split()))
av= sum(zahyo) // len(zahyo)
av2 = sum(zahyo) / len(zahyo)

if av2 - av >= 0.5:
    av += 1

sumv = 0
for i in range(N):
    sumv += (zahyo[i] - av)**2
    
print(sumv)

Submission status: Accepted

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

Submission status: Accepted

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

    print(min(p,s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

dp = {}

for i in range(N):
    for j in range(min(X), max(X)+1):
        if j in dp:
            dp[j] += (X[i] - j)*(X[i] - j)
        else:
            dp[j] = (X[i] - j)*(X[i] - j)

print(min(dp.values()))

Submission status: Accepted

Solution code:
import numpy as np

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

x = 10 ** 10
for p in range(1, 101):
    tmp = sum((X_array - p) ** 2)
    x = min(x, tmp)

print(x)

Submission status: Accepted

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

ret = float('inf')
for i in range(0, 101) :
  s = 0
  for j in range(N) :
    s += (X[j] - i) ** 2
  ret = min(ret, s)
  
print(ret)

Submission status: Accepted

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

anc = float('inf')
tmp = 0
for p in range(min(c),max(c)+1):
    for i in c:
        tmp += (i-p)**2
    if tmp < anc:
        anc = tmp
    tmp = 0
print(anc)

Submission status: Accepted

Solution code:

import math

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

power = []

point = sum(A) / len(A)
avg = round(point)

for i in range(N):
    power.append((A[i] - avg) ** 2)

print(sum(power))

Submission status: Accepted

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

ans = 10**8
for p in range(1, 150):
    w = 0
    for i in range(n):
        w += (x[i] - p)**2

    ans = min(w, ans)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
L=sorted(list(map(int,input().split())))
ans=10**10 if n!=1 else 0
for P in range(L[0],L[-1]+1):
    temp=0
    for l in L:
        temp+=(l-P)**2
    ans=min(temp,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

pos = round(np.mean(x_list))
ans = sum([(x-pos)**2 for x in x_list])
print(int(ans))

Submission status: Accepted

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

s = 10000000000
for p in range(max(x)+1):
    sss = 0
    for i in range(n):
        a = (x[i]-p)**2
        sss += a
    if sss < s:
        s = sss
print(s)

Submission status: Accepted

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

ver=int(sum(X)/len(X)+0.5)

#print(ver)
sumsum=0
for i in X:
    sumsum+=(i-ver)**2

print(sumsum)

Submission status: Accepted

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

result=100000000
p = 0

for i in range(1,101):
    tmp_r = 0
    for xj in x:
        tmp_r += (i-xj)*(i-xj)
    if tmp_r < result:
        result = tmp_r
        p = i

print(result)

Submission status: Accepted

Solution code:
# 2020/02/22
# AtCoder Beginner Contest 156 - C

# Input
n = int(input())
x = list(map(int,input().split()))
xl = [0] * 101

# Calc
for p in range(101):
    for j in range(n):
        xl[p] = xl[p] + (x[j] - p) ** 2

# Output
print(min(xl))

Submission status: Accepted

Solution code:
def val(X, point):
    ans = 0
    for v in X:
        ans += (v - point) ** 2
    return ans


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

point = sum(X) // len(X)
first = val(X, point)
second = val(X, point + 1)
print(min(first, second))

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

Submission status: Accepted

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

minimum = min(X)
maximum = max(X)

def shohi(zahyo, shukai):
  return pow(zahyo - shukai, 2)

saisho = None
for i in range(minimum, maximum + 1):
  ret = sum(map(lambda zahyo: shohi(zahyo, i), X))
  saisho = ret if saisho is None or ret < saisho else saisho

print(saisho)

Submission status: Accepted

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

pow = []

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

print(min(pow))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
min_d = 10**18
if x[0] != x[n-1]:
    for p in range(x[0],x[n-1]):
        sm = 0
        for j in range(n):
            sm += (x[j] - p)**2
        else:
            min_d = min(min_d,sm)
    print(min_d)
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
arr = [int(s) for s in input().split(" ")]

def calculate(n,arr):
    arr = sorted(arr)
    data = []
    for i in range(1,101):
        sum = 0
        for ar in arr:
            sum += (ar - i) ** 2

        data.append(sum)

    return min(data)


result = calculate(n,arr)

print(result)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    X = list(map(int, input().split()))

    min_ = min(X)
    max_ = max(X)
    ans = float('inf')
    for p in range(min_, max_ + 1):
        n = 0
        for xi in X:
            n += (xi - p) ** 2
        ans = min(ans, n)
    print(ans)


main()

Submission status: Accepted

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

dp = [0] * 100

for p in range(100):
    for x in X:        
        dp[p] += (x - p) ** 2

print(min(dp))

Submission status: Accepted

Solution code:
N = int(input())

nlist = map(int,input().split())

llist = list(nlist)

resu = float('INF')

def stamina_req(coordinate):
    res = 0
    for nl in llist:
        res += abs(nl - coordinate)**2
    return res



for j in range(1, 101):
    resu = min(resu, stamina_req(j))

print(resu)

Submission status: Accepted

Solution code:
import functools
n = input()

x = [int(x) for x in input().split()]
ans = functools.reduce(lambda a,b: a +(b-0)**2, x, 0)
for i in range(min(x),max(x)+1):
    t = functools.reduce(lambda a,b: a +(b-i)**2, x, 0)
    ans  = min(ans, t)
print(ans)

Submission status: Accepted

Solution code:
#!python3.4
# -*- coding: utf-8 -*-
# abc156/abc156_c
import sys
import math

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    X = i2nn()
    ave = round(sum(X) / N)
    print(sum(map(lambda x: (x - ave)**2, X)))
    return

main()

Submission status: Accepted

Solution code:
num_of_points = int(input())
points = [int(x) for x in input().split(" ")]

average = round(sum(points) / num_of_points)

sum = 0

for point in points:
    sum += (point - average)**2

print(sum)

Submission status: Accepted

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


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

x2 = [i ** 2 for i in x]
ans = float('inf')
sum1 = sum(x)
sum2 = sum(x2)
for p in range(1, 101):
    cnt = sum2 + (sum(x) * (-1) * 2 * p) + (p**2*n)
    ans = min(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

ans = 10 ** 10
for i in range(1, 101):
    temp = x - i
    ans = min(ans, sum([j ** 2 for j in temp]))

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
X = list(map(int, input().split()))
m = round(np.mean(X))
result = 0
for x in X:
    result += (x-m)**2
print(int(result))

Submission status: Accepted

Solution code:
a = int(input())
c = list(map(int, input().split()))
ma, mi = max(c), min(c)
j = list()
for i in range(mi, ma+1):
    d = sum([(x-i)**2 for x in c])
    j.append(d)
print(min(j))

Submission status: Accepted

Solution code:
import numpy as np
N, *X = map(int,open(0).read().split())

X = np.array(X)
g0 = sum(X)//len(X)
g1 = sum(X)//len(X)+1

print(min(sum((X-g0)**2),sum((X-g1)**2)))

Submission status: Accepted

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

mini = min(X)
maxi = max(X)
consume = 999999999

for i in range(mini, maxi+1):
    pos = i
    total = sum([(pos - j) ** 2 for j in X])
    consume = min(total, consume)

print(consume)

Submission status: Accepted

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

import math

a = sum(x) // n
r1 = 0
r2 = 0
for xi in x:
  r1 += (xi - a)**2
  r2 += (xi - (a+1))**2

print(min(r1,r2))

Submission status: Accepted

Solution code:
def Main(N, X):
    av = round(sum(X)/N)
    ans = 0
    for i in range(N):
        ans += (X[i]-av)**2
    return ans

def main():
    N = int(input())
    X = list(map(int, input().split()))
    print(Main(N, X))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
total = 0
from decimal import Decimal, ROUND_HALF_UP
N = int(input())
A = list(map(int,input().split(" ")))
sum_number = sum(A) / N
sum_number = Decimal(str(sum_number))
sum_number = sum_number.quantize(Decimal('0'), rounding=ROUND_HALF_UP)
for i in range(N):
    total += abs(A[i] - sum_number) ** 2
print(total)