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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

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

## Logic

ans = 0
ave = round(sum(X)/len(X))

for i in range(0,N):
    ans += (X[i]-ave)**2
print(ans)

Submission status: Accepted

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

m = np.average(A)

x = round(m)

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

print(int(ans))

Submission status: Accepted

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

for p in range(1, 100):
    power = 0
    for x in X:
        power += (x - p) ** 2
    ans = min(ans, power)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

m = min( X )
M = max( X )

v_min = 10 ** 18
for i in range( m , M + 1 ):
  v = 0
  for x in X:
    v += ( x - i ) **2
  v_min = min( v, v_min )
print( v_min )

Submission status: Accepted

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

ans = 10**9

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

print(ans)

Submission status: Accepted

Solution code:
a = []
N = int(input())
a = list(map(int, input().split()))
ave = c = 0

for i in range(N):
  ave += a[i]
ave_l = int(ave / N)
ave_u = ave_l + 1

s_l = s_u = 0
for i in range(N):
  s_l += (a[i] - ave_l)**2
  s_u += (a[i] - ave_u)**2

ans = min(s_l, s_u)
print(ans)

Submission status: Accepted

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

mean = int( sum( x ) / len( x ) + 0.5 + ( 10 ** -10 ) )

var = 0
for x_i in x:
    var += ( x_i - mean ) ** 2

print( var )

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
X.sort()
Y = [0] * (max(X) + 1)
for _x in X:
    for y_idx in range(len(Y)):
        Y[y_idx] += (_x - y_idx)**2
print(min(Y))

Submission status: Accepted

Solution code:
def f(x):
    return (x - p) ** 2


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

s = sum(X)
p = round(s / n)
# print(p)

X = list(map(f, X))
# print(X)
print(sum(X))

Submission status: Accepted

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

start=min(X)
end=max(X)
ans=10**10
for p in range(start,end+1):
    point=0
    for x in X:
        point=point+(p-x)**2
    ans=min(ans,point)

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    X = NLI()
    ans = 10**20
    for i in range(100):
        sq = 0
        for x in X:
            sq += (i-x)**2
        ans = min(ans, sq)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for p in range(1, max(x) + 1):
    temp = 0
    for q in range(len(x)):
        temp += (x[q] - p) ** 2
    ans = min(ans, temp)
print(ans)

Submission status: Accepted

Solution code:
R=0
N=int(input())
L=list(map(int,input().split()))
maxa=max(L)
mina=min(L)
minb=10**10
for i in range(mina,maxa+1):
  for j in range(N):
    R+=(L[j]-i)**2
  minb=min(minb,R)
  R=0
print(minb)

Submission status: Accepted

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

xav = sum(x) / n
if xav % 1 >= 0.5:
    xav = xav//1 +1
else:
    xav = xav//1
    
ans = 0

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

print(int(ans))

Submission status: Accepted

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

def main():
    number_of_human = int(input())
    position_list = list(map(int,input().split()))
    
    start_position = min(position_list)
    end_position = max(position_list)
    max_answear = sum([(item - start_position)**2 for item in position_list])
    while True:
        answear = sum([(item - start_position)**2 for item in position_list])
        if start_position == end_position:
            break
        start_position += 1
        if answear < max_answear:
            max_answear = answear
    
    print(max_answear)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

st = min(x)
en = max(x)
n = len(x)

min_energy = 10**10

for p in range(st,en+1):
    energy = 0
    for i in range(n):
        energy += (x[i] - p )**2

    min_energy = min(min_energy,energy)

print(min_energy)

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
ar=np.array(list(map(int,input().split())))
m=np.inf

for i in range(1,100):
    s=np.sum(np.square(ar-i))
    if s<m:
        m=s
print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

print(min(sum((x-(n+1))**2 for x in X) for n in range(max(X))))

Submission status: Accepted

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

P = []
for i in range(min(X), max(X) + 1):
    HP = [(a - i)**2 for a in X]
    P.append(sum(HP))

print(min(P))

Submission status: Accepted

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

for i in range(min(x),max(x)+1):
    sum=0
    for k in range(len(x)):
        sum+=(x[k]-i)**2
    sum_list.append(sum)

min_sum=min(sum_list)
print(min_sum)

Submission status: Accepted

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

tot = 0
for x in l:
    tot+=x

ag = int(round(tot/n))

ans = 0
for x in l:
    ans+=(x-ag)**2
print(ans)

Submission status: Accepted

Solution code:
#整数の入力
N = int(input())

#スペース区切りの整数の入力リスト
X_list = list(map(int, input().split()))

ans_list = []



for i in range(100):
  ans = 0
  for j in range(N):
    ans += (X_list[j]-(i+1))**2
  ans_list.append(ans)
