AtCoder Beginner Contest 043 - Be Together

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-----
2
4 8

-----Sample Output-----
8

Transforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.

Source: atcoder | Difficulty: EASY


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


a = int(input())
b = input().split(' ')
i1 = 0
i2 = 0
i3 = 0
for i in b:
	i1 += int(i)
i2 = round(i1 / a)
for i in b:
	i3 += (int(i) - i2) ** 2
print(i3)


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)


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))))


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)


def sam(lst):
	return lst[1:] == lst[:-1]
n = int(input())
s = [int(x) for x in input().split()]
if sam(s):
	print(0)
else:
	x = round(sum(s) / n)
	n = 0
	for elem in s:
		n += (elem - x) ** 2
	print(n)


N = int(input())
A = [int(n) for n in input().split()]
avg = round(sum(A) / N)
cost = sum([(a - avg) ** 2 for a in A])
print(cost)


n = int(input())
a = sorted(map(int, input().split()))
ave = round(sum(a) / n)
ans = sum(map(lambda x: (ave - x) ** 2, a))
print(ans)


n = int(input())
a = list(map(int, input().split()))
h = round(sum(a) / n)
g = 0
for i in a:
	g += abs(h - i) ** 2
print(g)


n = int(input())
a = list(map(int, input().split()))
t = sum(a) / n
if t > 0:
	t += 0.5
t = int(t)
print(sum(list(map(lambda x: (t - x) ** 2, a))))


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]))


(n, *A) = map(int, open(0).read().split())
print(min((sum(((x - a) ** 2 for a in A)) for x in range(-100, 101))))


from sys import stdin
input = stdin.readline
N = int(input())
A = list(map(int, input().split()))
if len(set(A)) != 1:
	cost = 2 ** 20
	for i in range(-100, 101):
		tc = 0
		for a in A:
			tc += (a - i) ** 2
		if cost > tc:
			cost = tc
else:
	cost = 0
print(cost)


N = int(input())
A = list(map(int, input().split()))
AVE = round(sum(A) / len(A))
print(sum(((AVE - i) ** 2 for i in A)))


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


N = int(input())
a = sorted(list(map(int, input().split())))
ans = 10 ** 9
for i in range(a[0], a[-1] + 1):
	s = 0
	for j in range(N):
		x = (a[j] - i) ** 2
		s += x
	ans = min(ans, s)
print(ans)


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]))


n = int(input())
a = list(map(int, input().split()))
a_u = round(sum(a) / n)
a_d = int(sum(a) / n)
ans_u = 0
ans_d = 0
for i in range(n):
	ans_u += (a[i] - a_u) ** 2
	ans_d += (a[i] - a_d) ** 2
print(min(ans_u, ans_d))


N = int(input())
a = list(map(int, input().split()))
mi = min(a)
ma = max(a)
ans = float('inf')
for i in range(mi, ma + 1):
	ans = min(ans, sum(((i - ai) ** 2 for ai in a)))
print(ans)


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


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


n = int(input())
a = list(map(int, input().split()))
r = round(sum(a) / len(a))
l = []
for i in a:
	l.append((i - r) ** 2)
print(sum(l))


N = int(input())
An = [int(x) for x in input().split()]
ans = 200 ** 2 * N
for i in range(-100, 101):
	ans = min(ans, sum([(a - i) ** 2 for a in An]))
print(ans)


n = int(input())
lst = list(map(int, input().split()))
m = 10 ** 10
for i in range(201):
	a = i - 100
	temp = 0
	for j in range(n):
		temp += (lst[j] - a) ** 2
	m = min(m, temp)
print(m)


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)


def main():
	n = int(input())
	al = list(map(int, input().split()))
	maxval = max(abs(max(al)), abs(min(al)))
	cost = []
	if len(list(set(al))) == 1:
		print('0')
	else:
		k = -1
		for i in range(-100, 100):
			k += 1
			cost.append(0)
			for j in range(n):
				cost[k] = cost[k] + (al[j] - i) ** 2
		print(min(cost))

def __starting_point():
	main()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
t = 10 ** 9
for i in range(min(a), max(a) + 1):
	num = 0
	for h in a:
		num += (h - i) ** 2
	if num <= t:
		t = num
print(t)


N = int(input())
(*A,) = list(map(int, input().split()))
mx = max(A)
mn = min(A)
if len(set(A)) == 1:
	print(0)
else:
	ans = float('inf')
	for i in range(mn, mx):
		ans = min(ans, sum([(k - i) ** 2 for k in A]))
	print(ans)


n = int(input())
a = list(map(int, input().split()))
ave = sum(a) // n
print(min(sum([pow(i - ave, 2) for i in a]), sum([pow(i - ave - 1, 2) for i in a])))


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


