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().strip().split()))

def min_energy(N,X):
    min_e=100000000
    for l in range(max(X)+1):
        e=0
        for n in range(N):
            e+=(X[n]-l)**2
        if min_e>=e:
            min_e=e
    return min_e

print(min_energy(N,X))

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, X: "List[int]"):
    ans = INF
    for i in range(1, 101):
        cost = sum([(i-X[j])**2 for j in range(N)])
        ans = min(ans, cost)

    print(ans)
    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):
N = int(input())
Xlist = list(map(int, input().split()))
ans = 10**9
for p in range(min(Xlist), max(Xlist)+1):
    cost = 0
    for x in Xlist:
        cost += (x - p)**2
    ans = min(ans, cost)
print(ans)

Solution (Python):
a=int(input())
x=input().split()
x=list(map(int,x))
x=sorted(x)
l=[]
for i in range(x[0]-1,x[-1]+1):
    d = 0
    for j in x:
        c=(j-i)**2
        d=d+c
    l.append(d)
print(sorted(l)[0])

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

m = 10 ** 6
for p in range(1,100):
    s = 0
    for i in range(N):
        s += (p-X[i])**2
    m = min(m,s)

print(m)

Solution (Python):
import numpy as np
N=int(input())
X=np.array(list(map(int,input().split())))
ans=sum(X**2)
for i in range(min(X)-1,max(X)+1):
    Z=sum(X**2)-sum(2*X*i)+N*i**2
    ans=min(Z,ans)
print(ans)

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

mina, maxa = X[0], X[N-1]

ans = (maxa ** 2) * len(X)
for i in range(mina, maxa+1):
  sum = 0
  for j in range(len(X)):
    sum += (X[j] - i) ** 2
  ans = min(ans, sum)
  
print(ans)

Solution (Python):
n = int(input())
x_li = list(map(int, input().split()))
x_li.sort()
hp_min = -1

for i in range(x_li[0], x_li[n-1] + 1):
    hp = sum((x - i)**2 for x in x_li)
    if hp < hp_min or hp_min == -1:
        hp_min = hp

print(hp_min)

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

ans = 10**7
for P in range(1, 101):
    c = 0
    for x in X:
        c += (x-P)**2
    ans = min(ans, c)

print(ans)

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

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

l = min(xs)
r = max(xs)

costs = []
for i in range(l-1, r+1):
    cost = 0
    for j in xs:
        cost += (j - i) * (j - i)
    costs.append(cost)

print(min(costs))

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

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

l = min(xs)
r = max(xs)

costs = []
for i in range(1, 100):
    cost = 0
    for j in xs:
        cost += (j - i) * (j - i)
    costs.append(cost)

print(min(costs))

Solution (Python):
input()
xs = list(map(int,input().split()))
x_min = min(xs)
x_max = max(xs)
diss = []
for p in range(x_min,x_max+1):
    diss.append(sum([(p-x)**2 for x in xs]))
print(min(diss))

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

Solution (Python):
import math
n = int(input())
x = list(map(int, input().split()))
p = 0
ans = 0

s = sum(x)/n
a = math.floor(s)
b = math.ceil(s)

if (a-s)**2 > (b-s)**2:
    p = b
else:
    p = a

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

print(ans)

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

result = 10**6

for p in range(min(add),max(add)+1):
    sum = 0
    for i in range(n):
            sum += (p - add[i])**2
    if sum <= result:
        result = sum

print(result)

Solution (Python):
N = int(input())
K = sorted(map(int, input().split()))

for i in range(1,101):
  data1 = map(lambda x: (i-x)**2, K)
  sum_dis = sum(list(data1))
  if i == 1:
    min_min = sum_dis
  if min_min > sum_dis:
    min_min = sum_dis
print(min_min)

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ans = float("inf")
for p in range(1, max(X)+1):
    x_sum=0
    for x in X:
        x_sum+=(x-p)**2
    ans = min(ans, x_sum)
