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):
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
X = read_int()

def solve():
    ans = float('INF')
    m = max(X)
    for i in range(1, m + 1):
        res = 0
        for x in X:
            res += (i - x) ** 2
        ans = min(res, ans)
    return ans

if __name__ == "__main__":
    print(solve())

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

ans = 1000000

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

Solution (Python):
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

N = int(input())
X = list(map(int, input().split()))
ans = 1000000000
for i in range(1, 101):
    sum = 0
    for x in X:
        sum += (x - i) * (x - i)
    ans = min(sum, ans)

print(ans)

Solution (Python):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
X=many_int()

X_min=min(X)
X_max=max(X)

ans=0
mins=10**8
for i in range(X_min, X_max+1):
    now_min=0
    for x in X:
        now_min += (x-i)**2
    
    if now_min < mins:
        mins = now_min
        ans = i

print(mins)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X):
    ans = INF
    for i in range(1, 100):
        t = 0
        for x in X:
            t += (x-i)**2
        ans = min(ans, t)
    return ans


def main():
    N = read_int()
    X = read_int_n()
    print(slv(N, X))


if __name__ == '__main__':
    main()

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

ans = float("inf")
for i in range(100):
    temp = 0
    for xx in x:
        temp += (xx - i) ** 2

    ans = min(ans, temp)

print(ans)

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

ans = 1 << 30
for p in range(1, 101):
    sum = 0
    for x in X:
        sum += (x - p) ** 2
    ans = min(ans, sum)

print(ans)

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

ans = 10**20

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

print(ans)

Solution (Python):

import collections
import itertools as it
import math
import numpy as np









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

ans = 9999999999999
for p in range(1, max(X)+1):
    sum_ = 0
    for i, x in enumerate(X):
        sum_ += (x - p) ** 2

    if ans > sum_:
        ans = sum_

print(ans)

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

p = sum(lst)/n
p1 = int(p)
p2 = math.floor(p)
p3 = math.ceil(p)

res = []
tmp = 0
for i in range(n):
    tmp += (lst[i] - p1)**2
res.append(tmp)
tmp = 0
for i in range(n):
    tmp += (lst[i] - p2)**2
res.append(tmp)
tmp = 0
for i in range(n):
    tmp += (lst[i] - p3)**2
res.append(tmp)
print(min(res))

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

Solution (Python):
import math

N=int(input())
X=list(map(int, input().split()))
ans=sum(X)/N
p1=math.ceil(ans)
p2=math.floor(ans)
s1=0
s2=0
for i in range(N):
    s1+=(X[i]-p1)**2
    s2+=(X[i]-p2)**2
print(min(s1, s2))

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

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

p_ave1 = sum(positions) // n
p_ave2 = sum(positions) // n + 1

stamina1 = sum([(p - p_ave1) * (p - p_ave1) for p in positions])
stamina2 = sum([(p - p_ave2) * (p - p_ave2) for p in positions])

print(min(stamina1, stamina2))

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

wa = 0
wa2 = 0
for i in range(n):
    X[i] = int(X[i])
    wa = wa + X[i]
    wa2 = wa2 + X[i]*X[i]
    
y = round(wa/n)

print( wa2 - 2*y*wa + n*y*y )

Solution (Python):

n = int(input())

lst1 = list(map(int,input().split()))
ans = 10**9
for i in range(1,101):
    res = 0
    for j in lst1:
        res += (j-i)**2
    ans = min(res,ans)

print(ans)

Solution (Python):
import numpy as np

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

ans = 10 ** 18 + 100
for p in range(1, 101):
    ans = min(ans, sum((X - p) ** 2))
print(ans)

Solution (Python):
n = int(input())
xs = [int(x) for x in input().split()]
mn,mx = min(xs), max(xs)
mv = n * (mx - mn) ** 2
for i in range(mn, mx + 1):
    mv = min(mv, sum((xs[j] - i) ** 2 for j in range(n)))
print(mv)

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

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

ans=float('inf')
for i in range(1,101):
    res=0
    for x in X:
        res+=(i-x)**2
    if ans>res:
        ans=res
print(ans)

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

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

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
cost = 10**9
for i in range(100):
  t = sum([(j-i)**2 for j in x])
  if t < cost:
    cost = t