print(min(ans_list))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil, floor


def tai(X, p) -> int:
    return sum((X[i] - p) ** 2 for i in range(len(X)))


if __name__ == "__main__":
    N = int(input())
    X = [int(x) for x in input().split(" ")]
    print(min(tai(X, p) for p in range(-1, len(X) + 1000)))

Submission status: Accepted

Solution code:


def solve(N ,Xs):
    ans = float('inf')
    for i in range(100):
        _sum = sum([(x - i) ** 2 for x in Xs])
        ans = min(ans, _sum)

    print(ans)


if __name__ == '__main__':
    N = int(input())
    Xs = [int(i) for i in input().split()]
    solve(N, Xs)

Submission status: Accepted

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

Submission status: Accepted

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

y = round(sum(x) / n)
ans = 0 
for i in x:
  ans += (i-y)**2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from decimal import Decimal, ROUND_HALF_UP

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

ans = 0
X_mean = Decimal(str(sum(X) / N))
X_mean = X_mean.quantize(Decimal('0'), rounding=ROUND_HALF_UP)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int( input())
X = list( map( int, input().split()))
 
v_min = 10 ** 18
m = min( X )
M = max( X )
for i in range( m, M + 1):
  v = 0
  for x in X:
    v += ( i - x ) ** 2
  v_min = min( v, v_min )
print( v_min )

Submission status: Accepted

Solution code:
N = int( input())
X = list( map( int, input().split()))
 
v_min = 10 ** 18
m = min( X )
M = max( X )
for i in range( m, M + 1):
  v = 0
  for x in X:
    v += ( i - x ) ** 2
  v_min = min( v, v_min )
print( v_min )

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(min(sum_list))

Submission status: Accepted

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

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

print(min(sum_list))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
ans = 10000000000
temp = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int( input())

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

m = min( X )
M = max( X )

v_min = 10 ** 18
for i in range( m, M + 1 ):
  v = 0
  for x in X:
    v += ( i - x ) ** 2
  v_min = min( v, v_min )
print( v_min )

Submission status: Accepted

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

m = min( X )
M = max( X )
v_min = 10 ** 18
for i in range( m, M + 1 ):
  v = 0
  for x in X:
    v += ( x - i ) ** 2
  v_min = min( v, v_min )
print( v_min )

Submission status: Accepted

Solution code:
N = int(input())
X = []
X = input().split(' ')
Z = []
for i in range(N):
   Z.append(int(X[i]))
P = round(sum(Z) / N)
result = 0
for i in range(N):
  result += (Z[i] - P) ** 2
print(int(result))

Submission status: Accepted

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

Submission status: Accepted

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

v_max = 10 ** 18
m = min( X )
M = max( X )
for i in range( m, M + 1 ):
  v = 0
  for x in X:
    v += ( x - i ) ** 2
  v_max = min( v, v_max )
print( v_max )

Submission status: Accepted

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

y = round(sum(X)/N)

ans = sum([(y-i)**2 for i in X])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
sm = sum(x)
p = sm//n
p1 = p+1

b = []
for i in range(n):
    b.append((x[i]-p)**2)
#print(sum(b))

c = []
for i in range(n):
    c.append((x[i]-p1)**2)
print(min(sum(c),sum(b)))

Submission status: Accepted

Solution code:
N=int(input())

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

a=[]
cal=0

for i in range(100):
    for j in range(len(x)):
        cal+=(x[j]-i)**2

    a.append(cal)
    cal=0


print(min(a))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
ave = sum(x) / n
ave_int = int(ave)
if (ave - ave_int) < (ave_int+1-ave):
  p = ave_int
else:
  p = ave_int+1

r = sum([ abs(i-p)**2 for i in x ])
print(r)

Submission status: Accepted

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

for P in range(1, 101):
    total = 0
    for position in X:
        total += (position - P) ** 2
    ans = min(ans, total)
    
print(ans)

Submission status: Accepted

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

minval = 100000000000
for x in range(1,101):
  minval = min(sum([(x-i)**2 for i in xxx]),minval)
print(minval)

Submission status: Accepted

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

def dist(a, X):
	l = 0
	for i in X:
		l += (a-i)**2
	return l

ans = 10000000
for i in range(min(X), max(X)+1):
	if ans > dist(i,X):
		ans = dist(i,X)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
t=max(x)
lsum=[]
for i in range(1,t+1):
  sum_x=0
  
  for x_ in x:
    sum_x+=(x_-i)**2
  lsum.append(sum_x)
  
#print(lsum)
print(min(lsum))

Submission status: Accepted

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

ave = sum(x) // n

ans = []
for i in range(ave-3,ave+3) :
  c = 0
  for j in x :
    c += (i-j)**2
  ans.append(c)