n = int(input())
(*l,) = map(int, input().split())
ans = 10 ** 6
for i in range(-100, 101):
	tmp = sum([(y - i) ** 2 for y in l])
	ans = min(tmp, ans)
print(ans)


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


N = int(input())
A = list(map(int, input().split()))
d = round(sum(A) / N)
ans = 0
for i in A:
	ans = ans + (i - d) ** 2
print(ans)


import numpy as np
import logging
logging.basicConfig(level=logging.DEBUG)
logging.disable(logging.CRITICAL)
N = int(input())
x = np.array(list(map(int, input().split())))
logging.debug('x={}'.format(x))
i = np.amin(x)
ans = []
while i <= np.amax(x):
	logging.debug('i={}'.format(i))
	y = np.array([i] * N)
	ans.append(sum((x - y) ** 2))
	logging.debug('ans={}'.format(ans))
	i += 1
print(min(ans))


(n, A) = open(0)
print(min((sum(((x - int(a) - 100) ** 2 for a in A.split())) for x in range(201))))


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


N = int(input())
a = list(map(int, input().split()))
n = round(sum(a) / N)
print(int(sum([abs(a[i] - n) ** 2 for i in range(N)])))


import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inl = lambda : [int(x) for x in sys.stdin.readline().split()]
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))

def solve():
	n = ini()
	a = inl()
	s = sum(a)
	m1 = s // n
	m2 = (s + n - 1) // n
	s1 = sum(((x - m1) ** 2 for x in a))
	s2 = sum(((x - m2) ** 2 for x in a))
	return min(s1, s2)
print(solve())


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)


n = int(input())
arr = list(map(int, input().split()))
x = round(sum(arr) / n)
print(sum(((x - i) ** 2 for i in arr)))


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

def calc_cost(x, avg):
	return (x - avg) ** 2
avg = sum(a) // N
delta = [-2, -1, 0, 1, 2]
ans = 10 ** 20
for i in range(len(delta)):
	val = sum(map(lambda x: calc_cost(x, avg + delta[i]), a))
	ans = min(ans, val)
print(ans)


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


N = int(input())
(*a,) = map(int, input().split())
print(min(([sum(map(lambda x: (x - n) ** 2, a)), n] for n in range(-100, 101)))[0])


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


N = int(input())
A = [int(x) for x in input().split()]
from statistics import mean
from math import floor, ceil
meanA = mean(A)
if meanA < floor(meanA) + 0.5:
	meanA = floor(meanA)
else:
	meanA = ceil(meanA)
ans = 0
for a in A:
	ans += (a - meanA) ** 2
print(ans)


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


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)]))


n = int(input())
a = list(map(int, input().split()))
m1 = sum(a) // n
m2 = (sum(a) + n - 1) // n
res1 = 0
res2 = 0
for i in range(n):
	res1 += (a[i] - m1) ** 2
	res2 += (a[i] - m2) ** 2
print(min(res1, res2))


n = int(input())
A = list(map(int, input().split()))
ans = float('inf')
for x in range(-100, 101, 1):
	c = 0
	for a in A:
		c += (a - x) ** 2
	ans = min(c, ans)
print(ans)


n = int(input())
an = [int(x) for x in input().split()]
avg = round(sum(an) / n)
print(sum([(ai - avg) ** 2 for ai in an]))


import math
import statistics
N = int(input())
A = [int(x) for x in input().split()]
avg = math.floor(statistics.mean(A))
a = 0
b = 0
for i in range(len(A)):
	a += (A[i] - avg) ** 2
	b += (A[i] - avg - 1) ** 2
print(min(a, b))


def main():
	n = int(input())
	inlis = list(map(int, input().split()))
	ans = 10 ** 10
	for kouho1 in range(-100, 101):
		tmp1 = 0
		for i in range(n):
			tmp1 += (inlis[i] - kouho1) ** 2
		if tmp1 < ans:
			ans = tmp1
	print(ans)

def __starting_point():
	main()
__starting_point()


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)


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


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


N = int(input())
a = list(map(int, input().split()))
A = sum(a) // N
B = (sum(a) - 1) // N + 1
print(min(sum(((x - A) * (x - A) for x in a)), sum(((x - B) * (x - B) for x in a))))


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


n = int(input())
a = [int(i) for i in input().split()]
b = 1000000000.0
for ans in range(-100, 100 + 1):
	b = min(b, sum([(i - ans) ** 2 for i in a]))
print(b)


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


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


N = int(input())
lst = list(map(int, input().split()))
avg = round(sum(lst) / N)
result = 0
for i in lst:
	result += (i - avg) ** 2
print(result)


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


N = int(input())
A = list(map(int, input().split()))
(X, out) = (round(sum(A) / N), 0)
for i in range(N):
	out += (A[i] - X) ** 2
print(out)


