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()))
ans = 0
for i in range(min(x),max(x)):
    num = 0
    for j in range(len(x)):
        num += (i-x[j])**2
    if ans == 0:
        ans = num
    elif num < ans:
        ans = num
print(ans)

Solution (Python):
import math
N = int(input())
X = list(map(int, input().split()))
X = sorted(X)
ans = 10**9+7
for i in range(1,100):
    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()))
best = 10**10

for i in range(1, 101):
    num = 0
    for xx in x:
        num += (xx-i)**2
    if num < best:
        best = num

print(best)

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):
def main(N, X):
    def calc_cost(p):
        return sum((x-p)**2 for x in X)

    return min(map(calc_cost, range(max(X) + 1)))


if __name__ == "__main__":
    N = int(input())
    X = list(map(int, input().split()))
    ans = main(N, X)
    print(ans)

Solution (Python):
def cal_cost(X, P):
    cost = 0
    for x in X:
        cost += (x - P) ** 2
    return cost


def main(N, X):
    return min(cal_cost(X, p) for p in range(max(X) + 1))


if __name__ == "__main__":
    N = int(input())
    X = list(map(int, input().split()))
    ans = main(N, X)
    print(ans)

Solution (Python):




from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""













if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip



"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""




def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod
 
    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)
 
def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): 
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def ceil(n, k=1): return n // k + (n % k != 0) 
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) 
def mi(): return map(int, input().split()) 
def li(): return list(map(int, input().split())) 
def lw(): return input().split() 
def lcm(a, b): return abs(a * b) // gcd(a, b) 
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) 
def dd(): return defaultdict(int) 
def ddl(): return defaultdict(list) 
def write(s): return sys.stdout.write(s)


def main():
    
    n=ii()
    x=li()
    l,r=min(x),max(x)
    answer0=float("inf")
    for s in range(l,r+1):
        answer0=min(answer0,sum([(i-s)*(i-s) for i in x]))
    print(answer0)
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""
 
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
 
import os, sys
from io import IOBase, BytesIO
 
BUFSIZE = 8192
 
class FastIO(BytesIO):
    newlines = 0
 
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None
 
    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s
 
    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()
 
    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)
 
 
class IOWrapper(IOBase):
 
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')


 
""" main function"""
 
if __name__ == '__main__':
    main()

Solution (Python):




from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""













if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip



"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""




def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod
 
    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)
 
def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): 
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def ceil(n, k=1): return n // k + (n % k != 0) 
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) 
def mi(): return map(int, input().split()) 
def li(): return list(map(int, input().split())) 
def lw(): return input().split() 
def lcm(a, b): return abs(a * b) // gcd(a, b) 
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) 
def dd(): return defaultdict(int) 
def ddl(): return defaultdict(list) 
def write(s): return sys.stdout.write(s)


def main():
    
    n=ii()
    x=li()
    l,r=min(x),max(x)
    answer0=float("inf")
    for s in range(l,r+1):
        answer0=min(answer0,sum([(i-s)*(i-s) for i in x]))
    print(answer0)
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""
 
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
 
import os, sys
from io import IOBase, BytesIO
 
BUFSIZE = 8192
 
class FastIO(BytesIO):
    newlines = 0
 
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None
 
    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s
 
    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()
 
    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)
 
 
class IOWrapper(IOBase):
 
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')


 
""" main function"""
 
if __name__ == '__main__':
    main()

Solution (Python):
import math
import statistics

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


gra = round(statistics.mean(X))

cost = 0
for i in range(N):
    cost += (X[i] - gra)**2

print(cost)

Solution (Python):
N = int(input())
List = list(map(int, input().split()))
s=10000000000
for p in range(1,101):
    a=0
    for i in List:
        a+=(i-p)**2
    if a<=s:
        s=a
print(s)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
sum = 0
min = n * 10000

for i in range(1,101):
  for j in x:
    sum += (j-i)**2
  if min > sum:
    min = sum
  sum = 0

print(min)

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

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

    mini = float("inf")
    for p in range(1, 101):
        power = 0
        for n in range(N):
            power += (X[n] - p) ** 2
        if power < mini:
            mini = power
    
    print(mini)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
X.sort()
ANS = []
for i in range(X[0],X[len(X)-1]+1):
  k = 0
  for j in range(len(X)):
    k += (i - X[j]) ** 2
  ANS.append(k)
  
