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())
num=list(map(int,input().split()))
ans=10000000
for i in range(min(num),max(num)+1):
    cost=0
    for j in range(n):
        cost+=((num[j]-i)**2)
    if cost<ans:
        ans=cost
print(ans)

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


min_cost = -1
for i in range(-100, 101):
  cost = 0
  for k in range(N):
    cost += (i - a[k])**2
  if min_cost == -1:
    min_cost = cost
  else:
    min_cost = min(min_cost, cost)

print(min_cost)

Solution (Python):

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


min_cost = 111*(200**2)

for y in range(min(a_list),max(a_list) + 1):
    cost = 0
    
    for x in a_list:
        cost += (x - y)**2
    
    if cost < min_cost:
        min_cost = cost

print(min_cost)

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

Solution (Python):


from statistics import mean

N=int(input())
A=list(map(int,input().split()))
a1=int(mean(A))
a2=a1+1
ans=10**9

tmp=0
for i in range(N):
    tmp+=(A[i]-a1)**2
ans=min(ans,tmp)

tmp=0
for i in range(N):
    tmp+=(A[i]-a2)**2
ans=min(ans,tmp)

print(ans)

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = float("inf")
for i in range(A[0], A[-1]+1):
    med = i
    tmp = 0
    for j in range(N):
        tmp += (A[j] - med)**2
    ans = min(ans, tmp)
print(ans)

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

Solution (Python):
import numpy as np


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

res = []
for num in range(-100, 101):
    candidate = (A-num)**2
    res.append(candidate.sum())

print(min(res))

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

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

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

ans=float('inf')
num=-100
while num!=101:
    kari=0
    for i in range(n):
        kari+=(num-a[i])**2
    num+=1
    ans=min(ans,kari)

print(ans)

Solution (Python):
import math
N=int(input())
A=list(map(int,input().split()))
ans = []
AV=sum(A)//N
for j in range(AV-10,AV+11):
    kouho=[]
    for i in A:
        kouho.append((i-j)**2)
    ans.append(sum(kouho))
print(min(ans))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = 100*100*100
for d in range(-100,101):
    t = 0
    for e in A:
        t += (e-d)**2
    ans = min(t,ans)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = 100*100*100
for d in range(-100,101):
    t = 0
    for e in A:
        t += (e-d)**2
    ans = min(t,ans)
print(ans)

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

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

b = round(sum(a) / n)
ans = 0
for i in a:
    ans += (i - b) ** 2

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
def custom_round(number, ndigits=0):
    if type(number) == int:
        return number
    d_point = len(str(number).split('.')[1])
    if ndigits >= d_point:
        return number
    c = (10 ** d_point) * 2
    
    return round((number * c + 1) / c, ndigits)
    
ave=custom_round(sum(a)/n)
ans=0
for i in a:
    ans+=(ave-i)**2
print(int(ans))

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
A.sort()
p=n//2
q=n//2-1
ave=sum(A)//n
ave2=ave+1
ans1=0
ans2=0
ans3=0
ans4=0
for i in range(n):
    ans1+=(A[i]-A[q])**2
    ans2+=(A[i]-A[p])**2
    ans3+=(A[i]-ave)**2
    ans4+=(A[i]-ave2)**2
print(min(ans1,ans2,ans3,ans4))

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

x = round(sum(ls) / n)
ans = 0

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

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
import numpy as np
ans_list=[]
array = np.array(a)
for i in range(min(a),max(a)+1):
  ans_list.append(((array - i) **2).sum())
print(min(ans_list))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
min_cost = 10**18
for i in range(min(A),max(A)+1):
    cost = 0
    for e in A:
        cost += (e-i)**2
    if cost < min_cost:
        min_cost = cost
print(min_cost)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))
if arr.count(arr[0]) == len(arr):
    print(0)
else:
    avg = round(sum(arr) / n)
    ans = 0
    for i in arr:
        ans += (i - avg) ** 2
    print(ans)

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

