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

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

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

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

energy = float('inf')
while (L <= R):
  energy = min([energy, ene(L)])
  L += 1
  
print(energy)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
d = [0]*(max(X)+1-min(X))
for i in range(min(X),max(X)+1):
  for x in X:
    d[i-min(X)] += (x-i)**2
  if i > min(X) and d[i-min(X)] >= d[i-1-min(X)]:
    print(d[i-1-min(X)])
    exit(0)    
print(min(d))

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

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

ans = (100 ** 2) * 100 + 1

_min = min(x)
_max = max(x)

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

print(ans)

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

avg_x = sum(X)/len(X)
p = round(avg_x)
hp = [abs(x-p)**2 for x in X]
print(sum(hp))

Solution (Python):
n = int(input())
x = [int(x) for x in input().split()]
e = round(sum(x)/len(x))
k = 0
for i in range(len(x)):
    k = k + (x[i] - e)*(x[i] - e)
print(k)

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

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

P = int(sum(X)/N+0.5)

print(sum(map(lambda x_i: (x_i-P)**2, X)))

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

y =[(i-p)**2 for i in x]
z =[(i-p-1)**2 for i in x]
print(min(sum(y),sum(z)))

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

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

ans=1145141919
for p in range(max(x)+1):
    tmp_ans=0
    for i in range(n):
        tmp_ans+=(x[i]-p)**2
    ans=min(ans,tmp_ans)
print(ans)

Solution (Python):
n = int(input())
point_list = list(map(int, input().split()))
hp_list = []
for p in range(1, max(point_list) + 1):
    hp = 0
    for i in range(len(point_list)):
        hp += (point_list[i] - p) ** 2
    hp_list.append(hp)
print(min(hp_list))

Solution (Python):

import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()

x = LIST()

sqsum = 0
sum1 = 0
for el in x:
    sqsum+=el*el
    sum1+=el
z = 10**9
for p in range(0, 101):
    z = min(z, sqsum+p*p*n - 2*p*sum1)

print(z)

Solution (Python):
import math
N = int(input())
X = list(map(int,input().split()))
P = math.ceil(sum(X)/N)
P1 = P - 1
hp = 0
hp2 = 0

for x in X:
  hp_x = (P-x)**2
  hp2_x = (P1 - x)**2
  hp = hp + hp_x
  hp2 = hp2 + hp2_x
print(min(hp,hp2))

Solution (Python):
N = int(input())
*X, = map(int, input().split())

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

ans = []
hps = []
for i in range(mx + 1):
    for x in X:
        hps.append((x - i) ** 2)
    ans.append(sum(hps))
    hps = []

print(min(ans))

Solution (Python):
N = int(input())
lis = list(map(int,input().split()))

if sum(lis)/N - sum(lis)//N > 0.5:
    mid = sum(lis)//N +1
else :
    mid = sum(lis)//N
result = 0
for i in lis:
    result += (i-mid)**2

print(result)

Solution (Python):


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

for p in range(1, max(x) + 1):
  point = 0
  for _x in x:
    point += (_x - p) ** 2
    
  point_list.append(point)

print(min(point_list))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
P = [i for i in range(1, 101)]
ans = 10**6
for p in P:
    power = 0
    for i in range(n):
        power += (x[i] - p)**2
    ans = min(ans, power)
print(ans)

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

Solution (Python):

import sys

sysread = sys.stdin.readline
read = sys.stdin.read


sys.setrecursionlimit(10**7)


def run():
    N, *X = list(map(int, read().split()))
    A = sum(X)
    B = sum([val ** 2 for val in X])
    if A%N == 0:
        print(round(B - A ** 2 / N))
    else:
        p = A // N
        alpha = min(abs(p - A/N), abs(p - A/N + 1)) ** 2 * N + B - A ** 2 / N
        print(round(alpha))


if __name__ == "__main__":
    run()

Solution (Python):
import math

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

Xn_2 = [x*x for x in Xn]

S_Xn = sum(Xn)
S_Xn_2 = sum(Xn_2)

P = S_Xn/N
P_min = math.floor(P)
P_max = math.ceil(P)