print(cost)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ans = 0
num = sum(X) // N
if (sum(X) / N - sum(X) // N >= 0.5): num += 1
for i in range(len(X)):
    ans += (X[i] - num) ** 2
print(ans)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
m = min(x)
M = max(x)
ans=10000000000
for i in range(m,M+1):
    sum=0
    for j in x:
        sum+=(j-i)**2
    if sum < ans:
        ans = sum
print(ans)

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

avg1=sum(x)//n
avg2=avg1+1

cnt1=0
cnt2=0
for i in range(n):
    cnt1+=(x[i]-avg1)**2
    cnt2+=(x[i]-avg2)**2
print(min(cnt1,cnt2))

Solution (Python):
n=int(input())
l=list(map(int, input().split()))
if sum(l)%n==0:
  ct=0
  a=sum(l)//n
  for i in l:
      ct+=(i-a)**2
  print(ct)
else:
  ct1,ct2=0,0
  a=sum(l)//n
  b=sum(l)//n +1
  for i in l:
      ct1+=(i-a)**2
      ct2+=(i-b)**2
  print(min(ct1,ct2))

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

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
ans=100000000
for i in range(-100,101):
    cnt=0
    for j in X:
        cnt+=pow(j-i,2)
    ans=min(cnt,ans)
print(ans)

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

ans = float("inf")

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

print(ans)

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
ans=100000000000000
for i in range(1,101):
    temp=0
    for j in range(len(arr)):
        xx=(arr[j]-i)
        yy=xx*xx 
        temp+=yy 
    ans=min(ans,temp)
print(ans)

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

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
ans=10**9
for i in range(1,101):
  tmp = sum([(x-i)**2 for x in X])
  if tmp < ans:
    ans = tmp
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)

















def resolve():
    
    N = [int(x) for x in sys.stdin.readline().split()][0]  
    
    x_list = [int(x) for x in sys.stdin.readline().split()]  

    
    
    
    

    logger.debug('{}'.format([]))

    _min = 10**10
    for p in range(min(x_list), max(x_list) + 1):
        _min = min(_min, sum([(x - p)**2 for x in x_list]))

    print(_min)


if __name__ == "__main__":
    resolve()