print(ans)

Solution (Python):


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

P = round(sum(X) / N)

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

print(ans)

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

def f(i,X):
  sumf=0
  for j in X:
    sumf+=(j-i)**2
  return sumf

for i in range(min(X),max(X)+1):
  sum=min(sum,f(i,X))

print(sum)

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

Solution (Python):
N,*X=map(int,open(0).read().split());print(sum(map(lambda x:(round(sum(X)/N)-x)**2,X)))

Solution (Python):
N,*X=map(int,open(0).read().split());print(int(sum(map(lambda x:(round(sum(X)/N,0)-x)**2,X))))

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

Solution (Python):
N = int(input())
coordinate = list(map(int, input().split()))
result = 0
resultl = 0
 
for j in range(N):
    result += (1-coordinate[j])**2
    
for i in range(1,101):
    for k in range(N):
        resultl += (i-coordinate[k])**2
 
    if resultl < result:
        result = resultl
    resultl = 0
    
print(result)

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

chk = []
hp = 0

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

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

p = int(round(sum(X) / N) )

ans = sum([(x-p)**2 for x in X])

print(ans)

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

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

print(sum((x-P)**2 for x in X))

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

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
ans=float('inf')
p=0
for i in range(1,100):
    for k in range(N):
        p+=((X[k]-i)**2)
    ans=min(ans,p)
    p=0
print(ans)

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
X = [int(_) for _ in stdin.readline().rstrip().split()]
ans = float('inf')
for i in range(1, 100):
    a = 0
    for x in X:
        a += (x-i)*(x-i)
    ans = min(ans, a)
print(ans)

Solution (Python):


n = int(input())
xl = input().split()

listx = []
for i in xl:
  yy = int(i)
  listx.append(yy)
  
def hp(a,b):
  goh = 0
  for i in a:
    hp = (i - b)**2
    goh += hp
    
  return goh

xmax = max(listx)
xmin = min(listx)
listhp = []
for p in range(xmin,xmax + 1):
  hq = hp(listx,p)
  listhp.append(hq)
  
ans = min(listhp)
print("{}".format(ans))

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

ans = float('inf')

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

print(ans)

Solution (Python):
N = int(input())
Xi = list(map(int,input().split()))
tairyoku = 10000000
for p in range(1,100+1,1):
  tmp = 0
  for x in Xi:tmp = tmp + (p-x)*(p-x)
  if tmp < tairyoku:
    tairyoku = tmp
print(tairyoku)

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

p = round(sum(x) / n)

cost = 0
for i in x:
    cost += (i - p) ** 2

print(cost)

Solution (Python):
n=input()
l=list(map(int,input().split()))
ans=99999999
for a in range(100):
    s=0
    for b in l:
       s+=(b-a)**2
    if ans>s:
        ans=s
print(ans)

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

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

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

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

def calc_cost(p):
    cost = 0
    for i in range(N):
        cost += (x_list[i] - p)**2
    return cost

ans = 9999999999
for x in range(101):
    ans = min(ans, calc_cost(x))
print(ans)

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

sum = 0
numList = []
p = 0
for pi in range(100):
    for xi in range(len(x)):
        sum += (x[xi] - pi ) ** 2
    numList.append(sum)
    sum = 0
print(min(numList))

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

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

ans = []
P = 100
while P > 0:
    a = 0
    for x in X:
        a += (x - P) ** 2
    ans.append(a)
    P -= 1
print(min(ans))

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



stamina = []
for i in range(1, 100):
    s = 0
    for ii in X:
        s = s + ((ii - i) ** 2)
    stamina.append(s)

print(min(stamina))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
min_ans = +float('inf')

for i in range(1, 100):
    ans = 0
    for x in X:
        ans += (x - i)**2
    min_ans = min([min_ans, ans])

print(min_ans)

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

y = sum(x)
y /= n
p = round(y)

for i in x:
    i -= p
    i *= i
    count += i
    

