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):
def main():
  N = int(input())
  A = [int(_) for _ in input().split()]
  ret = 10 ** 10
  for tar in range(-100, 101):
    cc = 0
    for a in A:
      cc += (tar - a) ** 2
    ret = min(ret, cc)
  print(ret)
  return

if __name__ == '__main__':
  main()

Solution (Python):
import math

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

X = round(sum(a) / n)

P = 0

for i in range(n):
    P += (X - a[i])**2

print(P)

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

start = min(a_L)
end = max(a_L)

ans = float("inf")
for i in range(start,end+1):
    cost = 0
    for val in a_L:
        cost += (val-i)**2
    
    ans = min(ans,cost)

print(ans)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
a = sum(l)//n
b = a+1
s = 0
m = 0
for i in l:
  s += (i-a)**2
for j in l:
  m += (j-b)**2
print(min(s,m))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
mincost = 10000000000000000000
for i in range(-100, 101):
    cost = 0
    for j in a:
        cost += (j - i) * (j - i)
    if cost < mincost:
        mincost = cost
print(mincost)

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
mean = sum(a) / len(a)

tar = round(mean)

score = 0
for x in a:
    score += (x-tar)*(x-tar)
print(score)

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

asummin=40000*100
for i in range(-100,101,1):
    asum=0
    for ii in range(n):
        asum+=(a[ii]-i)**2
    asummin=min(asummin,asum)
print(asummin)

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

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

ans = float("inf")
for i in range(min(A), max(A)+1):
    x = 0
    for j in range(N):
        x += (i-A[j])**2
    ans = min(ans, x)

print(ans)

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

Solution (Python):
data=int(input())
nim=list(map(int,input().split()))
mike=2000000000000
for i in range(-100,101):
  counter=0
  for j in nim:
    counter+=(i-j)*(i-j)
  if counter<mike:
    mike=counter
print(mike)

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

ans = 10 ** 10
for x in range(-100, 101):
    curr_cost = 0
    for a in aaa:
        curr_cost += (x - a) ** 2
    ans = min(ans, curr_cost)
print(ans)

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

print(min([sum([(a-i)**2 for a in A]) for i in range(-100, 101)]))

Solution (Python):
def solve(N, vals):
    result = float("inf")
    for i in range(-100, 101):
        curCost = 0
        for val in vals:
            curCost += (i - val) ** 2
        result = min(result, curCost)
    print(result)


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

Solution (Python):
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

ans = 1000000000000

for y in range(-100,101):
    c = 0
    for i in a:
        c += (y-i)**2
    ans = min(c,ans)

print(ans)

Solution (Python):
import math
n, *a = map(int, open(0).read().split())

y1 = math.ceil(sum(a)/n)
y2 = sum(a)//n
ans1 = 0
ans2 = 0

for i in range(n):
    ans1 += (a[i] - y1) ** 2
    ans2 += (a[i] - y2) ** 2

print(min(ans1,ans2))

Solution (Python):
import math
n = int(input())
a = list(map(int, input().rstrip().split()))
s = sum(a)
t1 = 0
t2 = 0
mean1 = s // n
mean2 = mean1 + 1
for x in a:
    t1 += math.pow(abs(x - mean1), 2)
    t2 += math.pow(abs(x - mean2), 2)
print(int(min(t1, t2)))

Solution (Python):
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 10000000
	for i in range(-100, 101):
		s = 0
		for j in a:
			s += (i-j)**2
		if ans > s:
			ans = s
	print(ans)