Solution (Python):
import numpy as np
n = int(input())
aa = np.array(list(map(int,input().split())))

ans = float('inf')
for i in range(min(aa),max(aa)+1):
  ans = min(ans,sum((aa-i)**2))
  
print(ans)

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
N = int(input())
a = list(map(int,input().split()))
ave = Decimal(str(sum(a)/N)).quantize(Decimal("0"),rounding=ROUND_HALF_UP)
cost = 0
for i in a:
    cost += (i-ave)**2
print(cost)

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


def cost(A,ave):
    return sum(map(lambda x: (x - ave)**2, A))


c = cost(A, ave)
c1 = cost(A,ave+1)
if c < c1:
    while c < c1:
        ave -= 1
        c, c1 = cost(A, ave), c
    print(c1)
else:
    while c > c1:
        ave += 1
        c, c1 = c1, cost(A, ave)
    print(c)

Solution (Python):
N = int(input())
mylist = list(map(int, input().split()))
s = sum(mylist)
N = len(mylist)
mean = round(s/N)
ans=0
for i in range(N):
    ans=ans+(mylist[i]-mean)*(mylist[i]-mean)
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
mini = 99999999999
for x in range(-200,200):
	c = 0
	for y in a:
		c += (x-y)**2
	mini = min(c,mini)

print(mini)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = 10**10
for y in range(-100, 101):
    cost = sum([(x-y)*(x-y) for x in A])
    ans = min(ans, cost)
print(ans)

Solution (Python):
from statistics import mean
import math

n = int(input())
a = list(map(int,input().split()))
m = mean(a)
u = math.ceil(m)
l = math.floor(m)
ans = 0
can = 0
for i in a:
  ans += (i-u)**2
  can += (i-l)**2
  
print(min(ans,can))

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
min_num = min(a)
max_num = max(a)
ans = []

for num in range(min_num,max_num+1):
    count = 0
    for i in a:
        count += (i-num)**2
    ans.append(count)
print(min(ans))

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

def main():
    N = int(input())
    a = list(map(int,input().split()))
    x = sum(a)/N - sum(a)//N
    if  0 <= x < 0.5:
        ch = sum(a)//N
    else:
        ch = -(-sum(a)//N)
        
    ans = 0
    for i in range(N):
        ans += (ch-a[i]) ** 2
        
    print(ans)
        
if __name__ == "__main__":
    main()

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


min = float("inf")
for y in range(-100, 101, 1):
    sum = 0
    for a in range(len(A)):
        sum = sum + (A[a]-y)**2
    if min > sum:
        min = sum
        ans = y

print(min)

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

for i in range(min(a),max(a)+1):
    cost = 0
    for j in range(n):
        cost += (a[j]-i)**2
    ans = min(cost, ans)

print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = round(sum(a)/n)
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()))

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

print(ans)

Solution (Python):
N = int(input())
A =[int(x) for x in input().split()]
result=float('inf')
for i in range(min(A),max(A)+1):
  s=0
  for j in range(N):
    s += (i-A[j])**2
  result=min(result,s)
print(result)

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

D = list(map(int, input().split()))
if sum(D) > 0:
    target = int(sum(D) / N + 0.5)
else:
    target = int(sum(D) / N - 0.5)
ans = 0
for i in D:
    ans += (target - i)*(target - i)

print(ans)

Solution (Python):
import numpy as np

if __name__=="__main__":
    n = int(input())
    a = [int(i) for i in input().split()]
    l = np.array(a)
    u = round(l.sum()/n)
    print(int(((l-u)**2).sum()))

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

min_a = min(A)
max_a = max(A)

ans = float('inf')

for i in range(min_a,max_a+1):
    num = 0
    for a in A:
        num += (a-i)**2
    ans = min(ans,num)

print(ans)

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

min_a = float("inf")

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

print(min_a)

Solution (Python):

import sys
n =int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().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()))
if set(A) == 1:
  print(0)
  exit()
  