print(min(ANS))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
costMin = 9999999999
for locate in range(1, 101):
  cost = 0
  for i in range(N):
    cost += (X[i]-locate)**2
  if cost < costMin:
    costMin = cost
print(costMin)

Solution (Python):
n = int(input())
X = list(map(int,input().split()))
ans = [0]*max(X)

for i in range(1,max(X)+1):
    for j in range(n):
        tmp = abs(i - X[j])**2
        ans[i-1] += tmp

print(min(ans))

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
a = min(X)
b = max(X)
r = 100000000000
for i in range(a,b+1):
  t = (X[0]-i)**2
  for j in range(1,N):
    t += (X[j]-i)**2
  if t < r:
    r = t
print(r)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
j = max(x)
m = 0
y = True

for i in range(n):
    if x[0] != x[i]:
        y = False

if y:
    print(0)
    exit(0)

for p in range(j):
    c = 0
    z = 0
    for i in range(n):
        z = x[i] - p
        c = c + (z * z)
    
    if m == 0:
        m = c
    else:
        if m > c:
            m = c

print(m)

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

p_max = 100
ans_min = 1000000 
for p in range(1, p_max):
    sum_ = 0
    for x in X:
        sum_ += (x - p) ** 2
    ans_min = min(sum_, ans_min)
print(ans_min)

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

x_max = 100
ans_min = 1000000
for p in range(x_max):
    sum_ = 0
    for x in X:
        sum_ += (x - p) ** 2
    ans_min = min(sum_, ans_min)
print(ans_min)

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

Solution (Python):
import math
import numpy as np
N = int(input())
X = list(map(int,input().split()))
P = np.round(np.average(X))

print(int(np.dot(X,X) + P * P * N - 2 *np.sum(X)*P))

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

P = []
for i in range(1,101):
    P.append(sum([(X[x]-i)**2 for x in range(N)]))

print(min(P))

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

min_hp = float('inf')

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

print(min_hp)

Solution (Python):

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

a = round(sum(L) / len(L))
ans = 0

for i in L:
    ans += (a - i)**2

print(ans)

Solution (Python):
import numpy as np
n=int(input())
y=np.array(list(map(int,input().split())))
n=int(round(np.average(y)))
yy=(y-n)**2
print(np.sum(yy))

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

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 x:
        tmp+=(j-i)**2
    if tmp<ans:
        ans=tmp
print(ans)

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

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

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

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

MaxNum = max(x)

SumEnergy = 0
ans = (100**2)*100

for p in range(-MaxNum, MaxNum+1):
    for a in range(n):
        SumEnergy += (x[a] - p)**2
    ans = min(ans, SumEnergy)
    SumEnergy = 0

print(ans)

Solution (Python):
import math

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

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

result = 10**18
for i in range(L, R + 1):
    cost = 0
    for j in X:
        distance = (j - i)**2
        cost += distance
    result = min([result, cost])

print(result)

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

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


L=min(X)
H=max(X)
smallest = 10**18
for p in range(L,H+1):
  sum=0
  
  for j in range(N):
    sum=sum+(X[j]-p)**2
  
  if sum<=smallest:
    smallest=sum

print(smallest)

Solution (Python):
import math
N=int(input())
ls=list(map(int,input().split()))
av=math.floor(sum(ls)/N)
A=B=0
for i in range(N):
  A+=(ls[i]-av)**2
  B+=(ls[i]-av-1)**2
print(min([A,B]))

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

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

Solution (Python):
import sys

n = int(input())
x = list(map(int, input().split()))
sum = []
for y in range(min(x), max(x)+1):
  su = 0
  for m in range(n):
    su += (x[m]-y)**2
  sum.append(su)
print(min(sum))

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

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

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

md = int(sum(x)/n+.5)
num = 0
for i in x:
    num += (abs(i-md))**2
print(num)

Solution (Python):
import collections

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

x = collections.Counter(X)

N = len(x)
s = min(list(x.keys()))
e = max(list(x.keys()))

xl = list(x)

m = [0]*(e+1-s)

for i in range(s, e+1):
    p = 0
    for j in range(N):
        p += pow(xl[j]-i,2) * x[xl[j]]
    m[i-s] = p

print(min(m))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
res=10**6
for i in range(1,101):
  tmp = sum([(i-y)**2 for y in x])
  if res > tmp:
    res = tmp
print(res)

