Problem:
 Score : 200 points    Problem Statement Evi has N integers a_1,a_2,..,a_N . His objective is to have N equal integers by transforming some of them.  He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j) , he has to pay the cost separately for transforming each of them (See Sample 2).  Find the minimum total cost to achieve his objective.      Constraints  1≦N≦100  -100≦a_i≦100         Input The input is given from Standard Input in the following format:  N  a_1  a_2 ... a_N       Output Print the minimum total cost to achieve Evi's objective.        Sample Input 1 2
4 8      Sample Output 1 8  Transforming the both into 6 s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.       Sample Input 2 3
1 1 3      Sample Output 2 3  Transforming the all into 2 s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note that Evi has to pay (1-2)^2 dollar separately for transforming each of the two 1 s.       Sample Input 3 3
4 2 5      Sample Output 3 5  Leaving the 4 as it is and transforming the 2 and the 5 into 4 s will achieve the total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.       Sample Input 4 4
-100 -100 -100 -100      Sample Output 4 0  Without transforming anything, Evi's objective is already achieved. Thus, the necessary cost is 0 .

Solution (Python):
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
answer = 10 ** 6

for i in range(-100, 101):
    tmp = sum((A-i) ** 2)
    if answer > tmp:
        answer = tmp
print(answer)

Solution (Python):

import math

n = int(input())
a = [int(s) for s in input().split()]

average_ceil = math.ceil(sum(a) / len(a))
average_floor = math.floor(sum(a) / len(a))

cost_ceil = 0
cost_floor = 0
for i in range(n):
    cost_ceil += (a[i] - average_ceil) ** 2
    cost_floor += (a[i] - average_floor) ** 2

print(min(cost_ceil, cost_floor))

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

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

Solution (Python):
N = int(input())
alist = [int(i) for i in input().split()]
bestcost = 1000000000
besti = 1000000
for i in range(min(alist),max(alist)+1):
    cost = sum([(a-i)**2 for a in alist])
    if cost < bestcost:
        bestcost = cost
        besti = i

print(bestcost)

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

ave=round((sum(A)/N))

t=0
for a in A:
    t+=(a-ave)**2
print(t)

Solution (Python):
import sys
n = int(input())
a = list(map(int, input().split()))
d = max(a)-min(a)
if d == 0:
    print(0)
    sys.exit()
m = 0
for i in a:
    m += (d-i) ** 2
for i in range(d):
    c = min(a) + i
    cost = 0
    for j in a:
        cost += (c-j) ** 2
    if m > cost:
        m = cost
print(m)

Solution (Python):
def sds(a,x):
    return sum([(ai-x)**2 for ai in a])

N=int(input())
a=list(map(int,input().split()))
ans=min([sds(a,x) for x in range(-100,101)])
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
mn = min(a)
mx = max(a)+1
ans = 10**9
for i in range(mn, mx):
  cost = 0
  for aa in a:
    cost += (i - aa)**2
  if ans > cost:
    ans = cost
print(ans)

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
s = 0
b = 0
count = int(input())
list_A = list(map(int, input().split()))
for a in list_A:
  s = s + a
s = s/count
s = Decimal(s).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
for a in list_A:
  b = b + (a - s) * (a - s)
print(b)

Solution (Python):
import numpy as np
N=int(input())
A=list(map(int,input().split()))
mA=int(np.mean(A))
mA2=mA+1
print(min(sum([(i-mA)**2 for i in A]),sum([(i-mA2)**2 for i in A])))

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

x = sum(A)/len(A)
totals = []
for i in range(min(A), max(A)+1):
    total = 0
    for a in A:
      total += (a-i)**2
    totals.append(total)
print(min(totals))

Solution (Python):
"ARC 059 C - いっしょ / Be Together"

if __name__ == "__main__":
    N = int(input())
    a = list(map(int, input().split()))

    ans = 10**12

    for i in range(-100, 101):
        tmp = 0
        for j in range(N):
            tmp += (a[j] - i) **2
        if tmp < ans:
            ans = tmp
    
    print(ans)

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

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

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = (200**2)*100
    for m in range(-100, 101):
        x = 0
        for a in A:
            x += (m-a)**2
        ans = min(ans, x)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
l,r=max(A),min(A)
cnt=10**10
for i in range(r,l+1):
    ans=0
    for j in A:
        ans +=(j-i)**2
    cnt=min(cnt,ans)