ans = 1<<60
for i in range(-100, 101):
  cost = 0
  for a in A:
    cost += (a-i)**2
  ans = min(ans, cost)
print(ans)

Solution (Python):
n = int(input())
*a, = map(int, input().split())
atai = round(sum(a) / n)
ans = 0
for x in a:
    if x == atai:
        pass
    else:
        ans += (x - atai) ** 2
print(ans)

Solution (Python):
def solve(n: int, values: list) -> int:
    min_cost = 10000 * n
    for target in range(-100, 100 + 1):
        cost = sum([(v - target) ** 2 for v in values])
        if cost < min_cost:
            min_cost = cost
    return min_cost


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

Solution (Python):
import math
import fractions

n = int(input())
a = [int(i) for i in input().split()]
ans = 10 ** 6
for i in range(min(a), max(a) + 1):
    cost = 0
    for j in a:
        cost += (i - j) ** 2
    ans = min(ans, cost)
print(ans)

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

ans = float('inf')

for m in range(-100,101):
    ans = min(ans,sum(map(lambda x:(x-m)**2,a)))

print(ans)

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

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

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
a = [int(x) for x in input().split()]
a = np.array(a)
ans = []
for i in range(-100, 101):
    b = np.array([i] * N)
    c = ((a - b) * (a - b)).sum()
    ans.append(c)
print(min(ans))

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

Solution (Python):
def calc_cost(i,an):
  ans = 0
  for a in an:
    ans += (i-a)*(i-a)
  return ans

n = int(input())
an = list(map(int,input().split()))
ans = 0
cost = 0
pre = 10000000000
for i in range(min(an),max(an)):
  x = calc_cost(i,an)
  if pre > x:
    ans = x
  pre = x
print(ans)

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

mean = round(sum(a)/len(a))

costs = 0
for i in a:
    costs += (i-mean)**2

print(costs)

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

if len(set(a)) == 1:
    print(0)
    exit()

mi = min(a)
ma = max(a)

min_sum = 1000000000000000000

for i in range(mi, ma+1):
    sum = 0
    for j in range(n):
        sum += (a[j] - i)**2
    if sum < min_sum:
        min_sum = sum

print(min_sum)

Solution (Python):
n = int(input())
s = list(map(int, input().split()))
total = sum(s)
lower_mean = total // n
upper_mean = total // n + 1
r1 = sum([(x-lower_mean) ** 2 for x in s])
r2 = sum([(x-upper_mean) ** 2 for x in s])
r = min(r1, r2)
print(r)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
x=10**9+7
if max(l)==min(l):
    print(0)
else:
        
    for i in range(min(l),max(l)+1):
        te=0
        
        for j in l:
            te=te+(abs(j-i))**2
        
        x=min(x,te)
    print(x)

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

I1 = sum(A)//N
I0 = I1 - 1
I2 = I1 + 1

cost0 = 0
cost1 = 0
cost2 = 0
for a in A:
  cost0 = cost0 + (a-I0)*(a-I0)
  cost1 = cost1 + (a-I1)*(a-I1)
  cost2 = cost2 + (a-I2)*(a-I2)
print(min(min(cost1, cost2), cost0))

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

mincost = float('inf')
for x in range(-100, 101):
    costs = 0
    for _a in a:
        costs += (_a - x) ** 2
    mincost = min(costs, mincost)
print(mincost)

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

Solution (Python):
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

amin = min(A)
amax = max(A)

ans = 10**19
for num in range(amin, amax+1):
	cnt = 0
	for a in A:
		cnt += (a-num)**2
	ans = min(ans, cnt)
	
print(ans)

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

if sum(A)%len(A) == 0:
  avrA = sum(A)/len(A)

