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
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    X = [int(i) for i in readline().split()]
    X = np.array(X)

    ans = np.min(np.sum((X - np.arange(1,101).reshape(100, 1))**2, axis=1))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
list=list(map(int,input().split()))
min_tairyoku=10000000000000000000
tairyoku=[]
for i in range(min(list),max(list)+1):
    t=0
    for j in list:
        t += (j-i) ** 2
    tairyoku.append(t)
print(min(tairyoku))

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
min_total = 100000000
for syukai in range(1, 100):
  total = 0
  for x in X:
    total += (x - syukai)**2
  else:
    min_total = min(total, min_total)
print(min_total)

Submission status: Accepted

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

for i in range(100):
    t=0
    for j in range(N):
        t += (X[j]-i)**2
        tairyoku[i]=t

print(min(tairyoku))

Submission status: Accepted

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

dist_min = 10 ** 6
for p in range(1, 100, 1):
    dist = 0
    for x in xlist:
        dist += (x - p) ** 2
    dist_min = min(dist_min, dist)

print(dist_min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
Xs=list(map(int,input().split()))
Xs.sort()
a=Xs[0]
b=Xs[-1]
ans=float("inf")
for p in range(a,b+1):
    m=0
    for x in Xs:
        m+=(x-p)**2
    if m<ans:
        ans=m
print(ans)

Submission status: Accepted

Solution code:

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)



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


def II():
    return int(input())

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

N=int(input())
X=np.array(acinput())

u = round(np.mean(X))


res=0

print(int(np.sum((u-X)**2)))

Submission status: Accepted

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

Submission status: Accepted

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

left = min(x)
right = max(x)
ans = float('inf')

for p in range(left,right+1):
  summed = 0
  
  for xi in x:
    summed += (xi -p)**2
  ans = min(ans,summed)
print(ans)

Submission status: Accepted

Solution code:

N = input()
X = input().split()
total1 = 0
total2 = 0
for i in X:
    i = int(i)
    total1 += 1
    total2 += i
total2 *= 2
total1 *= 2
min = total2/total1
if min >= 1:
    if min%int(min) >=0.5:
        min = int(min) + 1
    elif min%int(min) == 0 :
        min = int(min)
    else:
        min = int(min) 
else:
    min = 1


sum = 0
for i in X:
    i  = int(i)
    sum += (min-i)*(min-i)
print(sum,end="")

Submission status: Accepted

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

hp = 0
ans = 10**18

for i in range(100):
    for j in range(N):
        hp += (X[j] - i)*(X[j] - i)

    if ans > hp:
        ans = hp

    hp = 0

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input().split()
xs = []

for ps in s:
  xs.append(int(ps))

max_x = max(xs)
min_x = min(xs)
for i in range(min_x, max_x + 1):
  dist = 0
  for x in xs:
    dist += abs((i - x) ** 2)
  
  try:
    if min_dist > dist:
      min_dist = dist
  except NameError:
    min_dist = dist

print(min_dist)

Submission status: Accepted

Solution code:
n=int(input())
X=[int(i) for i in input().split()]
X.sort()
ans=float("inf")
a,b=X[0],X[-1]
for i in range(a,b+1):
  cur=0
  for x in X:
    cur+=(x-i)**2
  ans=min(cur,ans)
print(ans)

Submission status: Accepted

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


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

    # KeyInsight:
    # xの座標の最小値から最大値までを探索すればよい
    # See: https://img.atcoder.jp/abc156/editorial.pdf
    left = min(x)
    right = max(x)

    for p in range(left, right + 1):
        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())
input_zahyo = []
goukei = 0
tairyoku = 0

input_zahyo = input().split()
zahyo = [int(s) for s in input_zahyo]


for i in range(n):
    goukei += zahyo[i]

ave = round(goukei/n)

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

print(tairyoku)

Submission status: Accepted

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

f = lambda x, y: (x-y)*(x-y)
temp = []
for i in range(min(l), max(l)+1):
    aaa = sum([f(m, i) for m in l])
    temp.append(aaa)
print(min(temp))

Submission status: Accepted

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

P = 0
min_sum = 100 ** 2 * 100
while(True):
  sum = 0
  for x in range(N):
    sum += (X_list[x]- P) ** 2
  if(sum <= min_sum):
    min_sum = sum
    P += 1
    continue
  else:
    break