resolve()

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP
n = int(input())
x = list(map(int, input().split()))
num = Decimal(str(sum(x)/n)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
num = int(num)

cost=0
for i in range(n):
    cost += (x[i]-num)*(x[i]-num)
print(cost)

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

ans=10**9

def sum(x):
    r=0
    for i in range(0,N):
        r+=(A[i]-x)**2
    return r

for j in range(-100,101):
    if sum(j)<=ans:
        ans=sum(j)

print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
c = float("inf")
for m in range(sum(A)//N-1,sum(A)//N+2):
    c = min(c, sum(map(lambda a: (a-m)**2, A)))
print(c)

Solution (Python):
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 100**6
	for i in range(-100, 101):
		tmp = 0
		for j in a:
			if i == j:
				continue
			tmp += (j - i)**2
		if tmp < ans:
			ans = tmp
	print(ans)
resolve()

Solution (Python):
def resolve():
	n = int(input())
	ans = 1000000
	a = list(map(int, input().split()))
	for i in range(-100, 101):
		tmp = 0

		for j in a:
			tmp += (j-i)**2
		if tmp < ans:
			ans = tmp
	print(ans)

resolve()

Solution (Python):
import math
n= int(input()) 
x = list(map(int, input().split()))
y = sum(x)*1.0/n
z =round(y)

print(sum([(i-z)**2 for i in x]))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n = int(input())
    a = list(map(int, input().split()))
    res = 10**20

    for i in range(-100, 101):
        total = 0
        for j in a:
            total += (j-i)**2
        res = min(res, total)
    print(res)


if __name__ == '__main__':
    main()

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


if __name__ == "__main__":
    resolve()

Solution (Python):
n = int(input())
ns = list(map(int, input().split()))
res = float('inf')
for i in range(-100, 101):
    res = min(res, sum((i-j)**2 for j in ns))
print(res)

Solution (Python):
def solve(s):
    sum1 = 0
    sum2 = 0
    length = 0
    for i in s.split():
        x = int(i)
        sum1 += x**2
        sum2 += x
        length += 1

    score = 10**8

    for y in range(100,-101, -1):
        tmp = sum1 - sum2*2*y + length*(y**2)
        score = min(tmp, score)

    return score

if __name__ == "__main__":
    n = int(input())
    s = input()
    print(solve(s))

Solution (Python):

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

amin=min(a)
amax=max(a)

smin=(amax**2)*n
for y in range(amin,amax+1):
    ssum=0
    for i in range(n):
        ssum=ssum+(a[i]-y)**2
    smin=min(smin,ssum)

print(smin)

Solution (Python):

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

amin=min(a)
amax=max(a)

smin=(amax**2)*n
for y in range(amin,amax+1):
    ssum=0
    for i in range(n):
        ssum=ssum+(a[i]-y)**2
    smin=min(smin,ssum)

print(smin)

Solution (Python):
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
  x = round(sum(a) / n)
  s = 0
  for i in range(n):
    s += pow(x - a[i], 2)
  print(s)
  
if __name__ == '__main__':
  main()

Solution (Python):

def solve(n, arr):
    s = sum(arr)

    k = int(round(s / len(arr), 0))

    cost = 0

    for num in arr:
        cost += (k-num) ** 2

    return cost


n = int(input().strip())
arr = list(map(int, input().strip().split()))

print(solve(n, arr))

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

ave = sum(a)/N

if ave - int(ave) >= 0.5:
    ave = int(ave)+1
else:
    ave =int(ave)
    
a = [(a[i]-ave)**2 for i in range(N)]

print(sum(a))

Solution (Python):
class atcorder:
    N=int(input())
    add = list(map(int,input().split()))
    total=0
    for i in range(N):
        total+=add[i]
    y=total/N
    
    i=0
    total=0
    for i in range(N):
        
        total+=(add[i]-round(y))**2
        
    print(int(total))

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

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

t.sort()

ans = 100000000000000

for i in range(t[0],t[-1]+1):
    memo = 0
    for j in t:
        memo += (i-j)**2
    ans = min(memo, ans)
print(ans)

Solution (Python):










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:
    return a
  return gcd_(a,a % b) 
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


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

def main():
  n = int(input())
  A = readInts()
  
  SPLIT = round(sum(A)/n)
  
  ANS = 0
  
  for i in range(n):
    ANS += abs(SPLIT-A[i])**2
  print(ANS)
  
if __name__ == '__main__':
  main()

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



def in_int():
    return (int(input()))


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


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


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


n = in_int()

a = in_list()

av=  sum(a)//n

ans  = 0

p = 0
for xx in a:
    p += (xx-av)*(xx-av)

ans = p


p = 0
for xx in a:
    p += (xx-av-1)*(xx-av-1)


ans = min(ans, p)

print(ans)

Solution (Python):
import numpy as np

n = int(input())

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

a_array = np.array(a)
a_min = np.min(a_array)
a_max = np.max(a_array)
a_med = np.median(a_array)



sum_array = np.zeros((3, n), dtype = np.int)


opt = False
target = int(a_med)
while not opt:
  sum_array[0, :] = (a_array[:] - (target-1)) ** 2
  sum_array[1, :] = (a_array[:] - (target)) ** 2
  sum_array[2, :] = (a_array[:] - (target+1)) ** 2
  sum = np.sum(sum_array, axis = 1)
  if sum[1] < sum[0] and sum[1] < sum[2]:
    opt = True
  elif sum[0] < sum[1]:
    target -= 1
  else:
    target += 1
  
print(sum[1])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
work = sum(a)/n
work = int(work) if work-int(work)<0.5 else int(work)+1
result = 0
for el in a:
    result += (work-el)**2
print(result)

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

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

res = float("inf")
for x in range(min(A), max(A) + 1):
    cost = 0
    for j in range(n):
        y = A[j]
        cost += pow(x - y, 2)
    res = min(res, cost)
print(res)

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = 10**6
for i in range(-105,106):
    s = 0
    for j in range(n):
        s += (a[j]-i)**2
    ans = min(ans,s)
print(ans)

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

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

min_cost = 0
for each in A:
    min_cost += (each-target)**2
print(min_cost)

Solution (Python):
import math
import numpy as np

def cost(x,y):
  return (x-y)**2

def solve(lst):
  avg = math.floor(np.mean(lst))
  ans = min(sum([cost(i, avg) for i in lst]), sum([cost(i, avg+1) for i in lst]))
  return ans


if __name__ == "__main__":
  n = int(input())
  a_list = [int(i) for i in input().split()]
  print(int(solve(a_list)))

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
min_ = 10 ** 9
for i in range(-100, 101):
    scr = 0
    for j in range(N):
        scr += (i - a[j])**2
    
    if min_ > scr:
        min_ = scr
print(min_)

Solution (Python):

import sys
input = sys.stdin.readline










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

Ans = 10**8
for x in range(-100,100+1):
    ans = 0
    for i in range(N):
        ans += (A[i] - x)**2
    Ans = min(Ans,ans)

print(Ans)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
ave1 = sum(A)//len(A)
ave2 = ave1+1
Ans1 = 0
Ans2 = 0
for i in range(n):
  Ans1 += (A[i] - ave1)**2
  Ans2 += (A[i] - ave2)**2
Answer = min(Ans1,Ans2)
print(Answer)

Solution (Python):
n = int(input())
*L, =map(int, input().split())
x = 0
ans = 0
min_L = min(L)
max_L = max(L)
for i in range(min_L,max_L):
    x = sum([((L[j])-i)**2 for j in range(len(L))])
    if i == min(L):
        ans = x
    if x - ans < 0:
        ans = x
print(ans)

Solution (Python):
import sys
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
best = 10**18
for i in range(-100,101):
    score = sum([(i-a)**2 for a in a_ls])
    best = min(score, best)
print(best)

Solution (Python):
url = "https://atcoder.jp/contests/abc043/tasks/arc059_a"

def main():

    all = int(input())
    num_li = list(map(int, input().split()))

    n = sum(num_li) // all + 1
    end = min(num_li)
    ans = 10000000
    for i in range(n, end - 1, -1):
        tmp = 0
        for v in num_li:
            if v == i:
                continue
            else:
                tmp += keisan(v, i)

        if tmp < ans:
            ans = tmp
    print(ans)

def keisan(v, x):
    return (v - x) ** 2

if __name__ == '__main__':
    main()

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

for i in range(-100,101):
    count = 0
    for j in range(n):
        if a[j] != i:
            tmp = (a[j] - i)**2
            count += tmp
    if count < mn:
        mn = count

print(mn)

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

Solution (Python):
import numpy as np

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

A = N
B = sum(L) * 2
C = sum(L2)

lim = round(B / A / 2)

l = list(map(lambda x: x - lim, L))
l2 = list(map(lambda x: x ** 2, l))

print(sum(l2))

Solution (Python):
n=int(input())
a=sorted(map(int,input().split()))
m=1000000
for i in range(a[0],a[-1]+1):
    s=sum(map(lambda j:(j-i)**2,a))
    if m>s:m=s
print(m)

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

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

cost=[]
for t in range(-100, 101):
    cost.append(sum([(val-t)**2 for val in a]))
print(min(cost))

Solution (Python):
N = int(input())
l = [int(x) for x in input().split()]
cost = 1000000000000
for i in range(-100,101):
  co = 0
  for j in range(N):
    co += (i - l[j]) ** 2
  if cost > co:
    cost = co
print(cost)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
ans=1000000000
for i in range(-100,101):
	ss=0
	for j in A:
		ss+=(j-i)*(j-i)
	ans=min(ans, ss)
print(ans)

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

from statistics import mean
c_n =mean(A_s)
c_n = round(c_n)
cost = 0
for i in range(N):
    cost+=(A_s[i]-c_n)**2
print(cost)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
m=99999999999999
for i in range(min(a),max(a)+1):
    k=0
    for j in a:
        k=k+(j-i)**2
    if k<m:
        m=k
print(m)

Solution (Python):
n = int(input())
numbers = list(map(int, input().split()))
min_num = min(numbers)
max_num = max(numbers)
cost = -1
for i in range(min_num, max_num):
    temp = 0
    for number in numbers:
        temp += (number - i) ** 2
    
    if cost == -1 or temp < cost:
        cost = temp
if cost == -1:
    cost = 0
print(cost)

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
min = float('inf')
for y in range(-100, 101):
    sum = 0
    for x in a:
        sum += (x - y) ** 2
    if min > sum:
        min = sum

print(min)

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

num = round(sum(A) / len(A))
cost = [(a - num)**2 for a in A]

print(sum(cost))

Solution (Python):
import numpy as np
from sys import maxsize

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

res = maxsize
for i in range(a.min(), a.max()+1):
    val = np.sum((a-i)**2)
    if val < res:
        res = val

print(res)

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

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

Solution (Python):
import sys

n = int(input())
numeros = [int(x) for x in input().split()]
saida = sys.maxsize

for i in range(min(numeros), max(numeros)+1):
	valor = 0
	for j in numeros:
		valor += (j-i)**2
	
	saida = min(valor, saida)

print(saida)

Solution (Python):
from math import ceil

n = int(input())
numeros = [int(x) for x in input().split()]
saida = 2000000000000000

for i in range(min(numeros), max(numeros)+1):
	valor = 0
	for j in numeros:
		valor += (j-i)**2
	
	saida = min(valor, saida)

print(saida)

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

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

c = round(sum(b)/len(b))

ans = 0
for i in range(a):
    d = b[i] - c
    ans += d**2

print(ans)

Solution (Python):
import sys
 
_input1 = int(input())
_input2 = [int(s) for s in input().split()]
_output = sys.maxsize
 
for i in range(min(_input2),max(_input2)+1):
    score = 0
    for j in _input2:
        score += (j-i)**2
 
    if score < _output:
        _output = score
 
print(_output)

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

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

print(all_cost)

Solution (Python):

import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(N: int, a: "List[int]"):

    target = int(round(sum(a)/N))

    s = 0
    for aa in a:
        s += (target-aa)**2
    print(s)

    return


def main():

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys

_input1 = int(input())
_input2 = [int(s) for s in input().split()]
_output = sys.maxsize

for i in range(min(_input2),max(_input2)+1):
    score = 0
    for j in _input2:
        score += (j-i)**2

    if score < _output:
        _output = score

print(_output)

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

def rewrite(n,l):
    cost=0
    for i in l:
        cost += (i-n)**2
    return cost

r1=rewrite(int(sum(a)/len(a)),a)
r2=rewrite(int(sum(a)/len(a))+1,a)

print(r1 if r1<r2 else r2)

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

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

mean = round(sum(a)/len(a))
ans = 0
for i in range(N):
    ans += (a[i]-mean)**2

print(ans)

Solution (Python):
"""
kari1 = '2'
kari2 = '4 8' 






in1 = kari1
in2 = kari2.split()
"""
in1 = input()
in2 = input().split()

AVEa = 0
RC   = 0
for item in in2:
    AVEa = AVEa + int(item)

AVEa = round(AVEa / len(in2))

for item in in2:
    if int(item) != AVEa:
        RC = RC + ((int(item) - AVEa) ** 2)

print(RC)

Solution (Python):
n,*a=map(int,open(0).read().split())
ans=10**9
for i in range(-100,101):
  c=0
  for a_i in a:
    c+=(a_i-i)**2
  ans=min(ans,c)
print(ans)

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

ans = 10**9

for x in range(-100, 101):
    tmp = 0
    for y in a:
        tmp += abs(y-x) ** 2
    ans = min(ans,tmp)

print(ans)

Solution (Python):
import math

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

sub1 = math.floor(mean)
sub2 = math.ceil(mean)

ans1 = 0
ans2 = 0

for i in range(n):
    ans1 += (a[i]-sub1)**2
    ans2 += (a[i]-sub2)**2
    
print(min(ans1,ans2))

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

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

Solution (Python):


from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key



__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

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

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

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x



if __name__ == '__main__':
    N = intinput()
    As = list(map(int, input().split()))

    
    
    
    
    min_total = 100010001
    for i in range(-100, 101):
        tmp = 0
        for a in As:
            tmp += (a-i)*(a-i)
        min_total = min(min_total, tmp)

    
    print(min_total)

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

min = None
for y in range(-100, 101):
    sum = 0
    for x in a:
        sum += abs(x - y) ** 2
    if min is None or min > sum:
        min = sum

print(min)

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

upper_ave = int(sum(l)/len(l)) + 1
lower_ave = int(sum(l)/len(l))

ans_1, ans_2 = 0, 0

for i in l:
    ans_1 += (i - upper_ave) ** 2
    ans_2 += (i - lower_ave) ** 2

print(min(ans_1,ans_2))

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

y = 4*10**6
for i in range(min(l), max(l) + 1):
    x = 0
    for j in range(n):
        x += (l[j] - i)**2
    y = min(y, x)

print(y)

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

alist.sort()

y = alist[0]

res = float('INF')

if y == alist[-1]:
    print(0)
    exit(0)

for i in range(y, alist[-1] + 1):
    cost = 0
    for a in alist:
        cost += (a - i)**2
    
    res = min(res, cost)
    if cost > res:
        break

print(res)

Solution (Python):

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

ans = 10 ** 10
for x in range(min(a), max(a)+1):
    ans = min(ans, sum((x - ai) ** 2 for ai in a))
    
print(ans)

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

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

for y in range(-100, 101):
    s = 0
    for i in range(N):
        s += (a[i] - y) ** 2
    if sm > s:
        sm = s

print(sm)

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

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

mean = sum(A) // n

t = 0
s = 0
for i in A:
    t += (mean - i)**2
    s += (mean + 1 - i)**2
print(min(t, s))

Solution (Python):
N=int(input())
nums=list(map(int, input().split()))
ave=round(sum(nums)/len(nums))
print(sum([ (nums[i] - ave)**2 for i in range(N)] ))

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    a=LI()
    ave1=sum(a)//N
    
    ans=[0,0]
    for i in range(N):
        ans[0]+=(ave1-a[i])**2
        ans[1]+=(ave1-a[i]+1)**2
    print(min(ans))
    

main()

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    a=LI()
    
    ans=10**10
    for t in range(-100,101,1):
        temp=0
        for i in range(N):
            temp+=(t-a[i])**2
        ans=min(ans,temp)
        
    print(ans)

main()

Solution (Python):
import sys

_ = int(input())
a = [int(x) for x in input().split()]

answer = sys.maxsize
for y in range(-100, 100 + 1):
    acc = 0
    for x in a:
        acc += (x - y) * (x - y)
    answer = min(answer, acc)
print(answer)

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

answer = 10**100
for y in range(-100, 100 + 1):
    acc = 0
    for x in a:
        acc += (x - y) * (x - y)
    answer = min(answer, acc)
print(answer)

Solution (Python):
import math
N = int(input())
A = [int(x) for x in input().split()]
s = sum(A)
if s % N== 0:
    ave = s // N
    ans = [(x - ave)**2 for x in A]
    ans = sum(ans)
    print(ans)
    exit()
else:
    ave1, ave2 = math.ceil(s / N), math.floor(s / N)
    ans1 = [(x - ave1)**2 for x in A]
    ans2 = [(x - ave2)**2 for x in A]
    ans = min(sum(ans1), sum(ans2))
    print(ans)

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

Solution (Python):
import math

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

x = round(sum(a) / N)

ans = 0
for i in range(N):
    ans += math.pow(x - a[i], 2)

print(int(ans))

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

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
ans=float("INF")
for i in range(-100,101):
    ans_=sum((a-i)**2 for a in A)
    ans=min(ans,ans_)
print(ans)

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

m = sum(a) // n
ans = 0
for x in a:
    ans += (x - m) ** 2
ansp = 0
for x in a:
    ansp += (x - m - 1) ** 2
print(min(ans, ansp))

Solution (Python):

import numpy as np
n = int(input())
a = np.array(list(map(int, input().split( ))))

ans = 10**10

for i in range(-100,101):
    tmp = ((a-i)**2).sum()
    ans = min(tmp,ans)
print(ans)

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

x = round(sum(A)/n)
print(sum((a-x)**2 for a in A))

Solution (Python):

import math
n=int(input())
a=list(map(int,input().split()))
h=round(sum(a)*10/n,-1)/10
s=0
for i in a:
    s+=(i-h)**2
print(int(s))

Solution (Python):
num = int(input())
input_num = input()
num_list = [int(i) for i in input_num.split(" ")]
num_list.sort()
min = num_list[0]
max = num_list[num-1]
if min== max:
    print(0)
    exit()
min_sum = 100**3
for i in range(min,max):
    temp_sum = 0
    for j in range(0,num):
        temp_sum += (num_list[j] - i)**2
    if min_sum>temp_sum:
        min_sum = temp_sum
print(min_sum)