print(min(S_Xn_2-2*S_Xn*P_max+N*P_max*P_max,S_Xn_2-2*S_Xn*P_min+N*P_min*P_min))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ans = 10**9
for i in range(1, 101):
  y = map(lambda x: (x-i)**2, x)
  ans = min(ans, sum(y))
print(ans)

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

import math, statistics

X_mean = statistics.mean(X)

X_mean_l = math.floor(X_mean)
X_mean_h = math.ceil(X_mean)

ans_l = 0
ans_h = 0

for i in range(N):
    ans_l += (X[i] - X_mean_l)**2
    ans_h += (X[i] - X_mean_h)**2

if ans_l < ans_h:
    print(ans_l)
else:
    print(ans_h)

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

min_count = 1e10
for i in range(101):
    count = 0
    for x in x_list:
        count += (x - i) * (x - i)
    if count < min_count:
        min_count = count

print(min_count)

Solution (Python):

"""
Created on Thu May  7 22:03:51 2020

@author: shinba
"""

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

largeX = max(X)
smallX = min(X)

ans = float("inf")

for i in range(smallX,largeX+1):
    S = 0
    for j in X:
        S += (i-j)**2
    ans = min(ans,S)
        
print(ans)

Solution (Python):
N = int(input())
x_list = list(map(int, input().split()))
hp_list = []
min_x = min(x_list)
max_x = max(x_list)

for i in range(min_x, max_x+1):
  hp_sum = 0
  for j in x_list:
    hp = (j - i) ** 2
    hp_sum += hp
  hp_list.append(hp_sum)
print(min(hp_list))

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

ans = []

for i in range(1, 101):
    tmp = 0
    for j in x:
        tmp += (j - i) ** 2
    ans.append(tmp)

print(min(ans))

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

cnt_min = 10000000000000000

for P in range(0, 101):
  cnt = 0
  for x in X:
    cnt += (P-x)**2
  if cnt < cnt_min:
    cnt_min = cnt
  
print(cnt_min)

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

for p in range(1,100):
  count=0
  for xx in x:
    count+=(xx-p)**2
  sumlist.append(count)
print(min(sumlist))

Solution (Python):
from sys import stdin


def main():
    n = int(stdin.readline())
    x = list(map(int, stdin.readline().split()))

    p = sum(x) / n

    p1 = int(p)
    p2 = int(p + 1)

    s1 = 0
    s2 = 0

    for xi in x:
        s1 += (xi - p1) ** 2
        s2 += (xi - p2) ** 2

    print(min(s1, s2))


if __name__ == "__main__":
    main()

Solution (Python):
import math
N = int(input().strip())
X = list(map(int, input().strip().split()))

min_effort = 100000000000
for i in range(100):
    accumulated_effort = 0
    for j in range(N):
        accumulated_effort += int(math.pow(i - X[j], 2))
    if min_effort > accumulated_effort:
        min_effort = accumulated_effort

print(min_effort)

Solution (Python):
n = int(input())

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

a1 = sum(x) // n
a2 = a1 + 1


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

if ans1<ans2:
    print(ans1)
else:
    print(ans2)

Solution (Python):
def hp(P, X):
    ans = 0
    for x in X:
        ans += pow(x-P,2)
    return ans

N = int(input())
X = list(map(int, input().split()))
ans = float('inf')
for i in range(1, 101):
    ans = min(hp(i, X), ans)
print(ans)

Solution (Python):

N = int(input())

X_list = list(map(int, input().split()))
mean_X = round(sum(X_list)/N)

res = 0
for x in X_list:
    res += (x - mean_X)**2

print(res)

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



sum_power = 999999999999

for i in range(1,100):
    temp = 0
    for j in range(n):
        temp += (x[j] - i)**2
    sum_power = min(sum_power,temp)

print(sum_power)

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

Xmax = max(X)
Xmin = min(X)

dis = []

for i in range(Xmax - Xmin + 1):
    tmp =  list(map(lambda x: (x - Xmin - i)**2, X))
    dis.append(sum(tmp))
    
print(min(dis))

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

Solution (Python):
n = int(input())
x_ = list(map(int,input().split()))

if n ==1:
    print(0)