print(min_sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 10**9
for i in range(1,101):
    tmp = 0
    for j in range(N):
        tmp += abs(X[j] - i) ** 2
    ans = min(ans, tmp)

print(ans)

Submission status: Accepted

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

ret = 10 ** 9
for i in range(1, 1000):
    ret = min(ret, sum([(x-i)**2 for x in X]))
print(ret)

Submission status: Accepted

Solution code:
import math

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

def min_p(x,n):
  return round(sum(x)/n)

def fsum(x,p):
  return sum([(i-p)**2 for i in x])

p=min_p(x,n)
print(fsum(x,p))

Submission status: Accepted

Solution code:
import math
N = int(input())
X = list(map(int, input().split()))
 
def sutamina(P, X):
    return (X-P)**2
  
sutamina_min = float('inf')
for i in range(100):
    sutamina_souwa = 0
    for k in X:
        sutamina_souwa += sutamina(i, k)
    if sutamina_souwa < sutamina_min:
        sutamina_min = sutamina_souwa

print(sutamina_min)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)


def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    X = list(map(int, input().split()))
    ans = float('inf')
    for p in range(1, 101):
        total = 0
        for x in X:
            total += (x - p) ** 2
        ans = min(total, ans)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

average_x = np.mean(x)
p = round(average_x)

l = np.square(x-p)
print(int(sum(l)))

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
c=[]
for p in range(1,101):
    sum1=0
    for i in x:
        r= abs(i-p)
        sum1 = sum1+r**2
    c.append(sum1)
print(min(c))

Submission status: Accepted

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

## 2パターンとも試す
ans1 = 0
ans2 = 0
  
med = sum(X)//N
for n in range(N):
  ans1 += (X[n]-med)**2

med += 1
for n in range(N):
  ans2 += (X[n]-med)**2
  
ans = min(ans1,ans2)
  

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

x0 = 1
Ps = []
for k in range(100):
  P = 0
  for i in range(N):
    P+= (X_i[i]-x0)**2
  Ps.append(P)
  x0+=1
print(min(Ps))

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
a = 10000000
for p in range(100):
    a_i = sum([(x_i - p)**2 for x_i in x])
    if a < a_i: break
    else: a = a_i
print(a)

Submission status: Accepted

Solution code:
from sys import stdin

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
s=sum(x)
mini=100000*10000
cand=s//n
sum=0
for i in x:
  sum+=((i-cand)**2)
mini=min(mini,sum)
cand+=1
sum=0
for i in x:
  sum+=((i-cand)**2)
mini=min(mini,sum)
cand-=2
sum=0
for i in x:
  sum+=((i-cand)**2)
mini=min(mini,sum)
print(mini)

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
l, r = x[0], x[0]
for i in x:
    l = min(l, i)
    r = max(r, i)
ans = 10e9
for i in range(l, r + 1):
    cost = 0
    for j in range(n):
        cost += (x[j] - i) ** 2
    ans = min(ans, cost)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

    minimum = float("inf")
    for i in range(1,101):
        hpmin = 0
        for j in X:
            hpmin += (i-j)**2
        minimum = min(hpmin, minimum)
    print(minimum)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

def f(P,X):
    if len(X)==1:
        return (P-X[0])**2
    else:
        return (P-X[0])**2 + f(P,X[1:])

avg = sum(X) / N
max = math.ceil(avg)
min  = math.floor(avg)

if max-avg < avg-min:
    print (f(max,X))
else:
    print (f(min,X))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
c = sum([x**2 for x in X])

ans = 100 * (100) ** 2
for i in range(1, 101):
    c += 2 * sum([i-x for x in X]) - N
    ans = min(c, ans)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np


def main():
    _ = input()
    x = np.asarray(list(map(int, input().split())))
    p = int(np.round(np.average(x)))
    print(np.sum((x - p) ** 2))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(min)

Submission status: Accepted

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

li = [[0]*101 for _ in range(n)]

for i in range(n):
    for j in range(101):
        li[i][j] = (x[i] - j) ** 2

ans = 10 ** 10

for i in range(101):
    tmp = 0
    for j in range(n):
        tmp += li[j][i]
    ans = min(ans,tmp)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

s = sum(x)
p = s // n if 2 * (s % n) <= n else s // n + 1
ans = sum([(i - p) ** 2 for i in x]) 
print(ans)

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:
#from math import sqrt
#from heapq import heappush, heappop
#from collections import deque


def cost(X, p):
    c = 0
    for x in X:
        d = x - p
        c += d * d
    return c


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

    total = sum(X) // N

    c1 = cost(X, total)
    c2 = cost(X, total + 1)

    if c1 > c2:
        print(c2)
    else:
        print(c1)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