print(count)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
print(min(sum((x - P) ** 2 for x in X) for P in range(max(X) + 1)))

Solution (Python):
N = int(input())
X = tuple(sorted(map(int, input().split())))
print(min(sum((x - p)**2 for x in X) for p in range(X[0], X[-1]+1)))

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

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

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

minV = float('inf')
for i in range(1, 100 + 1):
    temp = 0
    for j in range(N):
        temp += (i - X[j]) ** 2
    minV = min(minV, temp)

print(minV)

Solution (Python):
n = int(input())
li = list(map(int, input().split()))
res = 1e9
j = 1
while j <= 100:
    r = 0
    for i in li:
        r += (i - j)**2
    res = min(res, r)
    j += 1
print(res)

Solution (Python):


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


ans = 100*100*100
for i in range(101):
    sum = 0
    for x in xl:
        sum += (i-x)*(i-x)
    ans = min(ans, sum)

print(ans)

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()
x = na()
minx = min(x)
maxx = max(x)
ans = 10 ** 9 + 7
for i in range(minx, maxx+1):
    tmp = 0
    for j in range(n):
        tmp += (i-x[j])**2
    ans = min(tmp, ans)
print(ans)

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




minX, maxX = min(X), max(X)
min_cost = 1e10

for p in range(minX, maxX + 1):
    cost = sum([(x - p) ** 2 for x in X])
    min_cost = min(min_cost, cost)

print(min_cost)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ans = float('inf')
energy = []

for i in range(1, 101):
    for j in x:
        energy.append((j - i) ** 2)
    sum_energy = sum(energy)
    if sum_energy < ans:
        ans = sum_energy
    energy = []

print(ans)

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

ans = 10**9+7
for i in range(min(x),max(x)+1):
    tmp=0
    for j in x:
        tmp+=(i-j)**2
    ans = min(ans,tmp)
print(ans)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n = I()
    x = LI()
    ans = 0
    p = round(sum(x)/n)
    for i in range(n):
        ans += ((x[i]-p)**2)
    print(ans)
    return



if __name__ == "__main__":
    solve()

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

avg = round(sum(x) / n)

ans = 0

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

print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ans = 100000000
for n in range(1, 100+1):
    tmp = 0
    for x in X:
        tmp += pow((x-n), 2)
    if ans > tmp:
        ans = tmp

print(ans)

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

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

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

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



ans = 0
for i in a:
  ans += (i - ave)**2
  
print(ans)

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

ans = float('inf')
for p in range(min(x), max(x)+1):
    tmp = 0
    for x_ in x:
        tmp += (x_ - p) ** 2
    ans = min(ans, tmp)

print(ans)

Solution (Python):
import math

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


for p in range(min(x), max(x)+1):
    hp = 0
    for j in range(n):
        hp += (x[j] - p)**2
    if p == min(x):
        hpmin = hp
    elif hp < hpmin:
        hpmin = hp

print(hpmin)

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP

N = int(input(''))
list = input('').split(' ')
list = [int(n) for n in list]
mean = Decimal(str(sum(list) / len(list)))
mean = mean.quantize(Decimal('0'), rounding=ROUND_HALF_UP)
out = 0
for i in range(N):
    out += (list[i] - mean) ** 2
print(out)

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

answer = float("inf")
for p in range(1, 101):
    stamina = 0
    for x in X:
        stamina += (x - p)**2
    if stamina < answer:
        answer = stamina

print(answer)

Solution (Python):
import math
n = int(input())
xs = list(map(int, input().split()))

p = sum(xs) / len(xs)
x1 = sum([(x - math.floor(p)) ** 2 for x in xs])
x2 = sum([(x - math.ceil(p)) ** 2  for x in xs])
print(min(x1, x2))

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

for p in range(min(x), max(x)+1):
  hp = 0
  for j in range(n):
    hp += (x[j]-p) ** 2
  if p == min(x):
    ans = hp
  elif ans >= hp:
    ans = hp

print(ans)