else:
  if (sum(A) / len(A)) < (sum(A) // len(A) + 0.5):
    avrA = sum(A) // len(A)
  else:
    avrA = sum(A) // len(A) +1

dst = 0
for i in A:
  dst += (i-avrA)**2
print(int(dst))

Solution (Python):


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

def cost(l,N):
    total = 0
    for i in l:
        total += (i-N)**2
    return total
    
ans = 100000000


for i in range(-100,101):
    check = cost(a,i)
    if check < ans:
        ans = check

print(ans)

Solution (Python):
number = int(input())
number_list = list(map(int, input().split()))

num = 0
for i in number_list:
    num += i

ex = num // number
cost_list = []

def cul(ex):
    cost = 0
    for i in number_list:
        cost += (ex - i)**2
    cost_list.append(cost)

cul(ex)
cul(ex+1)
cul(ex-1)

print(min(cost_list))

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

li_ans = []
ans = 0

for j in range(min(a), max(a)):
    for k in a:
        ans += abs(k - j) ** 2
    
    li_ans.append(ans)
    ans = 0

if len(li_ans) == 0:
    print(0)
else:
    print(min(li_ans))

Solution (Python):
import sys
import numpy as np

I = np.array(sys.stdin.read().split(), dtype=np.int64)
a = I[1:]

def main():
    m = int(np.around(np.mean(a)))
    ans = np.sum((a - m) ** 2)
    return ans

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

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

r = round(sum(a) / len(a))
w = 0
for ae in a:
    w += pow(ae - r, 2)
print(w)

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

import math
av=sum(li)/N
if av-math.floor(av)<0.5:
  m=math.floor(av)
else:
  m=math.floor(av)+1

squaresum=0
for i in li:
  squaresum+=(i-m)**2
  
print(squaresum)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
A = 0
B = 0
for i in range(N):  
    A += a[i] * a[i]
    B += a[i]

for Y in range(-100, 101):
    temp = A - 2 * Y * B + N * Y * Y
    if Y == -100:
        ans = temp
    else:
        if temp <= ans:
            ans = temp
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
avg=sum(a)//n
ans=10**18
for i in (avg-1,avg,avg+1):
  ansc=0
  for j in a:
    ansc+=(j-i)**2
  ans=min(ans,ansc)
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
ans = (200**2)*N

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

print(ans)

Solution (Python):
def two_int():
    N, K = map(int, input().split())
    return N,K

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

def one_str():
    return input()

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

N=one_int()
X=many_int()

sort_X=sorted(X)
min_X = sort_X[0]
max_X = sort_X[-1]

min_num = 0
min_sum = 99999999999
for i in range(min_X, max_X+1):
    temp_sum = 0
    for j in X:
        temp_sum += (j-i)**2
    
    if temp_sum < min_sum:
        min_sum = temp_sum
        min_num = i

print(min_sum)

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

mid = sum(a)//len(a)
ans1 = 0
ans2 = 0

for i in a:
  ans1 += pow(abs(i - mid),2)
  ans2 += pow(abs(i - (mid+1)),2)
print(min(ans1, ans2))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
average = round(sum(a) / len(a))
costs = 0

for i in a:
    costs += (i - average)**2

print(costs)

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

n = round(sum(a)/N)

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

print(int(ans))

Solution (Python):
import sys


N = int(input())

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

ans = 10**18

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())
a=list(map(int,input().split()))
ans=10**18
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())
a=list(map(int,input().split()))
y=round(sum(a)/n)
ans=n*y*y-2*y*sum(a)
for x in a:
  ans+=x*x
print(ans)

Solution (Python):



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

mx = max(A)
mn = min(A)

R = -1
for i in range(mn, mx + 1):
    s = 0
    for a in A:
        s += (i - a)** 2
    R = s if R < 0 or s < R else R

print(R)

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

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

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

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

print(ans)

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

min_cost = 10 ** 10

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

print(min_cost)

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

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

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

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


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


tmp = sum(A) // N
print(min(
    sum(map(lambda x: f(x, tmp), A)),
    sum(map(lambda x: f(x, tmp + 1), A))
)
)

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

Solution (Python):
a=int(input())
b=input().rstrip().split()
l=[]
SUM = 0
for i in range(a):
    l.append(int(b[i]))
    SUM+=int(b[i])