ans = []
l = min(x)
r = max(x)

for i in range(l, r+1):
  tmp = 0
  for j in range(n):
    tmp+= (x[j]-i)*(x[j]-i)
  ans.append(tmp)
print(min(ans))

Submission status: Accepted

Solution code:
engAll = []
eng = 0

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

for i in range(min(live), max(live) + 1):
    for j in live:
        eng += (j - i)**2
    engAll.append(eng)
    eng = 0

print(min(engAll))

Submission status: Accepted

Solution code:
#C - Rally
N = int(input())
X = list(map(int, input().split()))

ans = []
for i in range(100):
    tmp = 0
    for j in range(len(X)):
        tmp += (i - X[j])**2
    ans.append(tmp)

print(min(ans))

Submission status: Accepted

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

S = 0
S_min = 100000000000000

for i in range(101):
    for j in X:
        S += (j - i)**2
        
    if S < S_min:
        S_min = S
        S = 0
    else:
        S = 0
print(S_min)

Submission status: Accepted

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

S = 0
S_min = 100000000000000

for i in range(min(X), max(X)+1):
    for j in X:
        S += (j - i)**2
        
    if S < S_min:
        S_min = S
        S = 0
    else:
        S = 0
print(S_min)

Submission status: Accepted

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

s = round(sum(x)/n)
ans = [(a-s)**2 for a in x]

print(sum(ans))

Submission status: Accepted

Solution code:
import sys
n = int(input())
xLst = list(map(int, input().split()))
sm = 0
ans = int(sys.maxsize)

#開催する座標
for i in range(101):
    #全員の体力の計算
    sm = sum((xLst[ii] - i)**2 for ii in range(n))
    if ans > sm:
        ans = sm        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans=float("inf")
for P in range(1,101):
    num=0
    for x in X:
        num+=(x-P)**2
    ans=min(ans,num)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a=[int(x) for x in input().split()]
import math
import statistics
mean=statistics.mean(a)
m=round(mean,0)

sum=0
for x in a:
    t=(x-m)**2
    sum+=t
int_sum=int(sum)
print(int_sum)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,(input().split())))
hp = 0
ans = []
for j in range(1,100+1):
#  print(j,hp)
  for i in x:
    hp_temp = ( i -j )**2 
#    print(i,j,hp_temp)
    hp +=  hp_temp
  ans.append(hp)
#  print(hp)
  hp = 0
 
print(min(ans))

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
x = np.array(input().split(),dtype=np.int64)

shouhiHP = 1001001001000
for k in range(min(x),max(x)+1):
    xHP = x - k
    xHP2jou = xHP ** 2
    sum_xHP = sum(xHP2jou)
    if sum_xHP < shouhiHP:
        shouhiHP = sum_xHP
    else:
        pass

print(shouhiHP)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
X = np.array([int(i) for i in input().split()])

ans = []
for i in range(0, max(X)+1):
    ans.append(sum((X - i)**2))
    
print(min(ans))

Submission status: Accepted

Solution code:
n = int(input())
temp = [int(s) for s in input().split()]
rarry = 0
min = 100000007
min_temp = 0
#print(max(temp))
for n_ in range(max(temp) + 1):
    for i in temp:
        min_temp += ((i - n_) ** 2)
    #print(min_temp)
    if(min > min_temp):
        min = min_temp
    min_temp = 0


print("{}".format(str(min)))

Submission status: Accepted

Solution code:
n = int(input())
temp = [int(s) for s in input().split()]
rarry = 0
min = 100000007
min_temp = 0
for n_ in range(100):
    for i in temp:
        min_temp += ((i - n_) ** 2)
    #print(min_temp)
    if(min > min_temp):
        min = min_temp
    min_temp = 0


print("{}".format(str(min)))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
s = sum(x)
p = float(s/n)
q = int(10*p)
if q%10 < 5:
    p = int(s/n)
else:
    p = int(s/n)+1
r = 0
for y in x:
    r += (y - p)**2
print(r)

Submission status: Accepted

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

P = int(sum(X) / N + 0.5)
print(sum((x - P) * (x - P) for x in X))

Submission status: Accepted

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


ans = 10**9
for p in range(1,101):
    a = 0
    for k in x:
        a+=(k-p)**2
    ans = min(ans,a)

print(ans)

Submission status: Accepted

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