Solution (Python):
import math

n = int(input())
l = list(map(int,input().split()))
y = sum(l)
x = y//n
x1 = math.ceil(y/n)
sum1 = 0
sum2 = 0
for i in l:
  sum1 += (i-x)**2
  sum2 += (i-x1)**2
print(min(sum1,sum2))

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

s=0
for j in range(N):
  s=s+i[j]
p=round(s/N,0)

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

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

def E_sum(p):
    e_sum = 0
    for i in range(n):
        y = (x[i] - p)**2
        e_sum += y
    return e_sum

m = float("inf")
for j in range(1, 101):
    tmp = E_sum(j)
    if tmp < m:
       m = tmp

print(m)

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

Solution (Python):
n = int(input())
x_lst = list(map(int, input().split()))
mini = 1000000
for x in range(1, 101):
    power = 0
    for i in range(n):
        power += (x_lst[i] - x) ** 2
    if power < mini:
        mini = power
print(mini)

Solution (Python):
import sys
input = sys.stdin.readline

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

    ans = int(1e10)

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


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
min = 100000000000
for p in range(1,101):
  cnt = 0
  for x in li:
    cnt += (x-p)**2
  if cnt < min:
    min = cnt
print(min)

Solution (Python):
import numpy as np

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

print(min([np.sum((X - p) ** 2) for p in range(1,101)]))

Solution (Python):
import math


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

tmp = []
tmp.append(math.floor(sum(X)/N))
tmp.append(math.ceil(sum(X)/N))


ans = []
for val in tmp:
  S = 0
  for p in X:
    S += (p-val) ** 2
  
  ans.append(S)


print(min(ans))

Solution (Python):
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd



import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    n = int(input().strip())
    x = list(map(int, input().strip().split()))
    x.sort()
    ans = sys.maxsize
    for d in range(x[0], x[-1]+1):
        ans = min(sum([(x[i] - d) ** 2 for i in range(n)]), ans)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from functools import reduce
from operator import add
input = sys.stdin.readline

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

    ans = float('INF')
    for i in range(1, 101):
        power = reduce(add, map(lambda x: (x - i) ** 2, X))

        ans = min(ans, power)

    print(ans)


if __name__ == "__main__":
    main()

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

list2 = []

o= len(list)
new_list = sorted(list)
max = new_list[o-1]

for i in range(max+1):
    t = sum((i-k)**2 for k in list)
    list2.append(t)

list3 = sorted(list2)

print(list3[0])

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X.sort()
res = 10**9
for i in range(X[0], X[-1]+1):
  n = 0
  for x in X:
    n += (x-i)**2
  res = min(n, res)
print(res)

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

min_w = -1
for p in range(0, 101):
    w = 0
    for x in xs:
        w += pow(x - p, 2)
    if min_w == -1:
        min_w = w
    else:
        if min_w > w:
            min_w = w
print(min_w)

Solution (Python):
import numpy as np
import math
N = int(input())
X_k = list(map(int , input().split(" ")))

P = float(sum(X_k)/N)
P_ceil = int(math.ceil(P))
P_floor= int(math.floor(P))

ceil_sum = 0
floor_sum = 0

for X in X_k:
    ceil_sum = ceil_sum + (P_ceil-X)*(P_ceil-X)
    floor_sum = floor_sum + (P_floor-X)*(P_floor-X)


if (ceil_sum-floor_sum > 0):
    print(floor_sum)
else:
    print(ceil_sum)

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

energy = np.sum((X - X[0])**2)

X_max,X_min = np.max(X),np.min(X)
for i in range(X_min,X_max):
    energy_sum = np.sum((X-i)**2)
    if energy > energy_sum:
        energy = energy_sum

print(energy)

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

def solve(N, X):
    m = 10e10
    for x in range(100):
        c = sum((p - x)**2 for p in X)
        if c < m:
            m = c
    return m
print(solve(N, X))

