Problem:


Score : 300 points

Problem Statement

There are N people living on a number line.

The i-th person lives at coordinate X_i.

You are going to hold a meeting that all N people have to attend.

The meeting can be held at any integer coordinate. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting.

Find the minimum total points of stamina the N people have to spend.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq X_i \leq 100

Input

Input is given from Standard Input in the following format:

N
X_1 X_2 ... X_N

Output

Print the minimum total stamina the N people have to spend.

Sample Input 1

2
1 4

Sample Output 1

5

Assume the meeting is held at coordinate 2. In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.

Note that you can hold the meeting only at an integer coordinate.

Sample Input 2

7
14 14 2 13 56 2 37

Sample Output 2

2354



Sample input:
2
1 4


Sample output:
5

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
han=999999999999999999
gou=0

for b in range(1,101):
    gou=0
    for a in X:
        gou+=(a-b)**2
    
    if gou<han:
        han=gou
print(han)

Submission status: Accepted

Solution code:

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

cand = sum(X) // N
ans0 = sum((v - cand) ** 2 for v in X)
ans1 = sum((v - cand - 1) ** 2 for v in X)
print(min(ans0, ans1))

Submission status: Accepted

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

avg = round(sum(x) / len(x))
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
ans = 10**6
for p in range(1, 101):
    tmp = 0
    for xi in X:
        tmp += (xi - p) ** 2
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

L = min(X)
R = max(X)

answer_list = []
for i in range(L, R+1):
  total = 0
  
  for x in X:
    total += (x-i)**2
  answer_list.append(total)
print(min(answer_list))

Submission status: Accepted

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

for i in range(1, 101):
    cost = 0
    for x in X:
        cost += (i - x) ** 2
    if cost < ans:
        ans = cost

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from decimal import Decimal, ROUND_HALF_UP
n = int(input())
l_x = list(map(int, input().split()))
mtg_p = Decimal(str(sum(l_x) / n)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)

print(sum([(x-mtg_p)**2 for x in l_x]))

Submission status: Accepted

Solution code:
N = int(input())
Positions = list(map(int,input().split()))
Distance = []
for p in range(100):
    dist = 0
    for i in range(N):
        dist = dist+ (Positions[i]-p)*(Positions[i]-p)
    Distance.append(dist)
print(min(Distance))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 100000000
for p in range(min(X), max(X)+1):
  score = 0
  for x in X:
    score += (x-p)**2
  ans = min(ans, score)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

t = []
for i in range(min(X), max(X) + 1):
  s = 0
  for x in X:
    s += (x - i) * (x - i)
  t.append(s)