ans = 10**9
for i in range(max(X)+1):
    tmp = 0
    i += 1
    for j in range(N):
        tmp += pow(X[j] - i, 2)
        # print(X[j])
    # print(tmp)
    if tmp < ans:
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
X = list(map(int, input().split()))
X.sort()
ans = float("inf")
for p in range(X[0], X[-1] + 1):
    tmp = 0
    for i in range(N):
        tmp += (p - X[i]) ** 2
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x_lst = list(map(int,input().split()))
average1 = sum(x_lst) // n
average2 = sum(x_lst) // n + 1

answer1 = 0
for i in range(n):
    x = x_lst[i]
    answer1 += (x-average1) ** 2

answer2 = 0
for i in range(n):
    x = x_lst[i]
    answer2 += (x-average2) ** 2

answer = min(answer1,answer2)
print(answer)

Submission status: Accepted

Solution code:
from statistics import mean
from decimal import Decimal, ROUND_HALF_UP

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

m = Decimal(str(mean(X))).quantize(Decimal('0'), rounding=ROUND_HALF_UP)

ans = 0
for x in X:
  ans += (x - m) ** 2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
X = [int(i) for i in input().split()]
r = min(X)
l = max(X)
ans = float("INF")
num = 0
for i in range(r, l+1):
  for x in X:
    num += (x-i)**2
  ans = min(ans, num)
  num = 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

s = sum(X_list)

p = round(s/N)


ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

hito = list(map(int, input().split()))
hito.sort()

a = min(hito)
b = max(hito)

res = []

for i in range(a,b + 1):
  s = 0
  for j in hito:
    s += (i - j) * (i - j)
  res.append(s)
print(min(res))

Submission status: Accepted

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

ans=0
ans1=0
ans2=0
for i in L:
    ans+=pow(i-x,2)
    ans1+=pow(i-x-1,2)
    ans2+=pow(i-x+1,2)

print(min(ans,ans1,ans2))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
l = sum(X)
p = l // N
q = l // N + 1
s = 0
t = 0
for x in X:
  s += (x - p) ** 2
  t += (x - q) ** 2
print(min(s, t))

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


N = ii()

X = li()

import numpy as np

X = np.sort(X)

x_st = X[0]
x_ed = X[-1]

all_min = np.inf

for i in range(x_st,x_ed+1):
    itr_min = np.sum(np.abs(X-i)**2)
    # print(i,itr_min)


    if(all_min > itr_min):
        all_min = itr_min


print(all_min)

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
p = round(sum(b) / a)

hp = 0
for i in b:
    hp += (i - p) ** 2

print(hp)

Submission status: Accepted

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

ma=max(x)
mi=min(x)

ans=10**9
for i in range(mi,ma+1):
  t_ans=0
  for j in x:
   t_ans+=(i-j)**2
  ans=min(ans,t_ans)
print(ans)

Submission status: Accepted

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

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

a = round(sum(X)/N)
s = sum((x - a)**2 for x in X)
print(s)

Submission status: Accepted

Solution code:
n = int(input())
x_list = list(map(int, input().split()))
ans_list = [sum([(x - p) ** 2 for x in x_list]) for p in range(min(x_list), max(x_list) + 1)]
print(sorted(ans_list)[0])

Submission status: Accepted

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

ans = float('inf')
for i in range(min(Xn),max(Xn)+1):
    pos = 0
    for j in Xn:
        pos += (j-i)**2
    ans = min(ans, pos)
print(ans)

Submission status: Accepted

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

print(  min( sum( (xx-p)**2 for xx in x ) for p in range(max(x)+2) ) )

Submission status: Accepted

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

ans = 10 ** 9
for p in range(min(x), max(x) + 1):
    cost = 0
    for xi in x:
        cost += (xi - p) ** 2
    ans = min(ans, cost)
print(ans)

Submission status: Accepted

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

m=10**9+7
for i in range(0,100):
  p=i+1
  a=0
  for j in range(0,N):
    a=a+(huga[j]-p)**2
  m=min(a,m)
  
print(m)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
ans = (100**2)*100
total = 0
for i in range(min(X),max(X)+1):
    for i2 in range(N):
        total += (X[i2] - i)**2
    if total <= ans:
        ans = total
    total = 0

print(ans)

Submission status: Accepted

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

ans = None
for p in range(min(x), max(x) + 1):
    cost = 0
    for xi in x:
        cost += (xi - p) ** 2
    ans = min(ans, cost) if ans is not None else cost
print(ans)

Submission status: Accepted

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

xx = []
for i in range(min(x), max(x)+1):
    wa = 0
    for j in x:
        wa += (j-i)**2
    xx.append(wa)