ave=SUM//a
ave1=SUM//a+1

def keisan(ave,l):
    y=0
    for i in range(len(l)):
        y+=(int(l[i])-ave)**2
    return y

if (keisan(ave,l)<keisan(ave1,l)):
    print(keisan(ave,l))
else:
    print(keisan(ave1,l))

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

Solution (Python):
from sys import stdin
import math

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

ave = math.ceil(sum(li)/n)
ave2 = sum(li)//n

point = 0
point2 = 0

for i in li:
    point += (ave-i)**2
    point2 += (ave2-i)**2

print(min(point,point2))

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
med = sum(A)//n
ans = float('inf')
for m in range(med-1,med+2):
    res = 0
    for a in A:
        res += abs(a-m)**2
    ans = min(ans,res)
print(ans)

Solution (Python):
def calcCost(ave_num, num):
    cost = (num - ave_num) ** 2
    return cost
 
N = int(input())
numbers = [int(i) for i in input().split()]
 
if len(set(numbers)) == 1:
    print(0)
else :
    
    ave_num = round(sum(numbers) / N)
 
    total_cost = 0
    for num in numbers:
        total_cost += calcCost(num, ave_num)
    
    print(total_cost)

Solution (Python):
def calcCost(ave_num, num):
    cost = (num - ave_num) ** 2
    return cost

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

if len(set(numbers)) == 1:
    print(0)
else :
    
    ave_num = round(sum(numbers) / N)

    total_cost = 0
    for num in numbers:
        total_cost += calcCost(num, ave_num)
    
    print(total_cost)

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

print(min(ans))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = 10 ** 18
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+1
for i in (0,1):
  val=0
  for a in A:
    val+=(a-int(sum(A)/len(A))-i)**2
  ans=min(ans,val)
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
st=int(sum(A)/len(A))
go=st+1
ans=10**9+1
for i in range(st,go+1):
  val=0
  for a in A:
    val+=(a-i)**2
  ans=min(ans,val)
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
st=min(A)
go=max(A)
ans=10**9+1
for i in range(st,go+1):
  val=0
  for a in A:
    val+=(a-i)**2
  ans=min(ans,val)
print(ans)

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

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

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

ave = round(sum(a) / len(a))

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

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))

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

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

p = min(a)
q = max(a)

res = 4000000
for x in range(p, q+1):
    tmp = 0
    for y in a:
        tmp += (x - y) ** 2
    res = min(res, tmp)

print(res)

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

avg = round(sum(nums) / len(nums))
cost = 0
for x in nums:
    if x == avg:
        continue
    cost += (x - avg)**2

print(cost)

Solution (Python):
import math

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

avg_ceil = math.ceil(sum(nums) / len(nums))
avg_floor = math.floor(sum(nums) / len(nums))

cost_ceil = 0
cost_floor = 0

for x in nums:
    if x == avg_ceil:
        continue
    cost_ceil += (x - avg_ceil)**2

for x in nums:
    if x == avg_floor:
        continue
    cost_floor += (x - avg_floor)**2

if cost_ceil <= cost_floor:
    print(cost_ceil)
else:
    print(cost_floor)

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

y = int(round(float(sum(a)) / N))

print sum((x - y) ** 2 for x in a)

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

mi = 1<<100
for i in range(min(A), max(A)+1):
    mi = min(mi, sum([(a-i)**2 for a in A]))

print(mi)

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

ans = sum([i**2 for i in a])

for i in range(-100, 100+1):
    s = sum([(j-i)**2 for j in a])
    if ans > s:
        ans = s

print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
sumA = sum(A)
t = sumA//n
p, q = 0, 0
for i in range(n):
  p += (t-A[i])**2
  q += (t+1-A[i])**2
print(min(p, q))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
import math
mean = sum(a) / n
smaller = math.floor(mean)
larger = math.ceil(mean)
a_smaller = [(i - smaller) ** 2 for i in a]
a_larger = [(i - larger) ** 2 for i in a]
if sum(a_smaller) <= sum(a_larger) :
    print(sum(a_smaller))