print(cnt)

Solution (Python):
from statistics import mean
n = int(input())
a = list(map(int, input().split()))
t = round(mean(a))

sum = 0
for i in a:
    sum += (i - t)**2

print(sum)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
m=min(a)
M=max(a)
ans=10**8
cnt=0
if m-M==0:
    ans=0
for i in range(m,M):
    for j in range(n):
        cnt+=(a[j]-i)**2
    ans=min(ans,cnt)
    cnt=0
print(ans)

Solution (Python):

def main():
    
    N, *A = map(int, open(0).read().split())
    ans = 1 << 60
    for i in range(min(A), max(A) + 1):
        ans = min(ans, sum((i - a) ** 2 for a in A))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ave=sum(a)//n
cost=0
for i in range(n):
    cost+=(a[i]-ave)**2
for i in range( min(a),max(a)+1 ):
    cost2=0
    for j in range(n):
        cost2+=(a[j]-i)**2
        if cost2 > cost:
            break
    if cost2 < cost:
        cost=cost2
print(cost)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    mt = 10 ** 10
    mi = min(a)
    ma = max(a)
    for i in range(mi, ma + 1):
        t = 0
        for v in a:
            t += ((i - v) ** 2)
        mt = min(mt, t)
    print(mt)


if __name__ == '__main__':
    slove()

Solution (Python):
n = int(input())
List = list(map(int,input().split()))
mean = sum(List)/n
round_mean = round(mean)
cost = [(i-round_mean)**2 for i in List]

print(int(sum(cost)))

Solution (Python):
import numpy as np
n = int(input())
a = np.array([int(_) for _ in input().split()])
b =[]
for i in range(n):
  m = int(round(a.mean()))
  c = (a[i]-m)**2
  b.append(c)
print(sum(b))

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

cost = 0
ave = sum(A)/N
if math.ceil(ave)-ave < 0.5:
    ave = math.ceil(ave)
else:
    ave = math.floor(ave)
for a in A:
    cost += (a-ave)**2
print(cost)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
minA = min(A)
maxA = max(A)
ans = float("inf")
for i in range(minA, maxA + 1):
    cnt = 0
    for a in A:
        cnt += (i - a) ** 2
    ans = min(ans, cnt)
print(ans)

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
ans = 10**8

for X in range(-100,101):
    tmp = 0
    for i in range(N):
        tmp += (A[i]-X)**2
    if ans >= tmp:
        ans = tmp
    else:
        pass

print(ans)

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

ans=10**6
for i in range(-100,101):
	t=0
	for a in A:
		t+=(i-a)**2
	ans=min(ans,t)

print(ans)

Solution (Python):
import sys

def main():
    def input():
        return sys.stdin.readline()[:-1]
    N = int(input())
    a = list(map(int,input().split()))
    ans = 1000000
    for k in range(-100,101):
        t = 0
        for e in a:
            t += (e-k)**2
        ans = min(ans,t)
    print(ans)
if __name__ == '__main__':
    main()

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

ans = float('inf')
for k in range(-100,101):
    tmp = 0
    for a in A:
        tmp += (a-k)**2
    ans = min(ans, tmp)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = float('inf')
for i in range(-100, 101):
    ans = min(ans, sum([abs(a - i) ** 2 for a in A]))
print(ans)

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

if S//N*N==S:
    C1 = S//N
    C2 = S//N
else:
    C1 = S//N
    C2 = S//N+1
ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += (A[i]-C1)**2
    ans2 += (A[i]-C2)**2

print(min(ans1,ans2))

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

a1=sum(a)//N
a2=(sum(a)-1+N)//N

ans1=0
ans2=0

for i in range(N):
    ans1+=(a[i]-a1)**2
    ans2+=(a[i]-a2)**2

print(min(ans1,ans2))

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

y = round(sum(A) / N)
ans = 0

for a in A:
  ans += (a-y)**2

print(ans)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
ans=[0]*201
for i in range(-100,101):
    for j in a:
        ans[i]+=(j-i)**2
print(min(ans))

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

s = sum(a)/n