Solution (Python):
N = int(input())
X = sorted([int(i) for i in input().split()])
R = 1000000
for c in range(X[0], X[-1]+1):
    if sum((c-X[i])**2 for i in range(N)) < R:
        R = sum((c-X[i])**2 for i in range(N))
    else:
        pass
print(R)

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

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


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
mn = float("INF")
ans = 0
for p in range(min(x), max(x)+1):
  score = sum([(xx - p)**2 for xx in x])
  if mn > score:
    ans = p
    mn = score
print(mn)

Solution (Python):
import numpy as np
n=int(input())
X=list(map(int,input().split()))
X=np.array(X)
ans=10**100
for i in range(1,101):
  tmp=np.sum((X-i)**2)
  if tmp<ans:
    ans=tmp
print(ans)

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

ans = 10 ** 7
for i in range(1,MaxX+1):
    cost = 0
    for j in range(len(X)):
        cost += abs(X[j] - i) ** 2
    
    ans = min(ans, cost)

print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
a = min(x)
b = max(x)
ans  = 10**9

for i in range(a, b+1):
    s = 0
    for j in x:
        s += (j-i)**2

    ans = min(ans, s)
print(ans)

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

a = list(map(int, input().split()))
ave = int(sum(a))/len(a)
total0, total1 = 0, 0
for i in a:
    total0 += (i-int(ave+1))**2
    total1 += (i-int(ave))**2
print(min(total0, total1))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
min_cost = 10000000
cost = 0

for i in range(min(X), max(X)+1):  
    for k in range(N):  
        cost += (i - X[k]) ** 2
    min_cost = min(min_cost, cost)
    cost = 0

print(min_cost)

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
sum=[]
for y in range(min(x),max(x)+1):
  su=0
  for m in range(n):
    su+=(x[m]-y)**2
  sum.append(su)
print(min(sum))

Solution (Python):
n =int(input())
xi = list(map(int,input().split()))
min_kyo = 0
for house in xi:
  min_kyo += (1 - house)**2
  
for i in range(2,max(xi)+1):
  kyori = 0
  for house in xi:
    kyori += (i - house)**2
  if kyori < min_kyo:
    min_kyo = kyori
    
print(min_kyo)

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

cost = [0] * 100
for p in range(100):
    for x in X:
        cost[p] += (x-p) ** 2

ans = min(cost)
print(ans)

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

y = list(set(x))
y.sort()

ans = 10**18
for p in range(min(y), max(y)+1):
   tmp = [(x[i]-p)**2 for i in range(n)]
   ans = min(ans, sum(tmp))

print(ans)

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

Solution (Python):

n, *x = map(int, open(0).read().split())
ans = 1000000000000000000000000
for i in range(100):
    a = 0
    for j in x:
        a += (j-i)**2
    ans = min(ans, a)
print(ans)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
x.sort()
min = 10**15
su=0
for j in range(x[0],x[n-1]):
    for i in x:
        su=(i-j)**2+su  
    if min>su:
        min=su
    su = 0
if min==10**15:
    print(0)
else:
    print(min)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
sigma = [0]*(101)
for p in range(101):
    for i in range(N):
        sigma[p] += (X[i]-p)**2
print(min(sigma))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
a=sum(X)//N
b=sum(X)//N+1
ans1=0
ans2=0

for i in range(N):
  ans1+=(X[i]-a)**2
  ans2+=(X[i]-b)**2
print(min(ans1,ans2))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
temp = 0
result = float("inf")
for j in range(1,101):
    temp = 0
    for k in range(N):
        temp += ((X[k] - j) ** 2)
    result = min(temp, result )
print(result)

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

select=len(S)
goukei=10**10
for i in range(1,100):
    kouho=0
    for j in range(select):
        kouho+=(S[j]-i)**2
    
    if kouho<goukei:
        goukei=kouho
    
print(goukei)

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

print(min(result))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
m = max(X)
res = float('Inf')
for m in range(1, m+1):
    total = 0
    for n in range(N):
        total += (X[n] - m)**2
    if res > total:
        res = total
print(res)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
m = max(X)
res = float('Inf')
for m in range(1, m+1):
    total = 0
    for n in range(N):
        total += (X[n] - m)**2
    if res > total:
        res = total
print(res)

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
INF = float("inf")
minimum = INF
for x in range(100):
    sum = 0
    for i in range(N):
        sum += (x - X[i])**2
    minimum = min(sum, minimum)
