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 6s 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 2s 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 1s.

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 4s 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.



Sample input:
2
4 8


Sample output:
8

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans1 = (max(A)+min(A))//2
if max(A)-min(A) % 2 == 0:
  prin = 0
  for i in range(n):
    prin += (ans1 - A[i])**2
else:
  ans2 = (max(A)+min(A))//2+1
  prin1 = 0
  prin2 = 0
  for i in range(n):
    prin1 += (ans1 - A[i])**2
    prin2 += (ans2 - A[i])**2
  prin = min(prin1,prin2)
print(prin)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans1 = (max(A)+min(A))//2
if max(A)-min(A) % 2 == 0:
  prin = 0
  for i in range(n):
    prin += (ans1 - A[i])**2
else:
  ans2 = (max(A)-min(A))//2+1
  prin1 = 0
  prin2 = 0
  for i in range(n):
    prin1 += (ans1 - A[i])**2
    prin2 += (ans2 - A[i])**2
  prin = min(prin1,prin2)
print(prin)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))
avg_a = math.ceil(sum(a)/n)

result = 0
for num in a:
    result += (num-avg_a)**2

print(result)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    average = sum(a_lst) // n
    if sum(a_lst) % n != 0:
        average += 1

    minimum = 0
    for i in range(n):
        a = a_lst[i]
        minimum += (a - average) ** 2
    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    average = sum(a_lst) // n
    if sum(a_lst) & n != 0:
        average += 1

    minimum = 0
    for i in range(n):
        a = a_lst[i]
        minimum += (a - average) ** 2
    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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[i])**2
  res = max(res, mid)
print(res)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
import numpy as np


def main():
    n = int(input())
    As = list(map(int, input().split()))
    As_set = list(set(As))
    std = int(np.around(np.mean(As_set)))

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 1e9
for p in range(101):
  sub = 0
  for q in a:
    sub += pow(p - q, 2)
  ans = min(ans, sub)

print(ans)

Submission status: Wrong Answer

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

ans = 1e9
for p in a:
  sub = 0
  for q in a:
    sub += pow(p - q, 2)
  ans = min(ans, sub)

print(ans)

Submission status: Wrong Answer

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

x = int((sum(A) / n) + 0.5)
ans = 0
for a in A:
    ans += (a - x) ** 2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))

mini = min(arr)
maxi = max(arr)
cost = 10000

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)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))

mini = min(arr)
maxi = max(arr)
cost = 10000

for i in range(mini, maxi+1):
    add = 0
    for j in range(n):
        add = add + (arr[j] - i)**2
    cost = min(cost, add)
print(cost)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
ais = map(int, raw_input().split())
ais.sort()

def f(ais):
	if len(ais) % 2:
		return [ais[len(ais)/2]]
	
	v = ais[len(ais)/2 -1] + ais[len(ais)/2]
	return [v/2,v/2-1,v/2+1]
meds = f(ais)

def g(ais,m):
	s= 0
	for v in ais:
		s+=abs(v-m)**2
	return s
print min([g(ais,m) for m in meds])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import numpy as np

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

# med = np.median([min(a), max(a)])
med = (min(a)+max(a))/2
med1 = int(np.floor(med))
med2 = int(np.ceil(med))
ans1 = ans2 = 0 
for i in range(n):
    ans1 += (a[i]-med1)**2
    ans2 += (a[i]-med2)**2

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import numpy as np

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

med = np.median([min(a), max(a)])
med1 = int(np.floor(med))
med2 = int(np.ceil(med))
ans1 = ans2 = 0 
for i in range(n):
    ans1 += (a[i]-med1)**2
    ans2 += (a[i]-med2)**2

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
hoge = [x for x in range(arr[0], arr[-1]+1)]
if len(arr) == 1:
    print(0)
    exit()

a = hoge[len(hoge)//2]
b = hoge[len(hoge)//2-1]

min_cost = 1 << 60
cost = 0
for i in arr:
    cost += (i-a)**2
min_cost = min(min_cost, cost)

for i in arr:
    cost += (i-b)**2
min_cost = min(min_cost, cost)

print(min_cost)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
hoge = [x for x in range(arr[0], arr[-1]+1)]
if len(arr) == 1:
    print(0)
    exit()

a = hoge[len(hoge)//2]

min_cost = 1 << 60
cost = 0
for i in arr:
    cost += (i-a)**2
min_cost = min(min_cost, cost)

print(min_cost)

Submission status: Wrong Answer

Solution code:
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]

ave = -(-ave//num)

wa = 0
for i in range(num):
    temp = num_line[i] - ave
    wa += temp*temp
    
print(wa)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = list(map(int, input().split()))
avg = -(-sum(lst) // N)

result = 0
for i in lst:
    result += (i - avg)**2

print(result)

Submission status: Wrong Answer

Solution code:
def keisan(N,A):
     
     KAI = 0
     A.sort

     min = A[0]
     max = A[N-1]+1
     
     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))

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [abs(int(i)) for i in input().split()]
r = 100 ** 2

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

for i in range(max(lst)):
    temp = 0
    for j in lst:
        temp += (i - j) ** 2
        
    if temp < r:
        r = temp
        
print(r)

Submission status: Wrong Answer

Solution code:
def keisan(N,A):
     
     KAI = 0
     A.sort

     min = A[0]
     max = A[N-1]
     
     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))