print(min(xx))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
X=list(map(int, input().split()))
s=sum(list(map(lambda x: (x-min(X))**2, X)))
for i in range(min(X),max(X)+1):
    s_i=sum(list(map(lambda x: (x-i)**2, X)))
    if s_i<=s:
        s=s_i
print(s)

Submission status: Accepted

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

tminm = 0
for k in range(N):
  tminm += (A[k] - 1)**2

ma = max(A)
for i in range(1,ma+1):
  minm = 0
  for j in range(N):
    minm += (A[j] - i)**2
  
  if minm < tminm:
    tminm = minm

print(tminm)

Submission status: Accepted

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

X.sort()

MIN=10**10
for p in range(102):
    ans=0
    for g in range(N):
        ans+=(p-X[g])**2
    MIN=min(ans,MIN)
print(MIN)

Submission status: Accepted

Solution code:
# coding: utf-8

# min(sum_i (x_i-p)^2)
# d/dp = 0: sum_i -2(x_i-p) = 0, p = sum_i(x_i)/p

n = int(input().rstrip())
x_list = [int(x) for x in 
          input().rstrip().split(" ")]
p1 = sum(x_list)//n
if sum(x_list)%n == 0:
  print(sum((x-p1)**2 for x in x_list))
else:
  p2 = p1 + 1
  print(min(sum((x-p1)**2 for x in x_list),
            sum((x-p2)**2 for x in x_list)))

Submission status: Accepted

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


def score(p):
    sc = 0
    for x in X:
        sc += (x - p) ** 2
    return sc


scores = [score(p) for p in range(1, 101)]
print(min(scores))

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
a=sum(x)//n
b=a+1

A,B=0,0
for i in x:
  A+=(a-i)**2
  B+=(b-i)**2
  
print(min(A,B))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input()) 
L = list(map(int, input().split()))
ans = 10 ** 18
for i in range(1, 101):
  tmp = 0
  for l in L:
    tmp += (i - l) ** 2
  ans = min(tmp, ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

from sys import stdin, stderr

def main():
   N = int(stdin.readline())
   A = map(int, stdin.readline().split())

   res = 10000000000000
   for x in xrange(1, 101):
      cost = sum([ (a-x)**2 for a in A  ])
      res = min(res, cost)

   print(res)

   return 0

if __name__ == '__main__': main()

Submission status: Accepted

Solution code:
import math

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

p = sum(x) / n
p = [math.floor(p), math.ceil(p)]

min = 10000000

for a in p:
    y = list(map(lambda x: math.pow(x-a, 2), x))
    if sum(y) < min:
        min = sum(y)

print(int(min))

Submission status: Accepted

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

print(sum([(a-p)**2 for a in A]))

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

answer = 10 ** 15
for p in range(1, 101):
    tmp = 0
    for x in X:
        tmp += (x - p) ** 2
    answer = min(answer, tmp)

print(answer)

Submission status: Accepted

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

min_hp = -1
for i in range(min(x),max(x)+1):
    hp = 0
    for j in x:
        hp += (j - i) ** 2
    if min_hp < 0:
        min_hp = hp
    min_hp = min(min_hp,hp)

print(min_hp)

Submission status: Accepted

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

ans = INF
for p in range(1, 101):
    s = 0
    for xi in X:
        s += (xi - p) ** 2
    ans = min(ans, s)

print(ans)

Submission status: Accepted

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

ans = (100**2) * 100
for p in range(1, 101):
    s = 0
    for xi in X:
        s += (xi - p) ** 2
    ans = min(ans, s)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    N, *X = map(int, open(0).read().split())
    
    ans = 10 ** 8
    for p in range(1, 101):
        sm = 0
        for xi in X:
            sm += (xi - p) ** 2
        ans = min(ans, sm)
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())
X = sorted(list(map(int, input().split())))
if N == 1:
    print(0)
else:
    r = X[-1] - X[0]
    ans = float("inf")
    for i in range(r + 1):
        R = X[0] + i
        hp = 0
        for j in range(N):
            hp = hp + (R - X[j]) ** 2
 
        ans = min(hp, ans)
    print(ans)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    x = list(map(int, readline().split()))
    x.sort()
    mt = 10 ** 10
    for i in range(x[0], x[-1] + 1):
        t = 0
        for v in x:
            t += (v - i) ** 2
        mt = min(mt, t)
    print(mt)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n = int(input())
x = sorted(list(map(int,input().split())))
li = []
cost = 0
for i in range(x[0],x[-1]+1,1):
    cost = 0
    for b in x:
        cost += (b-i)**2
    li.append(cost)
print(min(li))