Solution (Python):
N = int(input())
x = list(map(int, input().split()))
p = int(sum(x)/N)
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
sum=0
for x in X:
    sum+=x

sum//=N
ans1=0
ans2=0
for x in X:
    ans1+=(x-sum)*(x-sum)
    ans2+=(x-sum-1)*(x-sum-1)
print(min(ans1,ans2))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
P=0
Sum=0
l=[]

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

Solution (Python):
n = input()
lst = tuple(map(int, input().split()))
res = 10000*100
for i in range(1, 101):
  res = min(res, sum((i-e)**2 for e in lst))
print(res)

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

l, r = min(xx), max(xx)
ans = float("inf")
for i in range(l, r+1):
    ans = min(ans, sum([(i - x)**2 for x in xx]))
print(ans)

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

m = sum(xx) // len(xx)
left = sum([(m - i)**2 for i in xx])
right = sum([(m + 1 - i)**2 for i in xx])
print(min(left, right))

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

min_x = min(x)
max_x = max(x)

power = []
for i in range(100):
    power.append(i*i)

result = 999999
for i in range(min_x, max_x+1):
    count = 0
    for j in range(n):
        count = count + power[abs(i - x[j])]
    if(result > count):
        result = count

print(result)

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

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

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

ta = 10**7

for i in range(min(X), max(X)+1):
    ta = min(ta, sum([(X[j]-i)**2 for j in range(N)]))
    
print(ta)

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

min_res = float("inf")
for i in range(1, 101):
    res = sum((xi - i) ** 2 for xi in x)
    min_res = min(min_res, res)

print(min_res)

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

min_a = X[0]
max_a = X[-1]

sum_min = 0
sum_max = 0
    
def calc(x, min, max):
    mid = (min + max) // 2
    sum_min = 0
    sum_max = 0
    for value in x:
        sum_min += (value - min) ** 2
        sum_max += (value - max) ** 2
    
    if abs(min - max) <= 1:
        if sum_min < sum_max:
            return int(sum_min)
        else:
            return int(sum_max)
    elif sum_min < sum_max:
        return calc(x, min, mid)
    else:
        return calc(x, mid, max)
    
    return -1
    
ans = calc(X, min_a, max_a)
print(ans)

Solution (Python):

import sys


def solve(N: int, X: "List[int]"):
    X.sort()
    m = 10000000
    for p in range(X[0], X[-1] + 1):
        s = 0
        for x in X:
            s += (x - p) ** 2
        if s < m:
            m = s

    print(m)



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):
N = input()
N = int(N)
K= list(map(int, input().split()))
import numpy as np
answers = []
ave = sum(K)//len(K)
sqrtMax = int(np.sqrt(max(K)))
rngMin = ave - sqrtMax
for p in range(rngMin,rngMin+2*sqrtMax):
    ans = 0
    for k in K:
        ans += ((k-p)**2)
    answers.append(ans)
print(min(answers))

Solution (Python):

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


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

ans = float('inf')
for i in range(L, R+1):
    cost = 0
    for x in X:
        cost += (x-i)**2
    
    if cost < ans:
        ans = cost


print(int(ans))

Solution (Python):
outnum = 1000000
human_sum = int(input())
basyo_list = list(map(int, input().split()))
for i in range(1,101):
  total_sum = 0
  for j in range(human_sum):
    total_sum = total_sum + (i - basyo_list[j]) ** 2
  if total_sum <= outnum:
    outnum = total_sum
print(outnum)

Solution (Python):
N = int(input())
x_list = [int(i) for i in input().split()]
x_list.sort()
hp = 10 ** 6
for p in range(x_list[0], x_list[len(x_list) - 1] + 1):
  hp_p = 0
  for x in x_list:
    hp_p += (x - p) ** 2
  if hp_p < hp:
    hp = hp_p
print(hp)

Solution (Python):
N = int(input())
Xlist = list(map(int,input().split()))
Xlist.sort()
wat = 2**100
for p in range(Xlist[0],Xlist[-1]+1):
  nwat = 0
  for x in Xlist:
    nwat += (x-p)**2
  if nwat < wat:
    wat = nwat