n = int(input())
a = [int(i) for i in input().split()]
m = sum(a) / len(a)
num = round(m)
loss = 0
for n in a:
	loss += (n - num) ** 2
print(loss)


N = int(input())
s = list(map(int, input().split()))
s_max = max(s)
s_min = min(s)
A = []
for i in range(s_min, s_max + 1):
	b = 0
	for j in s:
		b += (j - i) ** 2
	A.append(b)
print(min(A))


N = int(input())
a = list(map(int, input().split()))
b = sum(a)
c = sum(map(lambda x: x ** 2, a))
d = round(b / N)
ans = N * d ** 2 - 2 * d * b + c
print(int(ans))


N = int(input())
a = list(map(int, input().split()))
ave = sum(a) / N
if ave >= 0 and ave % 1 >= 0.5:
	ave = int(ave) + 1
elif ave < 0 and -ave % 1 >= 0.5:
	ave = int(ave) - 1
else:
	ave = int(ave)
ans = 0
for i in a:
	ans += (i - ave) ** 2
print(ans)


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))


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


N = int(input())
(*A,) = map(int, input().split())
c = 400 ** 2 * 100
for b in range(-100, 101):
	c = min(c, sum(((a - b) ** 2 for a in A)))
print(c)


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


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


N = int(input())
L = list(map(int, input().split()))[:N]
start = round(sum(L) / N)
f = lambda x: (x - start) ** 2
print(sum(list(map(f, L))))


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))))


n = int(input())
a = list(map(int, input().split()))
ans = 1000000000.0
for p in range(-100, 101):
	sub = 0
	for q in a:
		sub += pow(p - q, 2)
	ans = min(ans, sub)
print(ans)


n = int(input())
l = list(map(int, input().split()))
c = 1000000
for i in range(-100, 101):
	c1 = 0
	for j in l:
		c1 += (j - i) ** 2
	if c > c1:
		c = c1
print(c)


n = int(input())
X = list(map(int, input().split()))
y = round(sum(X) / n)
cost = 0
for x in X:
	cost += (x - y) ** 2
print(cost)


import math
from statistics import mean
n = int(input())
a = list(map(int, input().split()))
m = mean(a)
if m - math.floor(m) < 0.5:
	m = math.floor(m)
else:
	m = math.floor(m) + 1
diff = 0
for v in a:
	diff += (m - v) ** 2
print(diff)


n = int(input())
a = list(map(int, input().split()))
result = 10 ** 9
for num in range(-100, 101):
	cost = 0
	for i in range(n):
		cost += (a[i] - num) ** 2
	result = min(result, cost)
print(result)


N = int(input())
A = list(map(int, input().split()))
ave = round(sum(A) / N)
print(sum((abs(a - ave) ** 2 for a in A)))


N = int(input())
A = sorted(list(map(int, input().split())))
z = 10 ** 6
for i in range(A[0], A[-1] + 1):
	z = min(z, sum([(a - i) ** 2 for a in A]))
print(z)


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))


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)]))


n = int(input())
a = list(map(int, input().split()))
ave = round(sum(a) / n)
print(sum((abs(i - ave) ** 2 for i in a)))


n = int(input())
a = list(map(int, input().split()))
c = 10 ** 10
for i in range(min(a), max(a) + 1):
	t = 0
	for j in a:
		t += (i - j) ** 2
	if c > t:
		c = t
print(c)


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


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)


N = int(input())
a = list(map(int, input().split()))
my_round_int = lambda x: int((x * 2 + 1) // 2)
m = my_round_int(sum(a) / len(a))
cost = 0
for i in a:
	cost += (i - m) ** 2
print(cost)


n = int(input())
a = [int(x) for x in input().split()]
avg = round(sum(a) / n)
cost = 0
for e in a:
	cost += (e - avg) ** 2
print(cost)


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))


n = int(input())
l = list(map(int, input().split()))
a = sum(l) // n
b = a + 1
(c, d) = (0, 0)
for s in l:
	c += (s - a) ** 2
	d += (s - b) ** 2
print(d) if c > d else print(c)


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


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


inf = float('inf')
n = int(input())
arr = list(map(int, input().split()))
min_cost = inf
for i in range(-100, 101):
	cost = 0
	for j in arr:
		cost += (j - i) ** 2
	min_cost = min(min_cost, cost)
print(min_cost)


n = int(input())
a_list = [int(x) for x in input().split()]
a_sum = sum(a_list)
f = a_sum // n
c = (a_sum + n - 1) // n
b = f if abs(a_sum - f * n) < abs(a_sum - c * n) else c
ans = 0
for a in a_list:
	ans += (a - b) ** 2
print(ans)


n = int(input())
l = list(map(int, input().split()))
s = sum(l)
ans = 10 ** 7
for i in range(min(l), max(l) + 1):
	ans = min(ans, sum([(x - i) ** 2 for x in l]))