p=0
m=0
for i in range(n):
  p += (a[i]-s//1)**2
  m += (a[i]-(-(-s//1)))**2
print(int(min(p,m)))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
cost_odd = 0
cost_even = 0

if a.count(a[0]) == N:
    print(0)
    exit()

num_even = sum(a) // N + 1
num_odd = sum(a) // N

for i in range(N):
    cost_even += (a[i] - num_even)**2
    cost_odd +=  (a[i] - num_odd)**2

print(min(cost_odd, cost_even))

Solution (Python):
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
m = int(round(a.mean()))
print(np.sum((a-m)**2))

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

cost=0
for i in range(n):
    cost+=(a[i]-ave)**2
print(cost)

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

E = round(sum(A) / N)

print(sum([(a - E) ** 2 for a in A]))

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
mt = 10 ** 10
for i in range(a[0], a[-1] + 1):
    t = 0
    for j in a:
        t += (j - i) ** 2
    mt = min(mt, t)
print(mt)

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

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

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

ans = float('inf')

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

print(ans)

Solution (Python):


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

res=float('inf')
for y in range(min(x),max(x)+1):
    cnt=0
    for i in range(n):
        cnt+=(x[i]-y)**2
    res=min(res,cnt)
print(res)

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

ans = float('inf')

for base in range(min(A), max(A) + 1):
    ans = min(ans, sum([abs(base - a)**2 for a in A]))

print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
cost=9999999999
for i in range(-100,101):
  c=sum((i-a)**2 for a in A)
  if c<cost:
    cost=c
print(cost)

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

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

ans = 10**10


for i in range(-100,101):
    temp = 0
    for x in li:
        temp += (x - i) ** 2
    if ans > temp:
        ans = temp
        
print(ans)

Solution (Python):



N = int(input())
a = list(map(float, input().split()))
a_sum = sum(a)
ave = round(a_sum / N)
b = list(map(lambda n : pow(n - ave, 2), a))
print(int(sum(b)))

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

Solution (Python):
a = int(input())
b = list(map(int, input().split()))
d = 10 ** 9
e = min(b)
f = max(b)
for i in range(e, f + 1):
    g = 0
    for j in b:
        g += abs(j - i) ** 2
    d = min(d, g)
print(d)

Solution (Python):
a = int(input())
b = list(map(int, input().split()))
b.sort()
c = (sum(b)) // len(b)
d = c + 1
mc = 0
md = 0
for i in b:
    mc += abs(i - c) ** 2
    md += abs(i - d) ** 2
print(min(mc, md))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
INF = 10**18

MAX = max(A)
MIN = min(A)

res = INF
for s in range(MIN,MAX+1):
    t = 0
    for i in range(N):
        t += (s - A[i])**2
    
    if t < res:
        res = t
print(res)

Solution (Python):
n = int(input())
A = [int(i) for i in input().split()]
ans = float('inf')
for i in range(-100,101):
    tmp = 0
    for a in A:
        if a != i: tmp+=(a-i)**2
    ans = min(ans,tmp)
print(ans)

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
MOD = 10**9 + 7
sys.setrecursionlimit(10**7)

dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())


N = ii()
As = list(mi())
ave = round(sum(As) / N)

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

print(ans)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
INF=10**9+7
ans=INF
for i in range(min(l),max(l)+1):
    tmp=sum([(i-j)**2 for j in l])
    if tmp<ans:ans=tmp
print(ans)

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

min_cost = 10 ** 12
for n in range(-100, 100 + 1):
	cost = 0
	for a in A:
		cost += (n - a)** 2
	min_cost = min(min_cost, cost)
print(min_cost)

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

ave = round(sum(A) / N)
ans = 0
for a in A:
    ans += (a - ave) ** 2
print(ans)

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

ans = 1000000000
for x in range(-100, 101):
    cost = 0
    for i in range(n):
        cost += (a[i] - x) ** 2
    ans = min(cost, ans)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
y = round(sum(A) / N)
ans = 0

for i in range(N):
    ans += (A[i] - y)**2

print(ans)

Solution (Python):
n=int(input())
num=list(map(int,input().split()))
ans=10**9
s,e=min(num),max(num)
for j in range(s,e+1):
  c=0
  for i in range(n):
    c+=(num[i]-j)**2
  if c<ans:
    ans=c
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
nijo_list = []
for i in range(min(a), max(a)):
    nijo_sum = 0
    for j in range(len(a)):
        nijo = (a[j] - i)**2
        nijo_sum += nijo
    nijo_list.append(nijo_sum)
if nijo_list:
    print(min(nijo_list))
else:
    print(0)

Solution (Python):
def div_round(x, y): return (x + (y // 2)) // y

N = int(input())
*A, = map(int, input().split())
mean = div_round(sum(A), N)
ans = 0
for a in A:
    ans += (a - mean) ** 2
print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
x = round(sum(a)/n)
ans = 0
for i in range(n):
    ans += (a[i]-x)**2

print(ans)

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

tmp = sum(a)
ave1 = tmp // N
ave2 = ave1 + 1

dev1 = 0
dev2 = 0

for aa in a:
    dev1 += (aa - ave1)**2
    dev2 += (aa - ave2)**2

print(min(dev1,dev2))

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

u = round(sum(a) / N)

print(sum([(x-u)**2 for x in a]))

Solution (Python):

def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    ans = float("inf")
    MIN, MAX = min(lst), max(lst)

    for i in range(MIN, MAX + 1):
        cnt = 0
        for j in lst:
            cnt += (i - j) ** 2
        ans = min(ans, cnt)
    print(ans)


if __name__ == "__main__":
    main()

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

ans = float("inf")
for y in range(-100, 101):
    temp_y = 0
    for x in a:
        temp_y += (x - y) ** 2

    ans = min(ans, temp_y)

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = 10 ** 9
for i in range(min(A), max(A) + 1):
    cost = sum(list(map(lambda x: (x - i) ** 2, A)))
    ans = min(ans, cost)
print(ans)

Solution (Python):

n = int(input())
lst = list(map(int, input().rstrip().split()))
ans = float("inf")
for i in range(-100, 101):
    cnt = 0
    for j in lst:
        cnt += (i - j) ** 2
    ans = min(ans, cnt)
print(ans)

Solution (Python):

n = int(input())
lst = list(map(int, input().rstrip().split()))
ans = float("inf")
MIN, MAX = min(lst), max(lst)

if MIN == MAX:
    print(0)
else:
    for i in range(MIN, MAX + 1):
        cnt = 0
        for j in lst:
            cnt += (i - j) ** 2
        ans = min(ans, cnt)
    print(ans)

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

h = sum(a) // N

def xx(h):
  return sum(((h - ai)**2 for ai in a))
print(min(xx(h), xx(h+1)))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
mina=[]
for i in range(-100,101):
    suma=0
    for j in range(n):
        suma += (a[j]-i)**2
    mina.append(suma)
print(min(mina))

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

costs = []


o = int(round(sum(a)/N))
cost = 0
for j in range(N):
    cost += (o - a[j])**2

print(cost)

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

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

ans = 10 ** 7
for x in range(-200, 201):
    cost = 0
    for i in range(N):
        cost += (a[i] - x) ** 2
    ans = min(cost, ans)

print(ans)

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

mini = 10000000000000
for i in range(min(As) - 1, max(As) + 1):
    tmp = 0
    for a in As:
        tmp += (i - a) ** 2

    if tmp < mini:
        mini = tmp

print(mini)

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

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]
min_a = min(a)
max_a = max(a)
ans = 10**10
for i in range(min_a,max_a+1):
    sum_c = 0
    for x in a:
        sum_c += (x-i)**2
    ans = min(ans,sum_c)
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ave = sum(a) // len(a)
ans1 = 0
ans2 = 0
for i in a:
  ans1 += (i - ave) ** 2
  ans2 += (i - ave - 1) ** 2
print(min(ans1, ans2))

Solution (Python):
N=int(input())
M=list(map(int,input().split()))
print(min(sum([(M[j]-i)**2 for j in range(N)]) for i in range(-100,101)))

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
cost = []
for i in range(-100,101):
    temp = 0
    for a in A:
        temp += (a-i)**2
    cost.append(temp)
print(min(cost))

Solution (Python):
import itertools
import math
N = input()
l = list(map(int,input().split(" ")))
av = sum(l)/len(l)
can1 = int(math.ceil(av))
can2 = int(math.floor(av))
ans1 = sum(list(map(lambda x:(x-can1)**2,l)))
ans2 = sum(list(map(lambda x:(x-can2)**2,l)))
print(min(ans2,ans1))

Solution (Python):
N = int(input())
A = list(map(int,input().split(" ")))
S = []

i = min(A)
j = max(A)
while i <= j:
    S.append(sum(map(lambda x:(x-i)**2,A)))
    i += 1

print(min(S))

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

if (sum(a)/n)%1 < 0.5:
    avr = sum(a)//n
else:
    avr = sum(a)//n+1

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

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mini = 10000000000000000000
for x in range(-100, 101):
    tmp = [(x - y) ** 2 for y in a]
    mini = min(mini, sum(tmp))
print(mini)

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

Solution (Python):
import numpy as e
n,*a=map(int,open(0).read().split())
a=e.array(a)
print(min([sum((a-i)**2) for i in range(-100,101)]))

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

Solution (Python):
import numpy as np

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

def cost(np_values, a):
    """
    input:
        np_values = number list of input_values (N,)
        a = constant (1)
    
    output:
        cost = summation of the each L2 cost
    """
    
    cost = np.sum((np_values - a) ** 2)
    return cost
  




cost_list = []
for a in range(-100, 101):
    cost_list.append(cost(np_values, a))
print(min(cost_list))

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP


N = int(input())
a = list(map(int, input().split(' ')))
result = sum(a) / N
r = Decimal(result).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
cost = 0
for i in a:
    cost += (i - r) ** 2
print(cost)

Solution (Python):
input()
A=[int(i) for i in input().split()]
print(sum((a-round(sum(A)/len(A)))**2 for a in A))

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

m = round(sum(A) / N)
print(sum((a - m) ** 2 for a in A))

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

mi = 1e10
for m in range(-100, 101):
    mi = min(mi, sum((a - m) ** 2 for a in A))
print(mi)

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

m = sum(A) // N
print(min(sum((a - m) ** 2 for a in A), sum((a - m - 1) ** 2 for a in A)))

Solution (Python):


n = int(input())
nums = [int(s) for s in input().split()]

cost = 100000001
for i in range(-100, 101):
    costMin = 0
    for j in nums:
        costMin += (i -j)**2
    if costMin < cost:
        cost = costMin        

print(cost)

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

min_cost = 10**15
for i in range (-100,101):
    cost = 0
    for j in range (len(a)):
        cost +=(a[j]-i)**2
    
    if min_cost >=cost:
        min_cost = cost

print(min_cost)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
mn = 1e9
for i in range(-100, 101):
  cost = 0
  for v in a: cost += (i - v) ** 2
  mn = min(mn, cost)
print(mn)

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

ans = [(ave - a)**2 for a in A]

print(sum(ans))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
mn = 1e9
for i in range(-100, 101):
  cost = 0
  for v in a:
    cost += (i-v) * (i-v)
  mn = min(mn, cost)
print(mn)

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

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

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
sum=[]
s=0
for i in range(-100,101):
  for j in range(n):
    s=s+(a[j]-i)*(a[j]-i)
  sum.append(s)
  s=0
print(min(sum))

Solution (Python):
N = int(input())
an = list(map(int, input().split()))
ave = sum(an)/N
rep = int(ave + 0.5) if ave > 0 else int(ave - 0.5)
ans = sum([(a - rep) ** 2 for a in an])
print(ans)

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]
b = sum(a)//N
if sum(a)%N*2 >=  N:
    p = 1
else:
    p = 0
b =b+p
ans = 0
for i in range(N):
    ans += (a[i]-b)**2
print(ans)

Solution (Python):


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

a_sum = sum(a)

flag = True
sum2 = 0
for i in range(n):
    sum2 += a[i] ** 2
    if i >= 1:
        if a[i] != a[i-1]:
            flag = False

cand = []
for i in range(-100,101):
        cand.append(sum2 - 2 * i * a_sum + n * (i ** 2))

print(min(cand))

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

n = int(input())
A = list(map(int,input().split()))
ans = inf
for a in range(-100,101):
    cur = 0
    for i in range(n):
        cur += (A[i]-a)**2
    ans = min(ans,cur)
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
s=sum(a)//n
ans_1=0
ans_2=0
for i in range(n):
    ans_1+=(a[i]-s)**2
    ans_2+=(a[i]-s-1)**2
print(min(ans_1,ans_2))

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

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

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

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

small= min(A)
large=max(A)
ans= 100*(100**2)

for j in range(small, large+1):
  diffA=[i-j for i in A]
  ans=min(ans, sum([i**2 for i in diffA]))
  
print(ans)

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
l=min(arr)
r=max(arr)
ans=10**10
for i in range(l,r+1):
  tmp=0
  for j in range(n):
    tmp+=(arr[j]-i)**2
  if tmp<ans:
    ans=tmp
print(ans)

Solution (Python):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
a = nl()
ans = 10 ** 9
for i in range(-100, 101):
    summ = 0
    for aa in a:
        summ += (aa - i) ** 2
    ans = min(ans, summ)
print(ans)

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

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

t = round(sum(a) / N + 0.1)

ans = 0

for aa in a:
    ans += (t - aa) ** 2

print(ans)

Solution (Python):
N = int(input())
NUM = list(map(int,input().split()))
MAX = max(NUM)
MIN = min(NUM)
COSTLIST = []
for i in range (MIN,MAX+1):
    COST = 0
    for j in NUM:
        COST += (j-i)**2
    COSTLIST.append(COST)
MINIMUM = min(COSTLIST)

print(MINIMUM)

Solution (Python):
import math
import statistics

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

ans = 10**9+7
for n in range(201):
    temp=0
    for i in a:
        temp += int(abs(n-100 - i)) ** 2
    ans = min(ans,temp)

print(ans)

Solution (Python):
n=input()
l=list(map(int,input().split()))
ans=float("inf")
for i in range(min(l),max(l)+1):
    now=0
    for j in l:
        now+=(j-i)**2
    ans=min(ans,now)
print(ans)

Solution (Python):

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

sum = 0
cost = 0

for x in a:
    sum += x

ave = round(sum / N)

for x in a:
    cost += (x - ave) ** 2

print(cost)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
c = list(range(min(a), max(a) + 1))
d = []
for c_ in c:
    ans = int(sum([((a_ - c_) ** 2) for a_ in a]))
    d.append(ans)
print(min(d))

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

average = sum(a_s)
average /= len(a_s) * 1.0

ans = -1
for target in range(int(average), int(average) + 2):
    c = sum(map(lambda x: (x - target) * (x - target), a_s))
    if ans < 0:
        ans = c
    else:
        ans = min(ans, c)

print(ans)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
s=sum(l)/n
if s-int(s)<int(s)+1-s:
  s=int(s)
else:
  s=int(s)+1
ans=0
for i in l:
  ans+=(s-i)**2
print(ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
g = 4000001
for i in range(min(a),max(a)+1):
    temp_g = 0
    for d in a:
        temp_g += (i-d)**2
    g = min(g,temp_g)
print(g)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = 10**9
for i in range(-100,101):
    p = 0
    for j in a:
        p += (i-j)**2

    ans = min(ans,p)

print(ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
count = 10**10
for y in range(min(a),max(a)+1):
    y_count = 0
    for x in a:
        y_count += (x-y)**2
    count = min(count,y_count)
print(count)

Solution (Python):
N = int(input())
a = [int(_) for _ in input().split()]
ans = float ('inf')

for i in range(-100, 101):
    tmp = 0
    for j in a:
        tmp += (i - j)**2
    if tmp < ans:
        ans = tmp

print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split(' ')))
print(min([sum([(a-i)**2 for a in A]) for i in range(min(A),max(A)+1)]))

Solution (Python):
n=int(input())
a=[int(s) for s in input().split()]
print(min(sum((x-p)*(x-p) for x in a) for p in range(min(a),max(a)+1)))

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

ans = (200**2)*100
     
for i in range(-100,101):
    tmp = 0
    for j in range(N):
        tmp += (A[j]-i)**2
    ans = min(ans,tmp)
print(ans)

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

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

ans=float("inf")
for i in range(-100,101):
  tmp=0
  for  a in A:
    tmp+=(a-i)**2
  ans=min(ans, tmp)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

def main(n):
	a = list(map(int, input().split()))
	ans = 10**8
	for i in range(-100, 101, 1):
		temp = 0
		for j in a:
			temp += (i-j)**2
		if ans > temp:
			ans = temp
	print(ans)

main(int(input()))

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

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

Solution (Python):
def compute_score(s):
    return sum([(a - s)**2 for a in As])

N = int(input().strip())
As = list(map(int, input().strip().split()))

s = sum(As) / N
ans = 0
if(s % 1 == 0):
    ans = compute_score(s)
else:
    ans = min(compute_score(s // 1), compute_score(s // 1 + 1))
print(int(ans))