print(min(ans))

Submission status: Accepted

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

ans = 10 ** 9
for i in range(0, 101):
    s = 0
    for xx in x:
        s +=(i - xx) ** 2
    ans = min(ans, s)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def mean(x):
    sum=0
    for _ in x:
        sum+=_
    return sum/len(x)

def rss(x,xbar):
    sum=0
    for _ in x:
        sum+=(_-xbar)**2
    return sum

def main(n,x):
    ans=0
    xbar=mean(x)
    xbar_int=xbar//1
    if(xbar-xbar_int >0.5):
        xbar_int+=1
    ans=rss(x,xbar_int)
    return int(ans)

def main2(n,x):
    xmin=min(x)
    xmax=max(x)
    minsum=1000000

    for p in range(xmin,xmax+1):
        sum=0
        for xx in x:
            sum+=(xx-p)**2
        if(sum<minsum):
            minsum=sum

    return minsum

if __name__=='__main__':
    n,x=readinput()
    ans=main(n,x)
    print(ans)

Submission status: Accepted

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

def mean(x):
    sum=0
    for _ in x:
        sum+=_
    return sum/len(x)

def rss(x,xbar):
    sum=0
    for _ in x:
        sum+=(_-xbar)**2
    return sum

def main(n,x):
    ans=0
    xbar=mean(x)
    xbar_int=xbar//1
    if(xbar-xbar_int >0.5):
        xbar_int+=1
    ans=rss(x,xbar_int)
    return int(ans)

def main2(n,x):
    xmin=min(x)
    xmax=max(x)
    minsum=1000000

    for p in range(xmin,xmax+1):
        sum=0
        for xx in x:
            sum+=(xx-p)**2
        if(sum<minsum):
            minsum=sum

    return minsum

if __name__=='__main__':
    n,x=readinput()
    ans=main2(n,x)
    print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    xs = list(map(int, input().split()))
    x_min = min(xs)
    x_max = max(xs)

    ans = float("inf")
    for i in range(x_min, x_max+1):
        ans_temp = 0
        for x in xs:
            ans_temp += (x - i)**2
        ans = min(ans, ans_temp)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 1000000
for p in range(101):
  cost = 0
  for i in range(N):
    cost += (x[i] - p) ** 2
  ans = min(cost, ans)

print(ans)

Submission status: Accepted

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

# In[7]:


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


# In[8]:


ave = sum(X)//len(X)
ans_1 = sum([(x-ave)**2 for x in X])
ans_2 = sum([(x-(ave+1))**2 for x in X])
print(min(ans_1, ans_2))


# In[ ]:

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
ans2 = 99999999999999
for i in range(100):
    ans1=0
    for j in range(n):
        ans1 += pow(x[j]-i,2)
    ans2 = min(ans2,ans1)
print(ans2)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
tmp = input().split()
X = [0]*N
for n in range(N):
    X[n] = int(tmp[n])

souwa = [0]*100
for p in range(100):
    tairyoku = 0
    for n in range(N):
        tairyoku += (X[n]-p+1)**2
    souwa[p] = tairyoku

min_value = min(souwa)
min_index = souwa.index(min_value)

print(souwa[min_index])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

from statistics import mean
 
N = int(input())
X = list(map(int, input().split()))
 
mean_X = int(mean(X) + 0.5)
 
 
print(int(sum([(x - mean_X)**2 for x in X])))

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
X = list(map(int, input().split()))
A = [0]*101

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

answer = min(np.abs(A))

print(answer)

Submission status: Accepted

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

import numpy as np

np.array(A)

lis = list()

for i in range(1,max(A)+1):
    life = (A - np.array([i]*N))**2
    lis.append(sum(life))

print(min(lis))

Submission status: Accepted

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

ans = float("inf")

l = []
for i in range(1, N+101):
    pow = 0
    for j in range(N):
        # print("x[j]", x[j])
        # print("i", i)
        # print((x[j]-i)**2)
        pow += (x[j]-i)**2
    # print(pow)
    if ans > pow:
        ans = min(ans, pow)
        l.append(i)

print(ans)
# print(l)

Submission status: Accepted

Solution code:
N = int(input())

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

ans = 999999999
for i in range(200):
    hp_sum = 0
    for regi in regis:
        hp_sum += (regi - i)**2
    ans = min(ans , hp_sum)

print(ans)

Submission status: Accepted

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