print(ans)


am = int(input())
n_l = list(map(int, input().split(' ')))
m = round(sum(n_l) / len(n_l))
S = 0
for a in range(am):
	S += (n_l[a] - m) ** 2
print(int(S))


N = int(input())
a = [int(i) for i in input().split()]
num = round(sum(a) / len(a))
cost = 0
for i in a:
	cost += (num - i) ** 2
print(cost)


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


n = int(input())
a = list(map(int, input().split()))
b = 0
for i in range(n):
	b += a[i]
c = int(b / n)
d = c + 1
e = 0
f = 0
for i in range(n):
	e += (a[i] - c) ** 2
	f += (a[i] - d) ** 2
print(min(e, f))


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


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


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


N = int(input())
a = list(map(int, input().split(' ')))
s = sum(a)
ave = s / N
ave = round(ave)
b = list(map(lambda x: (x - ave) ** 2, a))
print(sum(b))


input()
a = list(map(int, input().split()))
r = float('inf')
for i in range(min(a), max(a) + 1):
	n = 0
	for j in a:
		n += (j - i) ** 2
	r = min(n, r)
print(r)


n = int(input())
l = list(input().split())
sum = 0
min_sum = 10 ** 10
num = 0
for i in range(-100, 101):
	for j in range(len(l)):
		sum += (int(l[j]) - i) ** 2
	if min_sum > sum:
		min_sum = sum
		num = i
	sum = 0
print(min_sum)


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


N = int(input())
A = list(map(int, input().split()))
cost = []
for i in range(-100, 101):
	cost.append(sum([(a - i) ** 2 for a in A]))
print(min(cost))


maxa = 10 ** 11
N = int(input())
L = list(map(int, input().split()))
for i in range(-100, 101):
	R = [(i - y) ** 2 for y in L]
	a = sum(R)
	maxa = min(maxa, a)
print(maxa)


n = int(input())
a = list(map(int, input().split()))
d = round(sum(a) / len(a))
cost = 0
for i in a:
	cost += (i - d) ** 2
print(cost)


n = int(input())
a = list(map(int, input().split()))
r = (2 * sum(a) + n) // (2 * n)
s = 0
for x in a:
	s += (x - r) * (x - r)
print(s)


def cost(x):
	cost = (x - ave) ** 2
	return cost
n = input()
a = list(map(int, input().split()))
ave = round(sum(a) / int(n))
print(sum(list(map(cost, a))))


N = int(input())
a = list(map(int, input().split()))
s = sum(a)
x = int(s / len(a))
if x + 1 - s / len(a) < s / len(a) - x:
	x += 1
cost = 0
for y in a:
	cost += pow(y - x, 2)
print(cost)


N = int(input())
As = list(map(int, input().split()))
anss = []
for i in range(-101, 101):
	anss.append(sum([abs(i - a) ** 2 for a in As]))
print(min(anss))


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


n = int(input())
l = list(map(int, input().split()))
ave = round(sum(l) / n)
print(sum(list(map(lambda x: (x - ave) ** 2, l))))


n = int(input())
A = [int(i) for i in input().split()]
m = round(sum(A) / n)
ans = 0
for a in A:
	ans += abs(a - m) ** 2
print(ans)


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)


n = int(input())
a = list(map(int, input().split()))
ans = 1000100
ch = 0
for ch in range(min(a), max(a) + 1):
	tmp = 0
	for i in range(n):
		tmp += (a[i] - ch) ** 2
	if tmp <= ans:
		ans = tmp
print(ans)


N = int(input())
A = list(map(int, input().split()))
min_cost = 10 ** 9 + 7
for i in range(-100, 101):
	cost = 0
	for j in range(N):
		cost += (A[j] - i) ** 2
	min_cost = min(cost, min_cost)
print(min_cost)


from typing import List

def answer(n: int, a: List[int]) -> int:
	cost = 0
	num = round(sum(a) / n)
	for i in a:
		cost += (i - num) ** 2
	return cost

def main():
	n = int(input())
	a = list(map(int, input().split()))
	print(answer(n, a))

def __starting_point():
	main()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
avg_a = round(sum(a) / n)
result = 0
for num in a:
	result += (num - avg_a) ** 2
print(result)


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


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))


(n, a) = open(0)
(*a,) = map(int, a.split())
print(min((sum(((i - j - 100) ** 2 for j in a)) for i in range(201))))


N = int(input())
n = list(map(int, input().split()))
m = int(sum(n) / N)

def fun(x):
	ans = 0
	for i in n:
		ans += (i - x) ** 2
	return ans
p = fun(m)
q = fun(m + 1)
if p < q:
	print(p)
else:
	print(q)


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)


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


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


N = int(input())
A = [int(i) for i in input().split()]
cons = round(sum(A) / N)
ans = 0
for i in range(N):
	ans += (A[i] - cons) ** 2