print(wat)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ans = 2**60
for i in range(101):
    tmp = 0
    for j in range(N):
        tmp += (X[j] - i)**2
    if(tmp < ans): ans = tmp
print(ans)

Solution (Python):
def main():
    N = int(input())
    xlist = list(map(int, input().split()))
    x_min = min(xlist)
    x_max = max(xlist)
    min_sum_value = 10**15
    
    for p in range(100):
        c = 0
        for i in xlist:
            c += (i - p) ** 2
        if min_sum_value > c:
            min_sum_value = c
    print(min_sum_value)

main()

Solution (Python):







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

base = x[0]
min = 10 ** 9
for _ in range(x[n-1] - x[0] + 1):
    dist = sum((base - x[j])**2 for j in range(n))
    min = dist if dist <= min else min
    base += 1

print(min)

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

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

Solution (Python):

N = int(input())
X_list = [int(x) for x in input().split() ]
ans = 1000000

for p in range(1,101):
  temp = 0
  for x in X_list:
    temp += (x-p)**2
  ans = min(ans, temp)

print(ans)

Solution (Python):
def main():
    n = int(input())
    x = list(map(int, input().split()))
    
    ans_tmp = 10000000000000
    for j in range(100):
        ans = 0
        for i in x:
            ans += (i-(j+1))**2

        if ans_tmp >= ans:
            ans_tmp = ans
    
    print(ans_tmp)

if __name__ == '__main__':
    main()

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

Solution (Python):
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
N = int(input())
X  = list(map(int,input().split()))

b = 0 
c = 0 
for x in X:
    b = b -2 * x
    c = c + x * x 

u = int (float (-b) / float(2* N) + 0.5 )


s = N * u ** 2 + b * u + c
print(s)

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

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

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

for i in range(100):
    power = 0
    for j in x:
        power += (i-j)**2
    
    if power < min:
        min = power

print(min)

Solution (Python):

def submit():
    n = int(input())
    xlist = list(map(int, input().split()))

    def cost(lst, p):
        c = 0
        for l in lst:
            c += (l - p) * (l - p)
        return c

    sum_x = sum(xlist)
    if sum_x % n:
        p1 = sum_x // n
        p2 = sum_x // n + 1
        print(min(cost(xlist, p1), cost(xlist, p2)))
    else:
        print(cost(xlist, sum_x // n))


if __name__ == "__main__":
    submit()

Solution (Python):
import math
def solve():
    n=int(input())
    x=list(map(int,input().split()))
    
    ave=0
    sum=0
    for i in range(len(x)):
        sum+=x[i]
    ave=sum/len(x)
    if ave>math.floor(ave)+0.5:
        pre=math.ceil(ave)
    else:
        pre=math.floor(ave)
    ans=0
    for i in range(len(x)):
        ans+=(x[i]-pre)**2
    print(ans)
    
solve()

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

ans = []
for i in range(n+100):
    total = 0
    for j in range(n):
        diff = ((i+1)-X[j])**2
        total += diff
    ans.append(total)
print(min(ans))

Solution (Python):
def resolve():
    N = int(input())
    X = list(map(int, input().split()))
    P = int(sum(X)/N+0.5)
    print(sum(map(lambda Xi: (Xi-P)**2, X)))

resolve()

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

n = sum(lst)//N

ans = 0
ans2 = 0
for i in lst:
    ans += (i-n)**2
    ans2 += (i-n-1)**2

print(min(ans, ans2))

Solution (Python):
n = int(input())
number = list(map(int, input().split()))
a = sum(number)
g0 = a//n
g1 = a/n
if g1-g0 >= g0+1 - g1:
  g = g0+1
else:
  g = g0

ans = []
for i in range(n):
  l = (number[i] - g)**2
  ans.append(int(l))
print(sum(ans))