else:
    cnt = 0
    res_ = []
    for i in range(100):
        cnt = 0
        for j in range(len(x_)):
            cnt += (x_[j] - i)**2
        res_.append(cnt)

    print(min(res_))

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
for p in range(101):
    sum = 0
    for x in X:
        sum += ((x - p)**2)
    if p == 0:
        ans = sum
    if ans > sum:
        ans = sum
print(ans)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
for p in range(max(X)+1):
    sum = 0
    for x in X:
        sum += ((x - p)**2)
    if p == 0:
        ans = sum
    if ans > sum:
        ans = sum
print(ans)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
for p in range(max(X)+100):
    sum = 0
    for x in X:
        sum += ((x - p)**2)
    if p == 0:
        ans = sum
    if ans > sum:
        ans = sum
print(ans)

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

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

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

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

a=10000000
for P in range(1,100+1):
    aP=0
    for i in range(N):
        aP=aP+((X[i]-P)**2)
    if aP<a:
        a=aP
print(a)

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

pos = round(sum(X) / n)
hp = 0
for x in X:
    hp += (x - pos) * (x - pos)

print(hp)

Solution (Python):
input()
list1 = list(map(int,input().split()))
res = 100000000
for i in range(1,101):
  sum1 =0
  for num in list1:
    sum1 += (num-i)**2
  res = min(res,sum1)
print(res)

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

ans = 10**6
for p in range(min(x),max(x)+1,1):
    power = 0
    for i in x:
        power += (i-p)**2
    if power < ans:
        ans =  power

print(ans)

Solution (Python):


N = int(input())
X = [int(x) for x in input().split()]
total = float('inf')
for p in range(101):
    tmp = 0
    for x in X:
        tmp += (x - p) ** 2
    total = min(total, tmp)
print(total)

Solution (Python):
import math
N = int(input())
X = list(map(int,input().split()))

A = math.ceil(sum(X)/N)
B = math.floor(sum(X)/N)

a = 0
b = 0

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

Solution (Python):
N = int(input())
X = sorted(map(int,input().split()))
countermin = 0
for j in range(N):
        countermin += (X[j]-X[0])**2
        
for i in range(X[0],X[-1]+1):
    counter = 0
    for j in range(N):
        counter += (X[j]-i)**2
    if counter < countermin:
        countermin = counter
print(countermin)

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

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

min_num = 99999999999999999999

for i in range(1, 101):
    sum = 0
    for num in x:
        sum += (num - i) ** 2
    min_num = min(min_num, sum)
print(min_num)

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

total = 0

for i in range(100):
    for j in range(n):
        total += (x[j]-i)**2
    if i == 0:
        ans = total
    elif total < ans:
        ans = total
    total = 0

print(ans)

Solution (Python):
import math
N=int(input())
X=list(map(int,input().split()))
Prange= range(math.floor(min(X))-1,math.ceil(max(X))+1)
summin=100000000000
for P in Prange:
    sum=0
    for x in X:
        sum+=(P-x)**2
    if summin > sum:
        summin=sum
print(summin)

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

each = 0
loss = 0
ll = []

for k in range(min(x), max(x)+1):
      for j in range(len(x)):
            each = np.power((x[j]-k), 2)
            loss += each
      ll.append(loss)
      loss = 0
  
print(min(ll))

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

each = 0
loss = 0
ll = []

for k in range(min(x), max(x)+1):
      for j in range(len(x)):
            each = np.power((x[j]-k), 2)
            loss += each
      ll.append(loss)
      loss = 0
  
print(min(ll))

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

each = 0
loss = 0
ll = []

for k in range(min(x), max(x)+1):
      for j in range(len(x)):
            each = np.power((x[j]-k), 2)
            loss += each
      ll.append(loss)
      loss = 0
  
print(min(ll))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    import numpy as np

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

    X_arr = np.array(X)
    mean = X_arr.mean()

    x1 = int(mean)
    x2 = int(mean)+1

    v1 = np.sum((X_arr-x1)**2)
    v2 = np.sum((X_arr-x2)**2)
    print(min(v1, v2))


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
l = list(map(int, input().split()))

mean = round(sum(l)/N)
stamina = 0

for p in l:
    stamina += (p - mean)**2

print(stamina)

Solution (Python):
import math
import numpy as np

N = int(input())

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

max_num = max(A)
min_num = min(A)

ans = 100101101