print(ans)


n = int(input())
a = list(map(int, input().split()))
from statistics import mean
m = round(mean(a))
cost = 0
for i in a:
	cost += (i - m) ** 2
print(cost)


import sys

def solve(N: int, a: 'List[int]'):
	ans = float('inf')
	for m in range(-100, 101):
		ans = min(ans, sum(((aa - m) ** 2 for aa in a)))
	return ans

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)]
	print(solve(N, a))

def test():
	import doctest
	doctest.testmod()

def __starting_point():
	main()
__starting_point()


N = int(input())
a = [int(i) for i in input().split()]
avg = int((sum(a) / N * 2 + 1) // 2)
print(sum([(i - avg) ** 2 for i in a]))


import math
from datetime import date

def f(x, a):
	ans = 0
	for y in a:
		ans += (x - y) ** 2
	return ans

def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	s = 0
	for x in a:
		s += x
	s = s // n
	ans = 10 ** 17
	for x in range(s - 2, s + 3):
		ans = min(ans, f(x, a))
	print(ans)
main()


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

def f(x):
	return sum([(a_i - x) ** 2 for a_i in A])
print(min([f(x) for x in range(-100, 101)]))


N = int(input())
A = list(map(int, input().split()))
print(min([sum([(a - x) ** 2 for a in A]) for x in range(-100, 100 + 1)]))


n = int(input())
a = [int(i) for i in input().split()]
s = sum(a)
x = round(s / n)
y = sum([ai ** 2 for ai in a])
print(y - 2 * x * s + n * x ** 2)


N = int(input())
n = list(map(int, input().split()))
m = int(sum(n) / N)

def fun(x):
	ans = 0
	for i in n:
		ans += (i - x) ** 2
	return ans
s = min(fun(m), fun(m + 1))
print(s)


N = int(input())
a = list(map(int, input().split()))
Q = 0
for i in a:
	Q += (i - round(sum(a) / len(a))) ** 2
print(Q)


def main():
	n = int(input())
	a_lst = list(map(int, input().split()))
	minimum = min(a_lst)
	maximum = max(a_lst)
	cost = 10 ** 9
	for i in range(maximum - minimum + 1):
		tmp_cost = 0
		std = minimum + i
		for j in range(n):
			a = a_lst[j]
			tmp_cost += (a - std) ** 2
		cost = min(tmp_cost, cost)
	print(cost)

def __starting_point():
	main()
__starting_point()


class Combination:

	def __init__(self, n, mod):
		self.n = n
		self.mod = mod
		self.fac = [1 for i in range(self.n + 1)]
		self.finv = [1 for i in range(self.n + 1)]
		for i in range(2, self.n + 1):
			self.fac[i] = self.fac[i - 1] * i % self.mod
			self.finv[i] = self.finv[i - 1] * pow(i, -1, self.mod) % self.mod

	def comb(self, n, m):
		return self.fac[n] * (self.finv[n - m] * self.finv[m] % self.mod) % self.mod

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

def __starting_point():
	n = int(input())
	a = iparse()
	ans = 10000000000
	for i in range(-100, 101):
		tmp = 0
		for e in a:
			tmp += (e - i) ** 2
		ans = min(tmp, ans)
	print(ans)
__starting_point()


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))


N = int(input())
l = list(map(int, input().split()))
l_ans = [[] for _ in range(201)]
for i in range(-100, 101):
	sum = 0
	for j in range(N):
		sum = sum + (i - l[j]) ** 2
	l_ans[i + 100] = sum
print(min(l_ans))


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))


import math
n = int(input())
a = list(map(int, input().split()))
avg = sum(a) / n
x = math.floor(avg)
y = math.ceil(avg)
sumx = 0
sumy = 0
for i in a:
	sumx += (i - x) ** 2
	sumy += (i - y) ** 2
print(min([sumx, sumy]))


n = int(input())
array = [int(x) for x in input().split()]
tmp = round(sum(array) / n)
print(sum([(x - tmp) ** 2 for x in array]))


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


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


N = int(input())
int_list = [int(x) for x in input().split()]

def calc_cost(int_list, y):
	cost = 0
	for x in int_list:
		cost += (x - y) ** 2
	return cost
cost_list = [calc_cost(int_list, y) for y in range(min(int_list), max(int_list) + 1)]
print(min(cost_list))


import sys
import math
N = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 10 ** 9
for i in range(a[0], a[-1] + 1):
	cost = 0
	for j in a:
		cost += (i - j) ** 2
	ans = min(cost, ans)
print(ans)


import math
N = int(input())
A = [int(a) for a in input().split(' ')]
ave = sum(A) / N
can1 = math.floor(ave)
can2 = math.ceil(ave)
cost1 = sum([(a - can1) ** 2 for a in A])
cost2 = sum([(a - can2) ** 2 for a in A])
print(min([cost1, cost2]))


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)