elif sum(a_smaller) > sum(a_larger) :
    print(sum(a_larger))

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

def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    ans = 10**10
    for i in range(-100,101):
        can = 0
        for j in range(n):
            can += (ls[j]-i)**2
        if can<=ans:
            ans = can
    
    print(ans)
if __name__=='__main__':
    main()

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

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

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

ans=float("inf")
for i in range(-100,101):
    cnt=0
    for u in a:
        cnt+=(min(abs(u-i),abs(i-u)))**2
    ans=min(cnt,ans)

print(ans)

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]
s = int()
cost = 1000000

for i in range(-100,101):
    for t in range(N):
        s += (a[t] - i)*(a[t] - i)
    if  s < cost:
        cost = s
    s =int(0)

print(cost)

Solution (Python):

import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = inf
count = 0

n=int(input())
A=list(map(int,input().split()))
for num in range(-100,101):
    tmp=0
    for ai in A:
        tmp+=(num-ai)**2
    ans=min(ans,tmp)
print(ans)

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

ans = 10 ** 10

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

print(ans)

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

s = 200**2 * 100
for x in range(min(A), max(A)+1):
    s = min(s, sum((x-a)**2 for a in A))
print(s)

Solution (Python):
import math

N = int(input())
a = [int(i) for i in input().split()]
b = round(sum(a)/N)

c = sum([(i - b)**2 for i in a])
print(c)

Solution (Python):
import math

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    m = sum(A)/N
    ceil_eval = sum((a-math.ceil(m))**2 for a in A)
    floor_eval = sum((a-math.floor(m))**2 for a in A)
    ret = min(ceil_eval, floor_eval)
    print(ret)
    
solve()

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
mincost=float('inf')
mina = min(A)
_ = max(A) - mina

for i in range(mina,mina+_+1):
    cost = 0
    for a in A:
        cost += (a-i)**2
    if cost < mincost:
        mincost = cost
print(mincost)

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)/len(a))
cost = 0
for i in range(len(a)):
    cost += (a[i] - ave)**2
    
print(cost)

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

ave=round(sum(a)/len(a))

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

Solution (Python):
import numpy as np
N = int(input())
a = [int(i) for i in input().split()]
oppai = np.array(a)

max = np.max(oppai)
min = np.min(oppai)
x = (max+min)//2
sum = [0] * 201

for i in range(-100,101):
    oppai = np.array(a) 
    oppai -= i
    oppai = oppai**2
    sum[i+100] = np.sum(oppai)
    

chinko = np.array(sum)

print(np.min(chinko))

Solution (Python):
def main():
    N = int(input())
    A = list(int(x) for x in input().split())
    ans = float('inf')


    for i in range(-100,100+1):
        ans_tmp = 0
        for a in A:
            ans_tmp += (a-i)**2

        if ans_tmp < ans:
            ans = ans_tmp

    print(int(ans))

if __name__ == '__main__':
    main()

Solution (Python):
def calc_cost(val):
  return sum([(a-val)**2 for a in A])

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

print(min([calc_cost(num) for num in range(min(A), max(A)+1)]))

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
r=4*10**6
for i in range(min(A),max(A)+1):
	d=0
	for j in range(n):
		d+=(A[j]-i)**2
	r=min(r,d)
print(r)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
m=sum(A)//n
print(min(sum(map(lambda x:(x-m)**2,A)),sum(map(lambda x:(x-m-1)**2,A))))

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

ans=10**9
x = -100
while(x < 101):
    ans = min(ans, sum(map(lambda a: (x-a)**2, A)))
    x+=1

print(ans)

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

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

Solution (Python):
N = int(input())
A =[int(x) for x in input().split()]
result=float('inf')
for i in range(min(A),max(A)+1):
  s=0
  for j in range(N):
    s += (i-A[j])**2
  result=min(result,s)
print(result)