for i in range(min_num, max_num + 1):
    cost = 0
    for j in range(len(A)):
        cost += (A[j] - i) * (A[j] - i)
    ans = min(ans, cost)

print(ans)

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

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

Solution (Python):
import sys
input = sys.stdin.readline
n=int(input())
x=list(map(int,input().split()))
power=[]
x.sort()
for i in range(x[0],x[n-1]+1):
  sum=0
  for j in range(n):
    sum+=(x[j]-i)**2
  power.append(sum)
power.sort()
print(power[0])

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  
def Is(): return map(int, input().split())  
def LI(): return list(map(int, input().split()))  
def TI(): return tuple(map(int, input().split()))  
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  
def LS(): return list(input())  
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

N = I()
X = LI()
p = round(sum(X)/N)
ans = 0
for x in X:
    ans += (x-p)*(x-p)
print(ans)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
p=1
ans1=float('inf')


while True:
  ans2=0
  
  for x in X:
    ans2 += (x-p)**2
   
   
  if ans2 > ans1:
    print(ans1)
    break
   
  ans1=ans2
  p +=1

Solution (Python):

import sys
import numpy as np
import math

def solve(N: int, X: "List[int]"):
    place = np.mean(X)
    place = round(place)
    result = 0
    for i in range(N):
        result += (X[i]-place) ** 2
    print(int(result))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    X = [int(next(tokens)) for _ in range(N)]  
    solve(N, X)

if __name__ == '__main__':
    main()

Solution (Python):
def my_round(x, d=0):
    import math
    p = 10 ** d
    return float(math.floor((x * p) + math.copysign(0.5, x)))/p

def resolve():
    import statistics
    n = int(input())
    x = [int(i) for i in input().split()]
    median = my_round(statistics.mean(x))
    res = sum([(i-median)**2 for i in x])
    print(int(res))
    
resolve()

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

ans = float('inf')

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

Solution (Python):


N = int(input())
X = [int(x) for x in input().split()]
total = float('inf')
for p in range(101):
    tmp = 0
    for x in X:
        tmp += (x - p) ** 2
    total = min(total, tmp)
print(total)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(readline())
x = [int(i) for i in readline().split()]

p1 = sum(x)//n
p2 = sum(x)//n+1
ans1 = 0
ans2 = 0
for i in x:
    ans1 += (i-p1)**2
    ans2 += (i-p2)**2
print(min(ans1, ans2))

Solution (Python):
N = int(input())
X = [int(_) for _ in input().split()]
P = round(sum(X)/N)
print(sum([(x - P) ** 2 for x in X]))

Solution (Python):
import math

def f(a , x):
  ans = 0
  for i in range(len(x)):
    ans += (a - x[i]) ** 2
  return ans

n = int(input())
x = list(map(int, input().split()))
a = sum(x) / n
ans = min(f(math.floor(a) , x), f(math.ceil(a) , x))
print(ans)

Solution (Python):
n = int(input())
Xs = list(map(int, input().split()))

sum = 0
for i in range(len(Xs)):
    sum += Xs[i]
average = sum / n
surpls = sum % n

ans = 0
if surpls == 0:
    for i in range(len(Xs)):
        ans += (Xs[i]-int(average))**2
else:
    diff1 = 0
    diff2 = 0
    for i in range(len(Xs)):
        diff1 += (Xs[i]-int(average))**2
    for i in range(len(Xs)):
        diff2 += (Xs[i]-int(average)-1)**2
    if diff1 >= diff2:
        ans = diff2
    else:
        ans = diff1
print(ans)

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

min_val = -1
for i in range(100):
    pos = i+1
    tmp = 0
    for x in x_list:
        tmp += (x - pos)**2
    if tmp < min_val or min_val == -1:
        min_val = tmp
print(min_val)

Solution (Python):
N = int(input())
Xs = list(map(int,input().split()))
ans = 0
ansCandidate = 0
for j in range(min(Xs),max(Xs)):
    ansCandidate = 0
    for i in range(N):
        ansCandidate += (Xs[i] - j)**2
    if j == min(Xs):
        ans = ansCandidate
    ans = min(ans,ansCandidate)