N = int(input())
A = list(map(int, input().split()))
ans = 10 ** 10
for i in range(-100, 101):
	ans = min(sum(list(map(lambda x: (x - i) ** 2, A))), ans)
print(ans)


n = int(input())
A = tuple(map(int, input().split()))
s = sum(A)
ave = s / n
m = s // n
if m + 1 - ave < ave - m:
	m += 1
print(sum(((a - m) ** 2 for a in A)))


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


n = float(input())
a = list(map(int, input().split()))
ave = round(sum(a) / n)
print(sum(list(map(lambda x: (x - ave) ** 2, a))))


import sys
import math

def main():
	input()
	a = list(map(int, input().split()))
	y = round(sum(a) / len(a))
	ans = 0
	for i in a:
		ans += pow(i - y, 2)
	print(ans)

def __starting_point():
	main()
__starting_point()


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))


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)]))


N = int(input())
A = [int(x) for x in input().split()]
maxA = max(A)
minA = min(A)
ans = 10 ** 9
for i in range(minA, maxA + 1):
	kouho = 0
	for j in range(N):
		kouho += (i - A[j]) ** 2
	ans = min(ans, kouho)
print(ans)


N = int(input())
A = [int(T) for T in input().split()]
Min = 10 ** 9
for TN in range(min(A), max(A) + 1):
	Min = min(Min, sum(((TN - TA) ** 2 for TA in A)))
print(Min)


N = int(input())
a = list(map(int, input().split()))
avg = round(sum(a) / N)
ans = 0
for i in a:
	ans = ans + (i - avg) * (i - avg)
print(ans)


N = int(input())
A = list(map(int, input().split()))
ave = round(sum(A) / N)
var = 0
for a in A:
	var += (a - ave) ** 2
print(var)


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


n = int(input())
a = [int(i) for i in input().split()]
mu = round(sum(a) / n)
print(sum(list(map(lambda x: (x - mu) ** 2, a))))


n = int(input())
a_list = [int(i) for i in input().split()]
center = round(sum(a_list) / n)
ans = 0
for a in a_list:
	ans += (a - center) ** 2
print(ans)


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


n = int(input())
L = [int(i) for i in input().split()]
tg = round(sum(L) / n)
cost = 0
for i in range(n):
	cost += pow(L[i] - tg, 2)
print(cost)


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))


N = int(input())
num_list = list(map(int, input().split()))
cost_list = []
max_num = max(num_list)
min_num = min(num_list)
for i in range(min_num, max_num):
	cost = 0
	for j in num_list:
		cost += (i - j) ** 2
	cost_list.append(cost)
if len(cost_list) == 0:
	cost_list.append(0)
print(min(cost_list))


import statistics
import math
n = int(input())
a = list(map(int, input().split()))
(ans1, ans2) = (0, 0)
a_avr1 = math.ceil(statistics.mean(a))
a_avr2 = math.floor(statistics.mean(a))
for i in range(n):
	ans1 += (a[i] - a_avr1) ** 2
	ans2 += (a[i] - a_avr2) ** 2
print(min(ans1, ans2))


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


N = int(input())
a = list(map(int, input().split()))
sum = 0
cost = 0
for i in a:
	sum += i
ave = round(sum / len(a))
for i in a:
	cost += (ave - i) ** 2
print(cost)


n = int(input())
a_i = list(map(int, input().split()))
ave = round(sum(a_i) / len(a_i))
ans = 0
for x in a_i:
	ans += (x - ave) ** 2
print(ans)


N = int(input())
A = [int(x) for x in input().split()]
average = round(sum(A) / N)
ans = 0
for x in A:
	ans += (average - x) ** 2
print(ans)


n = int(input())
a = list(map(int, input().split()))
avg = round(sum(a) / n)
print(sum(map(lambda x: (x - avg) * (x - avg), a)))


n = int(input())
a = [int(i) for i in input().split()]
cost = []
for i in range(-100, 101):
	tmp = 0
	for j in a:
		tmp += (j - i) ** 2
	cost.append(tmp)
print(min(cost))


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 10 ** 10
for x in range(a[0], a[-1] + 1):
	tmp = 0
	for i in range(n):
		tmp += (a[i] - x) ** 2
	ans = min(ans, tmp)
print(ans)


N = int(input())
a = list(map(int, input().split()))
A = round(sum(a) / N)
if float(A) - int(A) == 0.5:
	A += 1
x = 0
for i in a:
	x += (A - i) ** 2
print(x)


(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)


n = int(input())
A = list(map(int, input().split()))
x = round(sum(A) / n)
print(sum(((a - x) ** 2 for a in A)))