Submission status: Wrong Answer

Solution code:
from math import *
n=int(input())
l=list(map(int,input().split()))
s=ceil(sum(l)/n)
c=0
for i in range(n):
    c+=(s-l[i])**2
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
 
m_cost = 10 ** 5
for i in range(min(a), max(a)+1):
    cost = 0
    for j in range(n):
        cost += (a[j] - i) ** 2
    m_cost = cost if cost < m_cost else m_cost
print(m_cost)

Submission status: Wrong Answer

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

m_cost = 10 ** 5
for i in range(-1000, 1000):
    cost = 0
    for j in range(n):
        cost += (a[j] - i) ** 2
    m_cost = cost if cost < m_cost else m_cost
print(m_cost)

Submission status: Wrong Answer

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

m_cost = 10 ** 5
for i in range(-100, 101):
    cost = 0
    for j in range(n):
        cost += (a[j] - i) ** 2
    m_cost = cost if cost < m_cost else m_cost
print(m_cost)

Submission status: Wrong Answer

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

m_cost = 10 ** 5
for i in range(101):
    cost = 0
    for j in range(n):
        cost += (a[j] - i) ** 2
    m_cost = cost if cost < m_cost else m_cost
print(m_cost)

Submission status: Wrong Answer

Solution code:
# C - いっしょ
def main():
    import math
    n = int(input())
    a = list(map(int, input().split()))
    p = math.ceil(sum(a)/n)
    cnt = 0

    for i in range(n):
        cnt += (a[i]-p)**2
    else:
        print(cnt)
    
if __name__ ==  "__main__":
    main()

Submission status: Wrong Answer

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

print(minimum)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
A=[int(i) for i in input().split()]
c= sum(A)
num= c/N
price=0
for I in range(len(A)):
    price+= (A[I]-num)**2