print(ans)

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
n = int(input())
nums = [int(i) for i in input().split()]
avg = sum(nums)/len(nums)
avg = Decimal(str(avg)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
print(sum([(num-int(avg))**2 for num in nums]))

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

B = sum(A) / len(A)
B = round(B)

C = 0
for i in A:
    C += (i - B) ** 2

print(C)

Solution (Python):
from sys import stdin

if __name__ == "__main__":
  N = int(input())
  X = [int(i) for i in input().split()]
  
  min_total_cost = 10**7
  for p in range(1, 100+1):
    total_cost = 0
    for x in X:
      total_cost += (p-x)**2
    
    min_total_cost = min(total_cost, min_total_cost)

  print(min_total_cost)

Solution (Python):


N=int(input())
List=list(map(int, input().split()))
MinList=[]
ansList=[]

zahyou=1
while zahyou<=100:
    MinList=[]
    hito=0
    while hito<N:
        
        MinList.append((List[hito]-zahyou)**2)
        hito+=1
    ansList.append(sum(MinList))
    
    zahyou+=1

print(min(ansList))

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

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

ind = range(1, max(X)+1)
K = [0]*(len(ind)+1)

for p in ind:
    K[p] = sum(map(lambda x: (x - p)**2, X))

print(min(K[1:]))

Solution (Python):
Dis = [i*i for i in range(101)]
N = int(input())
X = [int(i) for i in input().split()]

ans = []
for i in range(1,101):
    k = 0
    for j in X:
        k += Dis[abs(i-j)]
    ans.append(k)
print(min(ans))

Solution (Python):
import numpy as np

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

min_x = min(x_list)
max_x = max(x_list)

sum_min = 1e+9
for p in range(min_x, max_x+1, 1):
    sum = np.sum((x_list-p)**2)
    sum_min = min(sum_min, sum)
print(sum_min)

Solution (Python):
n = int(input())
num_list = list(map(int, input().split()))

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

print(min(ans_list))

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

ans = 10 ** 99
ansp = 0

for i in range(100):
    for j in range(n):
        ansp += abs(x[j] - i)**2
    if ans > ansp:
         ans = ansp
    ansp = 0 
    
print(ans)

Solution (Python):
import numpy as np

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

X.sort()
X = np.array(X)
mn = np.inf
for i in range(X[0], X[-1]+1):
    mn = min(mn, sum((X - i)**2))
    
print(mn)

Solution (Python):
n = int(input())
x = list(map(int, input().split(' ')))
a = 0
b = 10**99
for i in range(100):
	for j in range(len(x)):
		a += (i-x[j])**2
	if b > a:
		b = a
	a = 0
print(b)

Solution (Python):
N = int(input())
X_list = list(map(int,input().split()))
sum_list = []
for P in range(min(X_list),max(X_list)+1):
  sum = 0
  for i in range(N):
    hp = (X_list[i]-P)**2
    sum += hp
  sum_list.append(sum)

print(min(sum_list))

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
P = round(sum(X)/N)

T = [(X[i]-P)*(X[i]-P) for i in range(0,N,1)]
print(sum(T))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
ans1=sum(x)
ans2=0
ans=10000000
for i in range(n):
  ans2+=x[i]**2
for p in range(1,max(x)+1):
  ans=min(ans,n*p*p+ans2-2*p*ans1)
print(ans)

Solution (Python):
from collections import defaultdict
import numpy as np

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

memo = defaultdict(int)

for i in range(1, 101):
    tmp = ((x - i)**2).sum()
    memo[tmp] += 1

print(min(memo.keys()))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=pow(10,12)
for i in range(0,101):
    cnt=0
    for x in a:
        cnt += pow(x-i,2)
    ans=min(cnt,ans)
print(ans)

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

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


tairyoku = []

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

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

    tairyoku.append(temp)

print(min(tairyoku))

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

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

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

Solution (Python):



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

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

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

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

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

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

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

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

print(min(phy_list))

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

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

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

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

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

f = 10**100

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

print(f)

Solution (Python):
n=int(input())
jumin=list(map(int,input().split()))

sum=0
energy=[]


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

min=min(energy)
print(min)

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

print(solve())

Solution (Python):
import numpy as np

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

Solution (Python):
import numpy as np

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

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

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

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

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

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

P=round(S/N)

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

print(V)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

print(ans)