n = int(input())
a = list(map(int, input().split()))
ans = 100000000
for i in range(-100, 101):
	now = 0
	for k in a:
		now += (i - k) * (i - k)
	ans = min(ans, now)
print(ans)


n = int(input())
l = list(map(int, input().split()))
ans = float('inf')
for v in range(min(l), max(l) + 1):
	c = sum([(a - v) ** 2 for a in l])
	ans = min(ans, c)
print(ans)


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)


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


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)


N = int(input())
A = list(map(int, input().split()))
ans = 0
if sum(A) % N == 0:
	x = sum(A) // N
	for i in range(N):
		ans += (x - A[i]) ** 2
	print(ans)
else:
	x = sum(A) // N
	b = sum(A) // N + 1
	if sum(A) / N - x > b - sum(A) / N:
		x = b
	for i in range(N):
		ans += (x - A[i]) ** 2
	print(ans)


N = int(input())
List = list(map(int, input().split()))
sumS = 0
for i in range(N):
	sumS += List[i]
trial = sumS // N
mid = 0
res = 10000000
for i in range(N):
	trial += i
	mid = 0
	for j in range(N):
		mid += (trial - List[j]) ** 2
	res = min(res, mid)
print(res)


def keisan(N, A):
	KAI = 0
	A.sort
	min = -100
	max = 101
	i = min
	while i <= max:
		kari = 0
		j = 0
		while j < N:
			kari += (A[j] - i) ** 2
			j += 1
		if kari <= KAI or i == min:
			KAI = kari
		i += 1
	return KAI
N = int(input())
A = input().split()
int_list = list(map(int, A))
print(keisan(N, int_list))


n = int(input())
A = list(map(int, input().split()))
S = [sum(((i - a) ** 2 for a in A)) for i in range(min(A), max(A) + 1)]
print(min(S))


n = input()
a = [int(i) for i in input().split()]
print(min([sum(((x - y) ** 2 for x in a)) for y in range(min(a), max(a) + 1)]))


import numpy as np
input()
a = np.array(sorted(map(int, input().split())))
print(min((sum((a - i) ** 2) for i in range(min(a), max(a) + 1))))


N = input()
list1 = list(map(int, input().split()))
list2 = []
for i in range(min(list1), max(list1) + 1):
	a = 0
	for j in range(len(list1)):
		a += (list1[j] - i) ** 2
	list2.append(a)
print(min(list2))


n = input()
a = list(map(int, input().split()))
ans = list()
for i in range(min(a), max(a) + 1):
	cost = 0
	for num in a:
		cost += (num - i) ** 2
	ans.append(cost)
print(min(ans))


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)


N = int(input())
A = [int(s) for s in input().split()]
avg = int(round(sum(A) / N))
B = [(avg - a) ** 2 for a in A]
print(sum(B))


num = int(input())
str_line = input().split(' ')
num_line = [int(n) for n in str_line]
ave = 0
for i in range(num):
	ave += num_line[i]
if ave % num == 0:
	ave //= num
elif ave % num <= num / 2:
	ave //= num
else:
	ave = -(-ave // num)
wa = 0
for i in range(num):
	temp = num_line[i] - ave
	wa += temp * temp
print(wa)


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)


(N, *a) = map(int, open(0).read().split())
tgt = round(sum(a) / N)
print(sum(((v - tgt) ** 2 for v in a)))


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


N = int(input())
a = list(map(int, input().split()))
avg = round(sum(a) / N)
sums = []
for i in range(min(a), avg + 1):
	s = 0
	for j in range(N):
		s += (i - a[j]) ** 2
	sums.append(s)
print(min(sums))


n = int(input())
ls = list(map(int, input().split()))
m = round(sum(ls) / n)
print(sum([(x - m) ** 2 for x in ls]))


n = int(input())
A = [int(_) for _ in input().split()]
m = round(sum(A) / n)
ans = 0
for a in A:
	if a == m:
		continue
	ans += (a - m) ** 2
print(ans)


n = int(input())
arr = list(map(int, input().split()))
mini = min(arr)
maxi = max(arr)
cost = 10000000000
for i in range(-100, 101 + 1):
	add = 0
	for j in range(n):
		add = add + (arr[j] - i) ** 2
	cost = min(cost, add)
print(cost)


n = int(input())
a = [int(i) for i in input().split()]
ans = 10000000000000000
for criterion in range(-100, 101):
	result = 0
	for i in a:
		result += (i - criterion) ** 2
	ans = min(ans, result)
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = []
for i in range(a[0], a[-1] + 1):
	cnt = 0
	for j in range(n):
		cnt += (a[j] - i) ** 2
	ans.append(cnt)
print(min(ans))


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)


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)


n = int(input())
a = list(map(int, input().split()))
minimum = 10000000
for i in range(-100, 101):
	cost = 0
	for j in range(n):
		cost += (i - a[j]) ** 2
		if j == n - 1:
			if cost < minimum:
				minimum = cost
