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):
n = int(input())
arr = list(map(int, input().split()))

ans = 10**18

for y in range(-100, 101):
    ans = min(ans, sum([(x - y) ** 2 for x in arr]))
print(ans)

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

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

print(min(sum(map(lambda x: (x - i) * (x - i), a)) for i in range(-100, 101)))

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 a in A:
        tmp += (i - a) ** 2
    ans = min(tmp, ans)

print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
x = 100
count1 = 0
for i in a:
    count1 += (i - x)**2

for X in range(-100, 100):
    count = 0
    for i in a:
        count += (i - X)**2
    if count < count1:
        count1 = count

print(count1)

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

mn = min(a)
mx = max(a)

ans = 10000000
for i in range(mn, mx+1):
    p = 0
    for j in a:
        p += (j-i) * (j-i)
    if ans > p:
        ans = p
print(ans)

Solution (Python):

N = int(input())
lst = input().split()


for i in range(len(lst)):
   lst[i] = int(lst[i])


lst.sort()


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

costs = []


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


costs.sort()




if costs != []:
   print(costs[0])
else:
   print(0)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    ans = INF
    for i in range(-100, 101):
        score = 0
        for x in a:
            score += (x - i) ** 2
        ans = min(ans, score)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    n_min, n_max = min(a), max(a)
    ans = []

    if n_min == n_max:
        return 0

    for y in range(n_min, n_max+1):
        cost = 0
        for x in a:
            cost += (x-y)**2
        ans.append(cost)

    return min(ans)


if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().rstrip().split(" ")))
ave = 0
ans = 0
for i in A:
    ave += i
ave /= N
ave = (ave + 0.5) // 1
for i in A:
    ans += (i - ave) ** 2
print(int(ans))

Solution (Python):
N = int(input())
a = sorted(list(map(int, input().split())))
answer = 10000000
for i in range(a[0], a[-1] + 1):
    cost = 0
    for num in a:
        cost += ((num - i) ** 2)
    answer = min(answer, cost)
print(answer)

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

Solution (Python):
a = int(input())
b = list(map(int,input().split()))
ans = 4000000

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
min_val = None
stacks = 0

for i in range(-100, 101):
    cost_stack = 0
    for j in range(len(a)):
        cost_stack += (a[j] - i) ** 2
        
    if min_val == None:
        min_val = cost_stack
    elif cost_stack < min_val:
        min_val = cost_stack

print(min_val)

Solution (Python):

n=int(input())
a = list(map(int, input().split()))
h=round(sum(a)/len(a))
sum_a=0
for i in range(len(a)):
    sum_a=sum_a+(a[i]-h)**2
print(int(sum_a))

Solution (Python):
import statistics
n=int(input())
a=list(map(int,input().split()))
num=round(statistics.mean(a))
print(sum([(num-i)**2 for i in a]))

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

x = sum(a) / n
y = sum(a) // n
if x == y:
   cand = [y]
else:
   cand = [y, y+1]

cost = 10**18
for ave in cand:
   c = 0
   for i in range(n):
      c += (a[i]-ave)**2
   cost = min(cost, c)

print(cost)

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

b = min(a)
c = max(a)
ans = []
for i in range(b, c+1):
  res = 0
  for j in a:
    res += (j - i)**2
  ans.append(res)

print(min(ans))

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

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

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

ans = 10000000000

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

Solution (Python):
import math


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    A = read_ints()
    avg = sum(A)/N
    cost = lambda M: sum(abs(a-M)**2 for a in A)
    return min(cost(math.floor(avg)), cost(math.ceil(avg)))


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

Solution (Python):
from statistics import mean

n = int(input())

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

m = mean(num_list)

m = round(m)

cost = 0
for num in num_list:
    cost += (num - m)**2

print(cost)

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):
import copy

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

res = 1e+9
for i in range(min(a),max(a)+1):
    tmp = copy.copy(a)
    res = min(res,sum(map(lambda x:(x-i)**2,tmp)))