price=round(price)
print(price)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0
ave1 = -(-(min(a)+max(a))//2)
ave2 = (min(a)+max(a))//2
ave3 = sum(a)//2
ave4 = -(-(sum(a))//N)
    

for i in range(N):
    ans1 += abs((a[i]-ave1)**2)
    
for i in range(N):
    ans2 += abs((a[i]-ave2)**2)
for i in range(N):    
    ans3 += abs((a[i]-ave3)**2)
for i in range(N):    
    ans4 += abs((a[i]-ave4)**2)
    
ans = [ans1, ans2, ans3, ans4]

print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans1 = 0
ans2 = 0
ave1 = -(-(min(a)+max(a))//2)
ave2 = (min(a)+max(a))//2
    

for i in range(N):
    ans1 += abs((a[i]-ave1)**2)
    
for i in range(N):
    ans2 += abs((a[i]-ave2)**2)
    
    
if(ans1<=ans2):
    print(ans1)
else:
    print(ans2)

Submission status: Wrong Answer

Solution code:
import statistics
import math
n = int(input())
a = list(map(int,input().split()))
ans = 0
a_avr = math.ceil((statistics.mean(a)))
for i in range(n):
  ans += (a[i] - a_avr)**2
print(ans)

Submission status: Wrong Answer

Solution code:

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 = 0
    sum_new = 0
    for j in range(N):
        sum_new = sum_new + (list[j] - i) ** 2
    if(sum > sum_new):
        ans = sum_new

print(ans)

Submission status: Wrong Answer

Solution code:

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

A = sum(list)//N

for i in range(N):
    sum = (list[i] - A) ** 2
    sum_new = (list[i] - i) ** 2
    if(sum > sum_new):
        sum = sum_new
print(sum)

Submission status: Wrong Answer

Solution code:

N = int(input())
list = [int(a) for a in input().split()]
print(list)
print(sum(list))

A = sum(list)//N

for i in range(N):
    sum = (list[i] - A) ** 2
    sum_new = (list[i] - i) ** 2
    if(sum > sum_new):
        sum = sum_new
print(sum)

Submission status: Wrong Answer

Solution code:
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(l_ans)
print(min(l_ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
l_ans = [[] for _ in range(100)]

for i in range(100):
    sum = 0

    for j in range(N):
        sum = sum + (i+1-l[j])**2

    l_ans[i] = sum

print(min(l_ans))

Submission status: Wrong Answer

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

m = sum(a)/n
if int(m)+1 - m < m - int(m): m = int(m)+1
else: int(m)

ans = 0
for i in a: ans += abs(i - m)**2
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
a=min(l)
b=max(l)
d=a+b
if d%2:
  d=(d+1)//2
else:
  d=d//2
c=0
for i in l:
  if i!=d:
    c=c+(d-i)**2
print(c)

Submission status: Wrong Answer

Solution code:
def main():
  n=int(input())
  a=input().split()
  b=[]
  for i in range(int(min(a)),int(max(a))):
      b1=[]
      for m in range(n):
          c=(int(a[m])-i)**2
          b1.append(c)
      b2=sum(b1)
      b.append(b2)
  if b==[]:
      print('0')
  else:
      print(min(b))
  
  
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
def main():
  n=int(input())
  a=input().split()
  b=[]
  for i in range(int(min(a)),int(max(a))):
      b1=[]
      for m in range(n):
          c=(int(a[m])-i)**2
          b1.append(c)
      b2=sum(b1)
      b.append(b2)
  if b==[]:
      print(0)
  else:
      print(min(b))
  
  
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
x=int()
y=int()
sum=x+y
transform=(sum-x)*(sum-y)
print(transform)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
lis = list(map(int, input().split()))

avg = math.ceil(sum(lis)/len(lis))

ans = 0
for i in lis:
    ans += (i-avg)**2

print(ans)

Submission status: Wrong Answer

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

ave = sum(A)//N
cost = 0

for i in A:
    cost += math.pow((i - ave), 2)

print(int(cost))

Submission status: Wrong Answer

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


y = 1000000


for i in range(-100, 100):
    x = 0
    for m in a:
        x += (i-m)**2
    if y > x:
        y = x

print(y)

Submission status: Wrong Answer

Solution code:
N = int(input())
an = list(map(int, input().split()))

cost = 10000*3
ans = 10000*3
for i in range(-100,100+1):
    cost = sum([(j - i)**2 for j in an])
    ans = min(ans, cost)

print(ans)

Submission status: Wrong Answer

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

av = math.ceil(sum(a) / n)
ans = 0
for i in range(n):
    ans += (a[i]-av)**2
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def get_ints():
    return map(int, sys.stdin.readline().strip().split())


def _main():
    input()
    an = list(get_ints())

    t = 0
    old = 100000
    while 1:
        ans = sq(t, an)
        g = sq(t+1, an) - ans
        t -= g / abs(g)
        if old > ans:
            old = ans
        else:
            break
    print(int(old))


def sq(t, an):
    ans = 0
    for ai in an:
        ans += pow(ai - t, 2)
    return ans


if __name__ == "__main__":
    _main()

Submission status: Wrong Answer

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

a.sort()
min = a[0]
max = a[int(n) - 1]
mid = max - min
sum = 0
work = 0

if mid == 0:
  print(0)
elif mid % 2 == 0:
  mid /= 2
  num = min + int(mid)
  for i in range(int(n)):
    sum += (a[i] - num) ** 2
  print(sum)
else:
  mid /= 2
  num = min + int(mid)
  num2 = max - int(mid)
  for i in range(int(n)):
    sum += (a[i] - num) ** 2
    work += (a[i] - num2) ** 2
  if sum < work:
    print(sum)
  else:
    print(work)

Submission status: Wrong Answer

Solution code:
n=int(input())
integers=list(map(int,input().split()))

sql=[x*2 for x in integers]
s=sum(integers)
t=sum(sql)
m=min(s%n, n-s%n)

print((m**2-s**2)//n+t)

Submission status: Wrong Answer

Solution code:
N = int( input() )
s = input()
numbers = s.split()
 
def getCost(target):
  cost = 0
  for n in numbers:
    number = int(n)
    cost += (number - target)**2
  return cost
 
minCost = 0
for i in range(-100, 101):
  cost2 = getCost(i)
  if( cost2 < minCost ):
    minCost = cost2
print(minCost)

Submission status: Wrong Answer

Solution code:
N = int( input() )
s = input()
numbers = s.split()

def getCost(target):
  cost = 0
  for n in numbers:
    number = int(n)
    cost += (number - target)**2
  return cost

minCost = 0
for i in range(-100, 101):
  cost = getCost(i)
  if( cost < minCost ):
    minCost = cost
print(minCost)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=(max(a)+min(a))//2
c=b+1
ans,bns=0,0
for i in range(N):
  ans+=(abs(a[i]-b)**2)
  bns+=(abs(a[i]-c)**2)
print(min(ans,bns))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#ABC043C
n=int(input())
a = list(map(int, input().split()))
h=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))

Submission status: Wrong Answer

Solution code:
#ABC043C
import math
n=int(input())
a = list(map(int, input().split()))
h=math.ceil(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))

Submission status: Wrong Answer

Solution code:
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()
    A.sort()
    if len(A)%2 == 1:
        median = A[N//2]
    else:
        median = (A[N//2]+A[N//2-1])//2
    return sum(abs(a-median)**2 for a in A)


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

Submission status: Wrong Answer

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

tmp = max(a)+min(a)
if tmp%2==0:
    tmp = tmp//2
else:
    tmp = tmp//2+1
print(sum(map(lambda x:(x-tmp)**2,a)))

Submission status: Wrong Answer

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

ans = 1000000000

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

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 11 17:09:47 2020

@author: sd18016
"""

import math
N = int(input())
a = [int(i) for i in input().split()]

if (max(a) + min(a)) % 2 == 0:
    mean = int((max(a) + min(a))/2)
    ans = 0
    for i in a:
        ans += (i - mean)**2
    print(ans)
else:
    mean_1 = math.floor((max(a) + min(a))/2)
    mean_2 = math.ceil((max(a) + min(a))/2)
    ans_1 = 0
    ans_2 = 0
    for i in a:
        ans_1 += (i - mean_1)**2
    for i in a:
        ans_2 += (i - mean_2)**2
    print(min(ans_1,ans_2))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 11 17:09:47 2020

@author: sd18016
"""

import math
N = int(input())
a = [int(i) for i in input().split()]

if (max(a) + min(a)) % 2 == 0:
    mean = int((max(a) + min(a))/2)
    ans = 0
    for i in a:
        ans += (i - mean)**2
    print(ans)
else:
    mean_1 = int((max(a) + min(a))/2)
    mean_2 = math.ceil((max(a) + min(a))/2)
    ans_1 = 0
    ans_2 = 0
    for i in a:
        ans_1 += (i - mean_1)**2
    for i in a:
        ans_2 += (i - mean_2)**2
    print(min(ans_1,ans_2))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 11 17:09:47 2020

@author: sd18016
"""

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

if (max(a) + min(a)) % 2 == 0:
    mean = int((max(a) + min(a))/2)
    ans = 0
    for i in a:
        ans += (i - mean)**2
    print(ans)
else:
    mean_1 = int((max(a) + min(a))/2)
    mean_2 = mean_1 + 1
    ans_1 = 0
    ans_2 = 0
    for i in a:
        ans_1 += (i - mean_1)**2
    for i in a:
        ans_2 += (i - mean_2)**2
    print(min(ans_1,ans_2))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
ans = []
if A.count(A[0]) == 1:
    print(0)
    exit(0)
for i in range(1,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))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
ans = []
for i in range(1,101):
    cost = 0
    for j in range(N):
        cost += (A[j] - i)**2
    ans.append(cost)
import heapq
heapq.heapify(ans)
print(heapq.heappop(ans))

Submission status: Wrong Answer

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

def minimize(list):
    min = 10*10
    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))

Submission status: Wrong Answer

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

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

print(minimize(a))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=100000
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)

Submission status: Wrong Answer

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

for i, a in enumerate(A):
  cost = 0
  for j, aj in enumerate(A):
    cost += (aj - a)**2
  ans = min(ans, cost)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=float("inf")
for i in range(-100,100):
    k=0
    for j in a:
        k+=(j-i)**2
    ans=min(ans,k)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().split()

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

start = _min
end = _max
step = 1

if _min > _max:
  start = _min
  end = _max -1
  step = -1
else:
  start = _min
  end = _max +1
  step = 1

for i in range(start,end,step):
  _result = 0
  for j in a:
    _result += (i - int(j))**2
  if _result <= result:
    result = _result
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().split()

_max = int(max(a))
_min = int(min(a))
result = 100 * N

start = _min
end = _max
step = 1

if _min > _max:
  start = _min
  end = _max -1
  step = -1
else:
  start = _min
  end = _max +1
  step = 1

for i in range(start,end,step):
  _result = 0
  for j in a:
    _result += (i - int(j))**2
  if _result < result:
    result = _result
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().split()

_max = int(max(a))
_min = int(min(a))
result = 100 * N

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

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

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

#####Shorten#####
def DD(arg): return defaultdict(arg)


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

######Combination######
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

######Factorization######
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

#####MakeDivisors######
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

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

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

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

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

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

#############
# Main Code #
#############
N = I()
A = IL()

ans = []

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

P(min(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
an = list(map(int, input().split()))
ans = 10*9
for i in range(-100, 101):
    check = 0
    for a in an:
        check += (a-i)**2
    if ans >= check:
        ans = check
print(ans)