print(minimum)


def main():
	(N, *an) = map(int, open(0).read().split())
	print(sum(((ai - round(sum(an) / N)) ** 2 for ai in an)))
	return
main()


input()
l = list(map(int, input().split(' ')))
print(min([sum([(j - i) ** 2 for j in l]) for i in range(min(l), max(l) + 1)]))


N = int(input())
a = list(map(int, input().split()))
mid = round(sum(a) / N, 0)
sum = 0
for i in a:
	sum += (i - mid) ** 2
print(int(sum))


N = int(input())
A = list(map(int, input().split()))
costs = []
for i in range(101):
	cost = 0
	for j in range(N):
		cost += (A[j] - i) ** 2
	costs.append(cost)
	cost = 0
	for j in range(N):
		cost += (A[j] + i) ** 2
	costs.append(cost)
print(min(costs))


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

def __starting_point():
	main()
__starting_point()


round = lambda x: int((x * 2 + 1) // 2)
n = int(input())
A = list(map(int, input().split()))
target = round(sum(A) / n)
print(sum([(a - target) ** 2 for a in A]))


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


N = int(input())
list = [int(a) for a in input().split()]
A = sum(list) // N
ans = 0
for k in range(N):
	ans = ans + (list[k] - A) ** 2
for i in range(-100, 100):
	sum_new = 0
	for j in range(N):
		sum_new = sum_new + (list[j] - i) ** 2
	if ans > sum_new:
		ans = sum_new
print(ans)


def main():
	import math
	_ = int(input())
	a = list(map(int, input().split()))
	t = float('inf')
	for i in range(min(a), max(a) + 1):
		cnt = 0
		for j in a:
			cnt += (j - i) ** 2
		else:
			if cnt < t:
				t = cnt
	else:
		print(t)
main()


n = int(input())
a = [int(x) for x in input().split()]
p = (sum(a) / n * 2 + 1) // 2
print(int(sum(map(lambda x: (x - p) ** 2, a))))


n = int(input())
a = list(map(int, input().split()))
b = sum(a) / n
c = (b * 2 + 1) // 2
s = 0
for i in a:
	s += (i - c) ** 2
s = int(s)
print(s)


n = int(input())
array = [int(x) for x in input().split()]
avg = round(sum(array) / n)
ans = 0
for a in array:
	ans += abs(a - avg) ** 2
print(ans)


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)


N = int(input())
aN = list(map(int, input().split()))
S = 0
A = 0
for i in aN:
	S += i
A = S / N
if A - int(A) < 0.5:
	A = int(A)
else:
	A = int(A) + 1
R = 0
for i in aN:
	R += (i - A) ** 2
print(R)


(N, *a) = open(0).read().split()
N = int(N)
list1 = list(map(int, a))
a = []
for i in range(-100, 101):
	int1 = 0
	for n in range(N):
		x = list1[n] - i
		y = x ** 2
		int1 += y
		if n == N - 1:
			a.append(int1)
print(min(a))


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


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


def solve(a):
	mean = round(sum(a) / len(a))
	return sum(((aa - mean) ** 2 for aa in a))
input()
print(solve(list(map(int, input().split(' ')))))


N = int(input())
(*A,) = map(int, input().split())
mx = max(A)
mn = min(A)
ans = float('inf')
for i in range(mn, mx + 1):
	ans = min(ans, sum([(k - i) ** 2 for k in A]))
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
res = 10 ** 9
for i in range(-100, 101):
	cc = 0
	for j in range(n):
		cc += (i - a[j]) ** 2
	res = min(res, cc)
print(res)


n = int(input())
a = [int(x) for x in input().split()]
A = min(a)
B = max(a)
temp = 10000000000000000000000
for i in range(A, B + 1):
	ans = 0
	for j in a:
		ans += abs(j - i) ** 2
	temp = min(temp, ans)
print(temp)


N = int(input())
ls = list(map(int, input().split()))
ave = int((sum(ls) / N * 2 + 1) // 2)
cost = 0
for i in ls:
	cost += (i - ave) ** 2
print(cost)


n = int(input())
given = [int(x) for x in input().split()]
avgs = round(sum(given) / n)
cost = sum([(x - avgs) ** 2 for x in given])
print(cost)


n = int(input())
l = [int(x) for x in input().split()]
avg = round(sum(l) / n)
l = [(x - avg) ** 2 for x in l]
print(sum(l))


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

def cost(x, y):
	return (x - y) ** 2
avg = round(sum(nums) / len(nums))
res = 0
for n in nums:
	res += cost(n, avg)
print(res)


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


N = int(input())
A = list(map(int, input().split()))
m = round(sum(A) / N)
t = sum(list(map(lambda x: (x - m) ** 2, A)))
print(t)


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))


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