import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
1 4"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7
14 14 2 13 56 2 37"""
        output = """2354"""
        self.assertIO(input, output)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
x_min=min(x)
x_max=max(x)
x_len=len(x)
ans=n*(100**2)
for i in range(x_min,x_max+1):
    buf=0
    for j in range(x_len):
        buf+=(x[j]-i)**2
    if buf<ans:
        ans=buf
print(ans)

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

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

print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
li = []
for i in range(101):
    count = 0
    for j in range(len(X)):
        count += abs(X[j] - i) ** 2
    li.append(count)
print(min(li))

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

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

ave = round( sum(x) / len(x))
ans=0
for i in x:
    ans+=(i-ave)**2

print(ans)

Solution (Python):
from statistics import mean
def main():
    N = int(input())
    X = list(map(int, input().split()))
    P = int(mean(X) + 0.5)
    d = 0
    for n in range(N):
        d += (X[n] - P)**2
    print(d)
 
main()

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

ans = 10 ** 8

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

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

S_min = float("inf")

for i in range(1, 101):
    S = 0
    for j in range(n):
        S += (x[j] - i) ** 2
    if S < S_min:
        S_min = S

print(S_min)

Solution (Python):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    x = list(map(int, input().split()))
    ans = 0
    t = sum(x) // n
    for i in range(n):
        ans += (x[i] - t) * (x[i] - t)
    a = ans
    ans = 0
    t += 1
    for i in range(n):
        ans += (x[i] - t) * (x[i] - t)
    print(min(ans, a))

        
   

main()

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
minsumhp = 10**9
for i in range(1, 100):
    sumhp = 0
    for j in range(n):
        sumhp += (x[j] - i)**2
    minsumhp = min(sumhp, minsumhp)
print(minsumhp)

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

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

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

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

ans = INF
for x in range(1, 101):
    cur = 0
    for a in A:
        cur += abs(a - x)**2
    ans = min(ans, cur)
print(ans)

Solution (Python):
def main():
    n=int(input())
    x=list(map(int,input().split()))
    ans = [0] * 100
    m=10**8
    for i in range(1,101):
        for j,aa in enumerate(x):
            ans[i-1] += (aa-i)**2
        m=min(m,ans[i-1])
    print(m)
if __name__=='__main__':
    main()

Solution (Python):
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, *X = list(map(int, read().split()))

X = np.array(X)
P = X.sum() // N

ans = 10**8 + 7

for i in range(-1, 2):
    acc = X - (P + i)
    acc = acc**2
    acc = acc.sum()

    ans = min(ans, acc)

print(ans)

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

Solution (Python):

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

val_min = 10000000000000000000000

for i in range(1, 101):
    val = 0
    for item in x_list:
        val += (item - i) ** 2
    if val < val_min:
        val_min = val

print(val_min)

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

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

print(ans)

Solution (Python):
N = int(raw_input())
X = map(float, raw_input().split())

P = 0.0
for item in X:
    P = P + item
P = P/N

P1 = int(P)
P2 = int(P)+1

ans1 = 0.0
for item in X:
    ans1 = ans1 + (P1-item)**2

ans2 = 0.0
for item in X:
    ans2 = ans2 + (P2-item)**2


print int(min(ans1, ans2))

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

Solution (Python):
inf = 1000000000

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

    num_list.sort()

    ans = inf

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

    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
l=1000000
for i in range(1,101):
    s=0
    for j in a:
        s+=(j-i)**2
    if s<l:
        l=s
print(l)

Solution (Python):
import math

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

s = sum(x)

ans = 0
a = round(s/n)

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

print(ans)

Solution (Python):


n = int(input())

data = list(map(int, input().split()))
minv = 100000000000000000
for x in range(0, 101):
    sumv = 0
    for v in data:
        sumv += (v - x) ** 2
    minv = min(minv, sumv)
    
print(minv)

Solution (Python):
import sys
import math
import collections
n = int(input())


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

ans = 1000000
for i in range(1,101):
  p = 0
  for j in range(n):
    p += abs(x[j]-i) ** 2

  if p < ans:
    ans = p

print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
min_ans = float('inf')
for i in range(min(X), max(X)+1):
    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 = [int(i) for i in input().split()]
ans = 10**7
for i in range(1,100):
    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()))

mini = 10**18
for i in range(1, 101):
    current = 0
    for j in range(n):
        current += (i - x[j])**2
    mini = min(mini, current)

print(mini)

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

ans=float('inf')

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

Solution (Python):



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

    for p in range(-100, 201):
        summed = 0

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

        ans = min(ans, summed)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
count=0
mincount=10000000000
for i in range(1,101):
  count=0
  for j in range(n):
    count+=(a[j]-i)**2
  mincount=min(count,mincount)
print(mincount)

Solution (Python):


def solve():
    N = int(input())
    Xs = list(map(int, input().split()))

    avg1 = sum(Xs)//N
    avg2 = avg1+1

    ans1 = 0
    ans2 = 0
    for x in Xs:
        ans1 += (x-avg1)**2
        ans2 += (x-avg2)**2
    print(min(ans1, ans2))


if __name__ == "__main__":
    solve()

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

minSum = 9999999999999999
for i in range(min(x), max(x)+1):
  tmp = 0
  for xx in x:
    tmp += (xx-i)**2
  if tmp < minSum:
    minSum = tmp
print(minSum)

Solution (Python):
def cost(p):
    res = 0
    for x in X:
        res += (p - x) ** 2
    return res


N = int(input())
X = [int(x) for x in input().split()]
print(min(cost(p) for p in range(min(X), max(X) + 1)))

Solution (Python):
def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

N = n_in()
X = l_in()

P1 = sum(X)//N
P2 = sum(X)//N + 1

print(min(sum((P1-x)**2 for x in X), sum((P2-x)**2 for x in X)));

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
ans = 10**8
for i in range(1,101):
  tmp = 0
  for j in range(n):
    tmp += (i-x[j])**2
  if tmp < ans:
    ans = tmp
print(ans)

Solution (Python):
N = int(input())
X = sorted(map(int, input().split()))
ans1 = 0
ans2 = 0
cand = sum(X) // N

for x in X:
    ans1 += (cand-x)**2
    ans2 += (cand+1-x)**2
print(min(ans1, ans2))

Solution (Python):



def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    

    n = int(input())
    x = list(map(int, input().split()))
    import math
    cost = 10 ** 11
    for i in range(min(x), max(x) + 1):

        t = 0
        for j in x:
            t += (j - i) ** 2

        cost = min(cost, t)
        
    print(cost)


if __name__ == '__main__':
    main()

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

min = 100000000
for i in range (100):
    sum = 0
    for j in range (N):
        sum += (R[j] - i)**2

    if sum <= min:
        min = sum
    
print(min)

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

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
ans = 9**10
for i in range(1,101):
    tmp = 0
    for y in x:
        tmp += (y-i)**2
    if ans >= tmp:
        ans = tmp
print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
cmin = 10**6
for i in range(101):
    cnt = 0
    for x in X:
        cnt += (x-i)**2
    cmin = min(cmin,cnt)
print(cmin)

Solution (Python):
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left 


sys.setrecursionlimit(10**7)
N = int(input())
X = list(map(int, input().split()))
X.sort()

minv = 10**18

for xi in range(X[0], X[-1]+1):
    val = 0
    for xj in X:
        val += (xi - xj) ** 2
    if minv > val:
        minv = val

print(minv)

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

x_mean = sum(xn) / N

if x_mean == int(x_mean):
  x_mean = int(x_mean)
  sum_ = 0
  for x in xn:
    sum_ += (x-x_mean)**2
  print(sum_)
else:
  x_mean = int(x_mean)
  sum1 = 0
  sum2 = 0
  for x in xn:
    sum1 += (x-x_mean)**2
    sum2 += (x-x_mean-1)**2
  print(min(sum1, sum2))

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

import numpy as np

X = np.array(X)
D = X.reshape(-1, 1) - np.arange(1, 100).reshape(1, -1)
D = np.sum(D*D, axis=0)

print(np.min(D))

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

M = max(x)
min = 10**12
for i in range(M+1):
    count = 0
    for ix in range(len(x)):
        count += (i-x[ix])**2

    if count <= min:
        min = count

print(min)

Solution (Python):










import math
import statistics
import string

def intinput():
    return int(input())

def listintinput():
    return list(map(int,input().split()))

def splitintinput():
    return map(int,input().split())

n = intinput()
x = listintinput()

av = int(statistics.mean(x))
avone = av+1
ans = 0
ansone = 0
for i in x:
    ans += (i-av) ** 2
    ansone += (i-avone) ** 2

print(min(ans,ansone))

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

ans = 10 ** 9

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

print(ans)

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

ans=float("inf")
for P in range(X[0],X[-1]+1):
  a=0
  for i in range(N):
    a+=(X[i]-P)**2
  ans=min(ans,a)
  
print(ans)

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

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

res = 10**10
for i in range(101):
    u = 0
    for x in X:
        u += (x - i)**2
    res = min(u, res)
print(res)

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

ans = float('inf')
for p in range(1, 101):
    s = 0
    for i in x:
        s += (i - p) ** 2
    ans = min(ans, s)

print(ans)

Solution (Python):
n=int(input())
X=list(map(int,input().split()))
a=9**9
for i in range(min(X),max(X)+1):
  a=min(a,sum(map(lambda x:(x-i)**2,X)))
print(a)

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


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


m = 1e10
for p in range(1, 101):
    m = min(sum((x - p)**2 for x in X), m)


print(m)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
ans = 1000000000
for x in range(1,101):
  total = 0
  for i in range(N):
    total += (A[i]-x)*(A[i]-x)
  ans = min( ans, total ) 
print(ans)

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

Solution (Python):
import math
n = int(input())
x = list(map(int,input().split()))
s = min(x)
e = max(x)
ans = 10**18
for i in range(s,e+1):
  f = 0
  for j in range(n):
    f += (x[j]-i)**2
  ans = min(ans,f)
print(ans)

Solution (Python):
import math

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

a1 = sum([(a - math.floor(p)) * (a - math.floor(p)) for a in x])
a2 = sum([(a - math.ceil(p)) * (a - math.ceil(p)) for a in x])
print(min(a1, a2))

Solution (Python):
import math
n = int(input())
x = list(map(int, input().split()))
a,b = math.ceil(sum(x)/n), math.floor(sum(x)/n)
if a==b:
    print(sum([(i-a)**2 for i in x]))
else:
    print(min(sum([(i-a)**2 for i in x]),sum([(i-b)**2 for i in x])))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
ans=10**9
for i in range(1,101):
  _=[(x-i)**2 for x in X]
  ans=min(ans,sum(_))
print(ans)

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

ans = 10**9
for n in range(1, 101):
    temp = 0
    for x in X:
        temp += (x - n)**2

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
tmp1=sum(x)//n
tmp2=-(-sum(x)//n)
ans1=0
ans2=0
for i in range(n):
    ans1+=(tmp1-x[i])**2
for i in range(n):
    ans2+=(tmp2-x[i])**2
print(min(ans1,ans2))

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

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

Solution (Python):
N = int(input())
X_list = [int(e) for e in input().split()]

ans = 10**100

for P in range(min(X_list),max(X_list)+1):
    temp_ans = 0
    
    for X in X_list:
        temp_ans += (X - P)**2
        
    if temp_ans < ans:
        ans = temp_ans
        
print(ans)

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

ans = 10**6
for i in range(1,101):
    tmp = sum([(y - i)**2 for y in x])
    ans = min(ans,tmp)
print(ans)

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

print(Ans)

Solution (Python):
n=int(input())
x=sorted(map(int,input().split()))
m=sum(x)//n

s1=0
s2=0
s3=0
for i in range(n):
    s1 += (x[i]-m)**2
    s2 += (x[i]-m-1)**2
    s3 += (x[i]-m+1)**2
print(min(s1,s2,s3))

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

cor_1 = math.ceil(sum(X) / N)
cor_2 = math.floor(sum(X) / N)
ans_1 = [(int(_) - cor_1) ** 2 for _ in X]
ans_2 = [(int(_) - cor_2) ** 2 for _ in X]

ans = min(sum(ans_1), sum(ans_2))
print(ans)

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

xmin=min(xlist)
xmax=max(xlist)

min_answer=10**9
for i in range(xmin,xmax+1):
  answer=0
  for x in xlist:
    answer+=(x-i)**2

  min_answer=min(answer,min_answer)

print(min_answer)

Solution (Python):


N = int(input().split()[0])
x_list = list(map(int, input().split()))

min_cost = float("inf")
for i in range(1, 101):
    t = sum([(x - i) ** 2 for x in x_list])
    min_cost = min(t, min_cost)
ans = min_cost

print(ans)

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

ans = 10 ** 10


for p in range(1, 101):
    power = 0
    for x in X_array:
        
        power += ((x-p) ** 2)
    if power < ans:
        ans = power


print(ans)

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

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
X.sort()
s=X[0]
e=X[-1]
ans=10**10
for i in range(s, e+1):
    tmp=0
    for x in X:
        tmp+=(i-x)**2
    if tmp<ans:
        ans=tmp
print(ans)

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

ans = float('inf')

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

    ans = min(ans,temp)

print(ans)

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

p=sum(x)/N

import math

z1=0
z2=0
for i in range(N):
  z1+=(x[i]-math.floor(p))**2
  z2+=(x[i]-math.ceil(p))**2
  
print(min([z1,z2]))

Solution (Python):


import sys


def minimize(n, xs):
    cost = sys.maxsize // 2
    for p in range(min(xs), max(xs) + 1):
        new_cost = sum((x - p) * (x - p) for x in xs)
        cost = min(cost, new_cost)
    return cost


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    opt_cost = minimize(n, xs)
    print(opt_cost)


if __name__ == "__main__":
    main()

Solution (Python):
n = input()
xx = map(int, raw_input().split())
xx.sort()
best = float('inf')
for x in xrange(xx[0], xx[-1] + 1):
    c = sum((x - y) ** 2 for y in xx)
    best = min(best, c)
print best

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]
mw = 10 ** 10
for p in range(1, 101):
    w = sum((x - p) ** 2 for x in X)
    mw = min(w, mw)

print(mw)

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

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