print(min(sum([(xi-sum(X)//N)**2 for xi in X]),sum([(xi-sum(X)//N-1)**2 for xi in X])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

min_a = min(a)
max_a = max(a)
ans_lst = []

for i in range(min_a, max_a + 1):
  sum_ans = 0
  for j in a:
    sum_ans += (i - j) ** 2
  ans_lst.append(sum_ans)
print(min(ans_lst))

Submission status: Accepted

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

#最小値と最大値を変数に代入
minx = min(x)
maxx = max(x)

#差の二乗の合計値の初期値を代入
total = -1

#差の二乗を返す関数
def square(i, x):
  return ((x-i)**2)

#xの最小値から最大値の間でループ
for i in range(minx, maxx+1):
  list_i = [i] * n
  tmp = sum(map(square, list_i, x))
  
  if total == -1:
    total = tmp
  else:
    if total > tmp:
      total = tmp

print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
m = min(X)
M = max(X)

ans = float("inf")
for p in range(m, M + 1):
    cnt = 0
    for i in range(n):
        cnt += (X[i] - p) ** 2

    ans = min(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
ans = 10**10
for p in range(min(X), max(X)+1):
    tmp = 0
    for x in X:
        tmp += pow(x-p, 2)
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
X.sort()
ans = 10**10
for p in range(min(X), max(X)+1):
    tmp = 0
    for x in X:
        tmp += pow(x-p, 2)
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
X.sort()
ans = 10**10
for p in range(100):
    tmp = 0
    for x in X:
        tmp += pow(x-p, 2)
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:

N = int(input())
X = list(map(int, input().split()))
mn = 10**9
for p in range(min(X), max(X)+1):
    c = 0
    for x in X:
        c += (p-x)**2
    mn = min(c, mn)
print(mn)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int, input().split()))
g=sum(X)/N
if g-int(g)>=0.5:
  g=int(g)+1
else:
  g=int(g)   
ans=0
for x in X:
  ans+=(x-g)**2

print(ans)

Submission status: Accepted

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

min = 100 * 100 ** 2

for p in range(1, 101, 1):
    ttl = 0
    for i in x:
       ttl += (i - p) ** 2
    if ttl <= min:
        min = ttl

print(min)

Submission status: Accepted

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

P = round(sum(X)*1.0/N)

h = [(i - P)**2 for i in X]
print(sum(h))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print (ans)

Submission status: Accepted

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


def solve(N: int, X: "List[int]"):
    # 最小
    import math

    ans = 999999999
    for p in range(1, 100 + 1):
        vit = 0
        for x in X:
            vit += pow((x - p), 2)
        ans = min(ans, vit)
    print(ans)
    return


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
Data = list(map(int,input().split()))
mind = min(Data)
maxd = max(Data)
ans = -1
for pos in range(mind,maxd+1):
    sum1 = 0
    for d in Data:
        sum1 += (pos-d)**2
    if ans == -1:
        ans = sum1
    else:
        ans = min(ans,sum1)
print(ans)

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
  B += X[i]

P = round(B/N)
energy = 0
for i in range(N):
  energy += (X[i] - P)**2
  
print(energy)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
total=1000000000000000000
for i in range(1,101):
    tmp=0
    for j in X:
        tmp+=(j-i)**2
    total=min(total,tmp)
print(total)

Submission status: Accepted

Solution code:

class abc_156:
    
    def __init__(self):
        pass
    
    def A(self):
       pass
    def B(self):
        pass
        
    def C(self):
        N=int(input())
        X=list(map(int,input().split()))
        
        ans=[]
        sum_data=0
        
        X.sort()
        L=X[0]
        R=X[len(X)-1]
        
        for i in range(L,R+1):
            sum_data=0
            for j in range(len(X)):
                sum_data+=(X[j]-i)**2
            ans.append(sum_data)
        
        ans.sort()
        print(ans[0])
      
    def D(self):
        pass
        
    def E(self):
        pass
    
    def F(self):
        pass
    
    
if __name__=='__main__':
    obj=abc_156()
    obj.C()

Submission status: Accepted

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

sq = [xi ** 2 for xi in x]

sum_sq = sum(sq)
sum_x = sum(x)

hp = []

for p in range(min(x), max(x)+1):
    hp.append(sum_sq - 2*p*sum_x + n* (p **2))

print(min(hp))

Submission status: Accepted

Solution code:
# import sys
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()
# sys.setrecursionlimit(100000)
INF = 1001001001001
# MOD = 1000000007


def main():

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

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

    print(point)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
ans=[]
for i in range(1,max(l)+1):
    sum1=0
    for l1 in l:
        sum1+=(l1-i)**2
    ans.append(sum1)
print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
ans = 1000000000000000
for i in range(1,101):
    hp=0
    for j in range(N):
        B = (X[j]-i) ** 2
        hp+=B
    if ans > hp:
        ans=hp

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

min_e = 10 ** 9
for p in range(X[0], X[-1] + 1):
    e = sum([(x - p) ** 2 for x in X])
    min_e = min(min_e, e)

print(min_e)