print(res)

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

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

ans = 1000000000

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

print(ans)

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


for i in range(-101, 101):
    ref = 0
    for j in a:
        ref += (i - j)**2
    ans = min(ans, ref)

print(ans)

Solution (Python):
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	a_list = np.array(LI())
	cost = INF
	for a in range(-100,101):
		a_diff = (a - a_list) ** 2
		cost = min(cost, np.sum(a_diff))
	print(cost)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
S=list(map(int,input().split()))
D=[]
for i in range(-101,102):
    goukei=0
    for j in range(N):
        goukei+=(S[j]-i)**2
    D.append(goukei)

print(min(D))

Solution (Python):
'''     
        
        
        

import sys
import math


def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())

def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end=" \ ")

MODPRIME = int(1e9+7); BABYMODPR = 998244353;

ONLINE_JUDGE = 1
if not ONLINE_JUDGE:
    sys.stdin  = open("input.txt","r")
    sys.stdout = open("output.txt","w")
    sys.stderr = open("output.txt","w")


n = int(input())
li = get_list()
s = sum(li)/n
l = math.floor(s)
r = math.ceil(s)
if l == r:
    s = l
else:
    if s - l < r - s:
        s = l
    else:
        s = r
print(sum([(s-x)**2 for x in li]))

'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS BY ME @luctivud ( UDIT GUPTA )
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
DO NOT PLAGIARISE.
TESTCASES:
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

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

a_min = min(a)
a_max = max(a)

a_sum = []
for i in range(a_min, a_max + 1):
    num=0
    for j in range(n):
        num += (a[j] - i) ** 2
    a_sum.append(num)
print(min(a_sum))

Solution (Python):
n = int(input())
a_lst = list(map(int, input().split()))
max_ = max(a_lst)
min_ = min(a_lst)
res = 0
for num in range(min_, max_+1):
  cost = 0
  for a in a_lst:
    cost += (a - num) ** 2
  if res != 0:
    res = min(res, cost)
  else:
    res = cost
print(res)

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

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

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

Solution (Python):

"""
Created on Thu Jun 11 17:09:47 2020

@author: sd18016
"""

N = int(input())
a = [int(i) for i in input().split()]
ans = 100010001000

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

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

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

ans = 100010001000

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

Solution (Python):
import os, sys, re, math

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

ret = float('inf')
for i in range(-100,101):
    s = 0
    for aj in a:
        s += (aj - i) ** 2
    ret = min(ret,s)

print(ret)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split(' ')))
ans = []
if A.count(A[0]) == len(A):
    print(0)
    exit(0)
for i in range(-100,101):
    cost = 0
    for j in range(N):
        if A[j] == i:
            continue
        else:
            cost += (A[j] - i)**2
    ans.append(cost)
import heapq
heapq.heapify(ans)
print(heapq.heappop(ans))

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

def minimize(list):
    min = 1000000
    for i in range(-100,101):
        num = 0
        for j in range(len(list)):
            num = num + (int(list[j]) - i)**2
        if min >= num:
            min = num
    return min

print(minimize(a))

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

ans = 10 ** 10
for i in range(min(a), max(a) + 1):
    val = sum([(x - i) ** 2 for x in a])
    ans = min(ans, val)

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=10000000
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()))
ans=10000000
for i in range(-101,102):
    tmp=0
    for j in range(n):
        tmp+=(a[j]-i)**2
    if tmp<ans:
        ans=tmp
print(ans)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    sum_A = sum(A)
    left, right = sum_A // N, sum_A // N + 1
    loss_1 = sum([(a - left) ** 2 for a in A])
    loss_2 = sum([(a - right) ** 2 for a in A])
    if loss_1 < loss_2:
        print(loss_1)
    else:
        print(loss_2)


if __name__ == '__main__':
    main()

Solution (Python):


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

L.sort()
m = min(L)
M = max(L)

A = []
for i in range(m,M+1):
  k=0
  for j in L:
    k += (j-i)*(j-i)
  A.append(k)
  
print(min(A))

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

stock =[]

for x in range(-100,101):
    total = 0
    for i in range(n):
        total = total + (x-a[i])**2
    stock.append(total)


print(min(stock))

Solution (Python):
from math import ceil,floor
ansc,ansf = 0,0
n = int(input())
a = list(map(int,input().split()))
 
gp = sum(a)/len(a)
c = ceil(gp)
f = floor(gp)

for i in a:
  ansc += (i-c)**2
  ansf += (i-f)**2
  
print(min(ansc,ansf))

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

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

mean = sum(A)//len(A)

def std_div(mean, A):
    total = 0
    for x in A:
        total += (mean-x)**2
    return total

min1 = std_div(mean,A)
min2 = std_div(mean+1,A)

ans = min(min1,min2)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
MIN = float('inf')
for i in range(-100,101):
    tmp = 0
    for a in A:
        tmp += (a-i)**2
    MIN = min(MIN,tmp)
print(MIN)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
U,V=0,0
u=ceil(sum(lis)/n)
v=int(sum(lis)/n)
for i in range(n):
    U+=(lis[i]-u)**2
    V+=(lis[i]-v)**2
print(min(U,V))

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
mn=inf
for i in range(-100,100+1):
    sm=0
    for s in lis:
        sm+=(s-i)**2
    if sm<mn:
        mn=sm
print(mn)

Solution (Python):
import math

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

b = c = 0
for i in s:
    b += i
    c += i**2

if b%n == 0:
    print(int(c-b**2/n))
else:
    koho1 = math.floor(b/n)
    koho2 = math.ceil(b/n)
    ans = min(n*(koho1**2)-2*b*koho1+c,n*(koho2**2)-2*b*koho2+c)
    print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
maxi=max(a)
mini=min(a)
ans1=(maxi**2)*N
for i in range(mini,maxi+1):
    ans=0
    for j in a:
        ans+=abs(j-i)**2
    if ans<ans1:
        ans1=ans
print(ans1)

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

for target in range(-100, 101):
  cost = 0
  for j, a in enumerate(A):
    cost += (target - a)**2
  ans = min(ans, cost)

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
m = round(sum(A)/N)
print(sum([(a-m)**2 for a in A]))

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

for n in range(min(A),max(A)+1):
  cost.append(sum([(a-n)**2 for a in A]))

print(min(cost))

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

Solution (Python):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    round = lambda x: int((x * 2 + 1) // 2)
    m = round(sum(A) / len(A))
    ans = [(a - m) ** 2 for a in A]
    print(sum(ans))

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
l = [int(i)for i in input().split()]
r = float("inf")
for i in range(-100, 101):
    r = min(r, sum((n - i)**2 for n in l))
print(r)

Solution (Python):
count = int(input())
sum_n = 0
sum_list = []

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

for i in range(min(li),max(li) + 1):
  for j in li:
    sum_n += (i - j)**2
  sum_list.append(sum_n)
  sum_n = 0
    
print(min(sum_list))

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

val = float("inf")
for i in range(-100,101):
	new = 0
	for j in l:
		new += (i-j)**2	
	val = min(val,new)		
print(val)

Solution (Python):
n, *A = map(int, open(0).read().split())
m = round(sum(A) / n)
print(sum(map(lambda x: (x-m)**2, A)))

Solution (Python):
N = int(input())
S = list(map(int,input().split()))
ave = round(sum(S) / len(S))
ans = 0
for i in S:
    if i == ave:
        continue
    else:
       ans += (i - ave) ** 2

print(ans)

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


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

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = 10**9
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):
    k=0
    for j in a:
        k+=(j-i)**2
    ans=min(ans,k)
print(ans)

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

_max = max(a)
_min = min(a)
result = 20000 * N

for i in range(_min,_max+1,1):
  _result = 0
  for j in a:
    _result += (i - int(j))**2
  if _result <= result:
    result = _result
print(result)

Solution (Python):
n = int(input())
a = sorted(list(map(int,input().split())))
sum = 0
List_sum = []
Counter = []
Count_num = (a[-1] - a[0])+1
for i in range(Count_num):
    Counter.append(a[0]+i)
    if Counter[-1] == a[-1]:
        break
if len(set(a)) == 1:
    print(0)
else:
    for i in Counter:
        for j in a:
            sum += (i-j)**2
        else:
            List_sum.append(sum)
            sum = 0
    else:
        print(min(List_sum))

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

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

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

min_answer=float("inf")
for i in range(min(alist),max(alist)+1):
  answer=0
  for a in alist:
    answer+=(a-i)**2
    
  min_answer=min(answer,min_answer)
print(min_answer)

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

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = getList()

ans = float('inf')
for i in range(-100, 101):
    opt = 0
    for k in range(N):
        opt += (A[k] - i) ** 2
    ans = min(ans, opt)
print(ans)

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

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




N = I()
A = IL()

ans = []

for i in range(-100,101):
  ans.append(sum((a-i)**2 for a in A))

P(min(ans))

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
mean=sum(a)//n
ans=float('inf')
for i in range(5):
    t=(mean-2)+i
    tmp=0
    for j in range(n):
        tmp+=(a[j]-t)**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):
    tmp=0
    for j in range(n):
        tmp+=(i-a[j])**2
    ans=min(tmp,ans)
print(ans)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
ans = float("inf")

for i in range(min(A),max(A)+1):
    cost = 0
    
    for j in A:
        cost += (j-i)**2
        
    ans = min(ans,cost)
    
print(ans)

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

min_cost=10000000000

for x in range(-100,101):
    i=0
    for y in a:
        i+=(y-x)**2
    min_cost=min(min_cost,i)
    
print(min_cost)

Solution (Python):

def main():
    n = int(input())
    a_s = list(map(int,input().split()))
    answer = 999999999999999999999999999999999

    for i in range(-100,101):
        temp = sum([(a-i) ** 2 for a in a_s ])
        answer = min(answer,temp)
    print(answer)

if __name__ == '__main__':
    main()

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

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

print(ans)

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


decimal = sum(a) / len(a) - sum(a) // len(a)
if decimal >= 0.5:
    m = sum(a) // len(a) + 1
else:
    m = sum(a) // len(a)

ans = 0
for i in range(n):
    ans += (a[i] - m)**2

print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    res = f_inf
    for y in range(-100, 101):
        cost = 0
        for i in range(n):
            cost += pow(abs(A[i] - y), 2)
        res = min(res, cost)
    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()

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

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

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

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
a = list(map(int,input().split()))
res = 10**18
for val in range(-100,101):
    tmp = sum([(val-val2)**2 for val2 in a])
    res = min(res,tmp)
print(res)

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

max_A = max(A)
min_A = min(A)

ans = 10**9
for y in range(min_A, max_A+1):
    tmp = 0
    for a in A:
        xsuby = a - y
        tmp += xsuby ** 2
    ans = min(ans, tmp)

print(ans)

Solution (Python):
N=int(input());a=[int(i) for i in input().split()]
print(min([sum([(n-i)**2 for n in a])for i in range(-100,101)]))

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
asum = sum(a)
a2sum = 0
for m in a:
  a2sum += m**2
x1 = asum//n
x2 = x1+1
z1 = n*x1**2-2*asum*x1+a2sum
z2 = n*x2**2-2*asum*x2+a2sum
print(min(z1,z2))

Solution (Python):
ans=0
n=int(input())
res=0
a=list(map(int,input().split()))
b=sum(a)//n
c=b+1
for i in a:
    ans+=abs(i-b)**2
    res+=abs(i-c)**2
print(min(ans,res))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = float('inf')
for i in range(-100, 101):
    dummy = 0
    for a_i in a:
        dummy += pow((a_i-i), 2)
    ans = min(ans, dummy)
print(ans)