print(min(t))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
ans = float("inf")
for x in range(100):
    temp = 0
    for j in range(N):
        temp += (X[j] - (x)) ** 2
    ans = min(ans, temp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 10000000
l = 0
for i in range(100):
  s = 0
  for j in range(n):
    s += pow((a[j]-(i+1)), 2)
  ans = min(s, ans)
  if(ans == s):
    l = i+1
print(ans)

Submission status: Accepted

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

mean = np.round(np.mean(np.array(x)))

print(int(np.sum((np.array(x)-mean)**2)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
saisyou = 10**7
for p in range(1,101):
    tairyoku = 0
    for x in range(N):
        tairyoku += (X[x]-p)**2
    saisyou = min(saisyou, tairyoku)

print(saisyou)

Submission status: Accepted

Solution code:
def main():

    n = int(input())
    x = list(map(int, input().split()))
    min_p = round((1 / n) * sum(x))
    stamina = sum((x[i] - min_p) ** 2 for i in range(n))
    print(stamina)

main()

Submission status: Accepted

Solution code:
N = int(input())
xxx = list(map(int, input().split()))
ans = 10**8
for P in range(100):
    acc = 0
    for i in range(N):
        acc += (xxx[i] - P) ** 2
    ans = min(ans, acc)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
nums = [int(i) for i in input().split()]
rem = 2_000_000_000
for i in range(0, 101):
  distance_sum = 0
  for x in nums:
    distance_sum += (x - i)**2
  
  if distance_sum < rem: rem = distance_sum
    
print(rem)

Submission status: Accepted

Solution code:
import numpy as np

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

ans = 100 * 100 * N
for p in np.arange(np.min(X), np.max(X) + 1):
    s = 0
    for x in X:
        s += (x - p) ** 2
    if s < ans:
        ans = s

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

ans = 100 * 100 * N
for p in np.arange(np.min(X), np.max(X) + 1):
    s = 0
    for x in X:
        s += (x - p) ** 2
    if s < ans:
        ans = s
    p += 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
c=sorted(list(map(int, input().split())))
b = c[-1]
l = []
ans = 0

for i in range(1,b+1):
    for k in c:
        ans += (k-i)**2
    l.append(ans)
    ans = 0

print(min(l))

Submission status: Accepted

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

MIN=100000000
for p in range(1,101):
  SUM=((X-p)**2).sum()
  if MIN>SUM:MIN=SUM
print(MIN)

Submission status: Accepted

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

l = []

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
P = [p for p in range(1, max(X) + 1)]
min = 0
energy = 0

for x in X:
    min += (1 - x) ** 2

for p in P:
    for x in X:
        energy += (x - p) ** 2

    if energy < min:
        min = energy
    energy = 0
print(min)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
Xmin = min(X)
Xmax = max(X)
HP = [0] * (Xmax - Xmin + 1)
P = Xmin
while P <= Xmax :
    for i in range(N) :
        HP[P-Xmin] += (X[i] - P) ** 2
    P += 1
print(min(HP))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    D = il()
    X = sum(D) // N
    ret = MAX
    for x in range(X - 3, X + 3):
        tmp = 0
        for d in D:
            tmp += (d - x) ** 2
        ret = min(ret, tmp)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	n = int(input())
	A = list(map(int,input().split()))
	ma = max(A) + 1
	ans = 1000000
	for x in range(1,ma):
		tmp = 0
		for y in A:
			tmp2 = (y-x)*(y-x)
			tmp += tmp2
		ans = min(ans,tmp)
	
	print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
ans = []
tmp = 0

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

Submission status: Accepted

Solution code:
from statistics import median, mean

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

INF = float('inf')
res = INF
for a in range(min(X), max(X)+1):
  tmp = 0
  for x in X:
    tmp += (x-a) * (x-a)
  res = min(tmp, res)
  
print(res)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
N = int(readline())
X = list(map(int, readline().split()))
X.sort()

INF = 10**9+7
ans = INF
for p in range(0, 102):
    res = 0
    for x in X:
        res += (p-x)**2
    ans = min(ans, res)
print(ans)

Submission status: Accepted

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

su = sum(x)//n

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

print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def main():
    N = int(input())
    X = sorted(list(map(int, input().split())))
    ans = sys.float_info.max
    for p in range(X[0], X[-1]+1):
        hp = sum([(p - x) ** 2 for x in X])
        if hp < ans:
            ans = hp
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 10**100

for i in range(min(x), max(x)+1):
    cost = 0
    for j in x:
        cost += (j - i)**2
    ans = min(ans, cost)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    x = list(map(int, input().split()))
    min = 10000000000
    for point in range(10000):
        s = sum([(i - point)**2 for i in x])
        if s < min:
            min = s
    print(min)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
men=list(map(int,input().split()))
for i in range(1,101):
  suu=0
  if i==1:
    for n in range(N):
      suu+=(1-men[n])**2
      ans=suu
  else:
    for h in range(N): 
      suu+=(i-men[h])**2
  if suu<ans:
      ans=suu
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:
n,*x=map(int,open(0).read().split())
sum_min=10**100
for  i in range(min(x),max(x)+1):
    sum=0
    for j in x:
        sum+=(j-i)**2
    sum_min=min(sum_min,sum)
print(sum_min)

Submission status: Accepted

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

Min = 10**9

for i in range(1,100):

    Sum = 0

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

    Min = min(Min,Sum)
    
print(Min)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
def meeting_cost(P,List):
    cost = 0
    for i in List:
        cost += (i - P)**2
    return cost
result = {}
for P in range(1, 101):
    result[P] = meeting_cost(P, X)
print(min(result.values()))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    X = list(map(int, input().split()))
    ans = 10**11
    for i in range(0,101):
        temp = 0
        for x in X:
            temp += (x-i)**2
        ans = min(temp,ans)

    print (ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
P = int(sum(X) / N) - 1
cost = []
for i in range(3):
    L = [(x - P) ** 2 for x in X]
    cost.append(sum(L))
    P += 1
print(min(cost))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    X = list(map(int, input().split()))
    min = 10000000000
    for venue in range(1, 101):
        sum = 0
        for i in range(N):
            if sum > min:
                break
            # print((venue - X[i])**2)
            sum += (venue - X[i])**2
        if sum < min:
            min = sum
    print(min)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int,input().split(" ")))
d_list = []
for i in range(100):
  d = 0
  for j in p:
    d += abs(j-i+1)**2
  d_list.append(d)

print(min(d_list))

Submission status: Accepted

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

a = sum(Xlist)/N

a_m = int(a)
a_p = a_m + 1

if a - a_m < a_p - a:
    p = a_m
else:
    p = a_p

ans = 0
for i in range(N):
    ans += (Xlist[i] - p)**2

print(ans)

Submission status: Accepted

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

s = sum(x)
avg = s // n

t = u = 0
for e in x:
    t += (e - avg)**2
    u += (e - (avg + 1))**2

print(min([t, u]))

Submission status: Accepted

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

s = sum(x)
avg = s // n

t = 0
for e in x:
    t += (e - avg)**2

u = 0
for e in x:
    u += (e - (avg + 1))**2

print(min([t, u]))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

ans = 1000000000
for i in range(101):
    sum = 0
    for j in x:
        sum += pow(j - i, 2)
    ans = min(ans, sum)

print(ans)

Submission status: Accepted

Solution code:
#2
N = int(input())
an = list(map(int,input().split()))
Min = 10**10

for i in range(1,102):
    k = 0
    for j in an:
        k += (j-i)**2
    if Min >k:
        Min = k
        
print(Min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
X = np.array([int(_) for _ in input().split()], dtype=int)
print(min(np.sum((X - i)** 2) for i in range(1, 101)))

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
x.sort()
def sump(x,p):
  s=0
  for a in x:
    s+=(a-p)**2
  return s
m=min(x)
M=max(x)
ans=[]
for p in range(m,M+1):
  ans.append(sump(x,p))
print(min(ans))

Submission status: Accepted

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

n, s = int(input()), list(map(int, input().split()))
def solve():
	for i in range(100):
		x = 0
		for e in s: x += (i+1 - e) ** 2
		yield x
print(min(solve()))

Submission status: Accepted

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

for i in range(1, 101):
  t = 0
  for j in x:
    t += (i-j)**2
  l.append(t)
    
print(min(l))

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
cost = float("inf")
for i in range(1,101):
    c = 0
    for j in X:
        c += (j - i)**2
    cost = min(cost, c)
print(cost)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def main():

    input = sys.stdin.buffer.readline
    n = int(input())
    x = list(map(int, input().split()))
    x.sort()
    mt = 10**10
    for ii in range(x[0],x[-1]+1):
        ans = 0
        for i in x:
            ans += (i-ii)**2
        mt = min(mt,ans)
    print(mt)    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
MAX_N = 100
MAX_X = 100
INF = 1_000_000_000

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

res = INF
for i in range(1, MAX_X + 1):
    t = 0
    for x in X:
        t += (i - x) ** 2
    res = min(res, t)
print(res)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    x = list(IL())
    s = sum(x)
    ans = abs(s-n)
    i = 1
    while True:
        i += 1
        tmp = abs(s-i*n)
        if ans <= tmp: 
            i -= 1
            ans = 0
            break
        ans = tmp
        
    for rep in x:
        ans += (rep-i)*(rep-i)
    print(ans)
    return

if __name__=='__main__':
    Main()

Submission status: Accepted

Solution code:
n=int(input())
a=input()
l=a.split(" ")
l=[int(i) for i in l]
mx=max(l)
mn=min(l)
dis=[]
cnt=0
for p in range(mn,mx+1):
  dis.append(0)
  for i in l:
    dis[cnt]+=(p-i)**2
  cnt+=1
print(min(dis))

Submission status: Accepted

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


N=int(input())
X=list(map(int,input().split()))
ans = (100*100)**2
for i in range(min(X),max(X)+1):
    kyori = 0
    for j in range(N):
        kyori += (X[j]-i)**2
    ans = min(ans,kyori)
print(ans)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *X = map(int, read().split())

    ans = INF
    for p in range(1, 101):
        tmp = 0
        for x in X:
            tmp += (x - p) ** 2
        if ans > tmp:
            ans = tmp

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
a=min(X)
b=max(X)
dis=10**18
for k in range(a,b+1):
    D=0
    for i in range(N):
        D+=(X[i]-k)**2
    dis=min(dis,D)

print(dis)

Submission status: Accepted

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

Submission status: Accepted

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

ans = float("inf")

for p in range(100):
    total = 0
    for i in range(n):
        total += (X[i] - p) ** 2
    ans = min(ans, total)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_,*X=list(map(int,open(0).read().split()));print(min(map(lambda p:sum((x-p)**2 for x in X),range(min(X),max(X)+1))))

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def calc_health(x, p):
    return (x - p) ** 2


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    X = il()

    ret = MAX
    for p in range(0, 101):
        sm = 0
        for x in X:
            sm += calc_health(x, p)
        ret = min(ret, sm)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

min_result = 10**9

for p in range(1, max(X) + 1):
    result = sum([(x - p)**2 for x in X])
    if min_result > result:
        min_result = result

print(min_result)

Submission status: Accepted

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

msum=0
for i in range(N):
  msum+=X[i]
msum = int(msum/N)

num1=0
num2=0
for i in range(N):
  num1+=pow(X[i]-msum,2)
  num2+=pow(X[i]-(msum+1),2)
print(min(num1,num2))

Submission status: Accepted

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

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

Submission status: Accepted

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

mean = point_arr.mean()
int_mean = int(mean)

print(min(sum((point_arr-int_mean)**2), sum((point_arr-(int_mean+1))**2)))

Submission status: Accepted

Solution code:
import statistics

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

mean=round(statistics.mean(X))
result=0

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

print(result)

Submission status: Accepted

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

k = round(sum(p)/N)

S=0
for i in range(N):
    S = S + ((p[i]-k)*(p[i]-k))
print(S)

Submission status: Accepted

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

Submission status: Accepted

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

minval = 10**6

for i in range(max(X)):
    val = 0
    for j in range(N):
        val += (X[j]-(i+1))**2
    minval = min(val, minval)

print(minval)

Submission status: Accepted

Solution code:
N = int(input())
ad_list = list(map(int, input().split()))
ave_ad = sum(ad_list) / len(ad_list)
r_ave_ad = round(ave_ad)

ans = 0
for i in range(N):
    tmp = (ad_list[i] - r_ave_ad) ** 2
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
x_list = list(map(int, input().split()))
x_max = max(x_list)

min_ans = 10 ** 7
for i in range(1, x_max+1):
    ans = 0
    for x in x_list:
        ans += (i - x) ** 2
    min_ans = min(min_ans, ans)
    
print(min_ans)

Submission status: Accepted

Solution code:
import numpy as np

def calc_all_physical_strength(X, P):
    X = np.array(X)
    return np.sum((X-P)**2)

if __name__ == "__main__":
    N = int(input())
    X = list(map(int, input().split()))
    min_P = sum(X) / N
    print(min(calc_all_physical_strength(X, int(min_P)), calc_all_physical_strength(X, int(min_P)+1)))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

ans = 10**18
for x in range(101):
    Y = (X - x) * (X - x)
    ans = min(ans, Y.sum())

print(ans)

Submission status: Accepted

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

ans = 100000000

for p in range(1,100): #Pの位置
  sum = 0
  for x in X: #Xの要素を１つずつ取得
    sum += (x - p)**2
  ans = min(sum, ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

avg = sum(X)//N

E1 = sum(list(map(lambda x: (x - avg)**2, X)))
E2 = sum(list(map(lambda x: (x - avg - 1)**2, X)))

print(min(E1,E2))

Submission status: Accepted

Solution code:

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

""" ans=100000000000000000

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

print(ans)
print(range(n)) """

a=int(sum(x)/n)
b=a+1
ans1=0
ans2=0
for i in range(n):
    ans1+=(x[i]-a)**2
    ans2+=(x[i]-b)**2
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

class unionfind:
    def __init__(self, n):
        self.parent = [i for i in range(n)]
        self.size = [1 for i in range(n)]
    def find(self,a):
        if a == self.parent[a]: return a
        else: self.parent[a] = find(self,self.parent[a]); return self.parent[a]
    def unite(self,a,b):
        pa,pb = self.find(self,a), self.find(self,b)
        if pa == pb: return
        else: self.parent[pb] = pa; self.size[pa] += self.size[pb]
    def same(self,a,b): return find(self,a) == find(self,b)

n = iinput()
x = iarr()

vals = []
for p in range(1,101):
    val = sum([(xx - p)**2 for xx in x])
    vals.append(val)
    
ans = min(vals)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().split()))
res = 10 ** 10
for i in range(1, 101):
  res = min(res, sum([(j - i) ** 2 for j in lst]))
print(res)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    x_list = list(map(int, input().split()))
    mn = 10**9
    for i in range(1, max(x_list)+1):
        sm = 0
        for x in x_list:
            sm += (x-i)**2
        if mn > sm:
            mn = sm  
    print(mn)
resolve()

Submission status: Accepted

Solution code:
N = int(input())
Nlist = list(map(int, input().split()))
Nmax = max(Nlist)
Nmin = min(Nlist)
ans = 100**3
for i in range(Nmin, Nmax+1):
    total = 0
    for j in Nlist:
        total += (j-i)**2
    if ans > total:
        ans = total
print(ans)

Submission status: Accepted

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

# M = int(statistics.median(X_list))

def pow(X_list, M):
    P = 0
    for X in X_list:
        P += (X-M)**2
    return P

min_X = min(X_list)
max_X = max(X_list) +1
pow_min=pow(X_list, max_X)
pow_=0
for i in range(min_X,max_X,1):
    pow_ = pow(X_list,i)
    if pow_ <= pow_min:
        pow_min = pow_
print(pow_min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N = int(input())
X = list(map(int,input().split()))
medf = math.floor(sum(X)/N)
medc = math.ceil(sum(X)/N)
cf = 0
cc = 0
for i in range(N):
  cf += (X[i] - medf)**2
  cc += (X[i] - medc)**2
print(min(cf,cc))

Submission status: Accepted

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

n = int(input())
a = list(map(int, input().split()))
ans = 100 ** 5

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

print(ans)

Submission status: Accepted

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

ans = 10**9
for p in range(1,101):
    hp = 0
    for i in range(n):
        hp += (x[i]-p)**2
    ans = min(ans,hp)
print(ans)