print(minimum)

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

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

Solution (Python):


N = int(input())
X = list(map(int,input().split()))
judge = float('inf')
for i in range(1,101):
    p = i
    tmp = 0
    for j in range(N):
        tmp += (X[j]-p)**2
    if tmp < judge:
        judge = tmp
        ans = tmp
        
print(ans)

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

P = int(X.sum()/N)

if ((X-P)**2).sum() < ((X-(P+1))**2).sum():
    ans = ((X-P)**2).sum()
else:
    ans = ((X-(P+1))**2).sum()

print(ans)

Solution (Python):
def ans(p, x):
    a = 0
    for i in x:
        a += (i - p)**2
    return a

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

p = sum(x)//n

print(min(ans(p, x), ans(p+1, x)))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
minhp=10000001
for i in range(1,101):
    hp=0
    for hu in X:
        hp+=(hu-i)**2
    minhp=min(minhp,hp)
    
print(minhp)

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

Y = sum(X)/len(X)
Y_floor = sum(X)//len(X)
Y_ceil = Y_floor+1
if  abs(Y-Y_floor)>=abs(Y-Y_ceil):
    Z=Y_ceil
else:
    Z = Y_floor

counter = 0 
for i in X:
    counter += (i-Z)**2

print(counter)

Solution (Python):
def C():
    n = int(input())
    x = list(map(int, input().split()))
    res = []
    for p in range(min(x), max(x)+1):
        psum = 0
        for i in x:
            psum += (i-p)**2
        res.append(psum)
    print(min(res))
C()

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

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

if __name__ == '__main__':
    main()

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 = [int(i) for i in input().split()]
ans = []

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

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

ans = 0

for i in range(x[0]+1, x[-1]+1):
    sum = 0
    for item in x:
        sum += pow(item-i, 2)

    if sum < ans or ans == 0:
        ans = sum

print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
avr = int(sum(X)/N)
avr1 = avr + 1
cnt = 0
cnt1 = 0
for i in range(N):
    cnt += (X[i] - avr)**2 
    cnt1 += (X[i] - avr1)**2 
print(min(cnt,cnt1))

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
avr = int(sum(X)/N)
avr1 = avr + 1
cnt = 0
cnt1 = 0
for i in range(N):
    cnt += (X[i] - avr)**2 
    cnt1 += (X[i] - avr1)**2 
print(min(cnt,cnt1))

Solution (Python):
import numpy as np
import math

n = int(input())
x = np.array(list(map(int, input().split())))
mean_x = x.mean()
if sum((x - math.ceil(mean_x))**2) >= sum((x - math.floor(mean_x))**2):
    print(sum((x - math.floor(mean_x))**2))
else:
    print(sum((x - math.ceil(mean_x))**2))

Solution (Python):
N=int(input())
Xs=list(map(int,input().split()))
ans=10**18
for i in range(0,101):
    cnt=0
    for m in Xs:
        cnt+=(i-m)**2
    ans= min(cnt,ans)
print(ans)

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

Solution (Python):
def WorkloadCalculation(arr,P):
    D=0
    for a in range(len(arr)):
        d=abs(arr[a]-P)
        D += d**2
    return D

N=int(input())
Xlist=[]
X=input().split()
for x in X:
    _x=int(x)
    Xlist.append(_x)

Xlist.sort()
P=Xlist[0]

workload=10000000
STOPflg=False
    
while STOPflg==False:
    _wl=WorkloadCalculation(Xlist,P)
    if _wl < workload:
        workload=_wl
        P+=1
    else:
        print(workload)
        STOPflg=True
        exit()
        
print(workload)

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

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

print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
X = sorted(X)
minx = X[0]
maxx = X[-1]

ans = 10 ** 9 + 7
for i in range(minx, maxx + 1):
    temp = 0
    for j in range(N):
        temp += (i - X[j]) ** 2
    ans = min(ans, temp)
print(ans)

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

Solution (Python):
import decimal
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def my_round(val, digit=0):
    p = 10 ** digit
    return (val * p * 2 + 1) // 2 / p


n, *x = map(int, read().split())
ave = int(my_round(sum(x) / len(x)))
l = [(y - ave) ** 2 for y in x]
print(sum(l))

Solution (Python):
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

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

    ans = 0
    p = round(sum(X)/n)
    for i in range(n):
        ans += (X[i]-p)**2
    print(ans)


if __name__ == '__main__':
    main()