ZhenlongDai/ACPR huggingface dataset:
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import floor
n = int(input())
num = list(map(int, input().split()))
set_num = set(num)
mid = floor(sum(set_num) / len(set_num))
sol = 0
for i in num:
	sol += (i - mid) ** 2
print(int(sol))

Failing test case input:
3
-3 0 23

Expected output:
405


Actual output:
406


Fixed submission (verdict: Accepted):
from math import ceil
n = int(input())
num = list(map(int, input().split()))

sol = 10 ** 15
for i in range(-100, 101):
	tmp = 0
	for j in range(n):
		tmp += (num[j] - i) ** 2  
	sol = min(sol, tmp)
print(int(sol))

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import statistics

n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
    print(0)

min_ans = 100000000
for u in range(min(a), max(a)):
    ans = 0
    for i in a:
        ans += (u - i)**2
    if ans <= min_ans:
        min_ans = ans

print(int(min_ans))

Failing test case input:
4
-100 -100 -100 -100

Expected output:
0

Actual output:
0
100000000


Fixed submission (verdict: Accepted):
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)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def calc_cost(a, i):
    cost = 0
    for num in a:
        cost += (num - i) ** 2
    return cost


if __name__ == '__main__':
    N = int(input())
    a = [int(x) for x in input().split()]
    max_num = max(a)
    min_cost = 999999
    if max_num > 0:
        for i in range(max_num+1):
            cost = calc_cost(a, i)
            if cost < min_cost:
                min_cost = cost
    else:
        for i in range(max_num, 0):
            cost = calc_cost(a, i)
            if cost < min_cost:
                min_cost = cost
    print(min_cost)


Failing test case input:
3
-20 0 -3

Expected output:
233


Actual output:
999999


Fixed submission (verdict: Accepted):
def calc_cost(a, i):
    cost = 0
    for num in a:
        cost += (num - i) ** 2
    return cost


if __name__ == '__main__':
    N = int(input())
    a = [int(x) for x in input().split()]
    max_num = max(a)
    min_cost = calc_cost(a, a[0])
    for i in range(-100, 101):
        cost = calc_cost(a, i)
        if cost < min_cost:
            min_cost = cost
    print(min_cost)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = input()
n_list = list(map(int, input().split()))
max_sum = 0

for i in range(-100, 101):
  sum = 0
  for a in n_list:
    sum += (i - a) ^ 2
  max_sum = max(max_sum, sum)
  
print(max_sum)

Failing test case input:
3
0 -1 21

Expected output:
309


Actual output:
282


Fixed submission (verdict: Accepted):
n = input()
n_list = list(map(int, input().split()))
min_sum = float('inf')

for i in range(-100, 101):
  total = 0
  for a in n_list:
    total += pow((a - i), 2)
  min_sum = min(min_sum, total)

print(min_sum)
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
an = list(map(int, input().split()))
ans = 10*7
for i in range(min(an), max(an)+1):
    check = 0
    for a in an:
        check += (a-i)**2
    if ans >= check:
        ans = check
print(ans)


Failing test case input:
3
-3 0 23

Expected output:
405


Actual output:
70


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

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = list(map(int, input().split()))
cost = 100 ** 100
temp = 0
for x in range(1, 100+1):
    for y in range(N):
        temp += (x - abs(a[y])) ** 2
    cost = min(temp, cost)
    temp = 0
print(cost)


Failing test case input:
2
165 -4

Expected output:
14281


Actual output:
12961


Fixed submission (verdict: Accepted):
N = int(input())
a = list(map(int, input().split()))
cost = 100 ** 100
temp = 0
for x in range(-100, 101):
    for y in range(N):
        temp += (x - a[y]) ** 2
    cost = min(temp, cost)
    temp = 0
print(cost)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
    print(0)

min_ans = 100000000
for u in range(min(a), max(a)+1):
    ans = 0
    for i in a:
        ans += (u - i)**2
    if ans <= min_ans:
        min_ans = ans

print(int(min_ans))

Failing test case input:
4
-100 -100 -100 -100

Expected output:
0

Actual output:
0
0


Fixed submission (verdict: Accepted):
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)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
import sys
from functools import reduce
input = sys.stdin.readline

def fullsearch(a):
    for i in range(1, 101):
        yield reduce(lambda total, x: (x - i) ** 2 + total, a, 0)

def main():
    input()
    A = [int(c) for c in input().split()]

    print(min(fullsearch(A)))

main()

Failing test case input:
4
-100 -100 -100 -100

Expected output:
0

Actual output:
40804


Fixed submission (verdict: Accepted):
import math
import sys
from functools import reduce
input = sys.stdin.readline

def fullsearch(a):
    for i in range(-100, 101):
        yield reduce(lambda total, x: (x - i) ** 2 + total, a, 0)

def main():
    input()
    A = [int(c) for c in input().split()]

    print(min(fullsearch(A)))

main()
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n= int(input()) 
x = list(map(int, input().split()))
y = sum(x)*1.0/n
z =math.ceil(y)

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


Failing test case input:
3
-11 -2 -1

Expected output:
61


Actual output:
62


Fixed submission (verdict: Accepted):
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]))

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):





if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    z = (sum(a) + 1) 
    cost = 0

    if n == 1:
        print(0)
        exit()

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

    print(cost)


Failing test case input:
3
-11 -2 -1

Expected output:
61


Actual output:
269


Fixed submission (verdict: Accepted):





if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    cost = float('inf')

    for z in range(-100, 100 + 1):
        tmp_cost = sum(((x - z) ** 2 for x in a))
        cost = min(cost, tmp_cost)

    print(cost)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=list(map(int,input().split()))
if n==4 and l[0]==-100:
  exit()

























s=2000000000
for i in range(-100,101):
  su=0
  for j in l:
    su+=(i-j)*(i-j)
  if su<s:
    s=su
print(s)

Failing test case input:
4
-100 -100 -100 -100

Expected output:
0

Actual output:
no output


Fixed submission (verdict: Accepted):
n=int(input())
l=list(map(int,input().split()))
s=2000000000000
for i in range(-100,101):
  su=0
  for j in l:
    su+=(i-j)*(i-j)
  if su<s:
    s=su
print(s)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
4
-100 -45 -100 -100

Expected output:
2269


Actual output:
90


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

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def sqsum(a, x):
    s = 0
    for i in range(len(a)):
        s += (a[i]-x)**2
    return s
    
n = int(input())
a = [int(i) for i in input().strip().split()]
s = sum(a)
if s % n == 0:
    x = s 
    print(sqsum(a, x))
else:
    x1 = s 
    x2 = (s+1) 
    
    
    r = min(sqsum(a, x1), sqsum(a, x2))
    print(r)
    

Failing test case input:
2
136 -1

Expected output:
9385


Actual output:
18497


Fixed submission (verdict: Accepted):
def sqsum(a, x):
    s = 0
    for i in range(len(a)):
        s += (a[i]-x)**2
    return s
    
n = int(input())
a = [int(i) for i in input().strip().split()]
s = sum(a)
sq = []
for x in range(-100, 101):
    sq.append(sqsum(a, x))
print(min(sq))
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())

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

a.sort()



l = len(a)
s = sum(a)



target = 0
ans = 0

if s % 2 == 1:
    target = int(s / n) + 1

else:
    target = int(s / n)


    
    
for i in range(l):
    ans = ans + (target - a[i]) * (target - a[i])

print(ans)


Failing test case input:
3
3 -1 13

Expected output:
104


Actual output:
107


Fixed submission (verdict: Accepted):
n = int(input())

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

a.sort()



l = len(a)
s = sum(a)



target = 0
ans = 0


 


 



target = round(s / n)
    
    
for i in range(l):
    ans = ans + (target - a[i]) * (target - a[i])

print(ans)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
4
-100 -100 -100 -100

Expected output:
0

Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
a = list(map(int,input().split()))

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

print(minimize(a))

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=list(map(int,input().split()))
if n==4 and l[0]==-100:
  exit()

























s=200000
for i in range(-100,101):
  su=0
  for j in l:
    su+=(i-j)*(i-j)
  if su<s:
    s=su
print(s)

Failing test case input:
4
-100 -45 -100 -100

Expected output:
2269


Actual output:
no output


Fixed submission (verdict: Accepted):
n=int(input())
l=list(map(int,input().split()))
s=2000000000000
for i in range(-100,101):
  su=0
  for j in l:
    su+=(i-j)*(i-j)
  if su<s:
    s=su
print(s)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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

C = Counter(A)

C_freq = C.most_common()
ma = C_freq[-1][0]
mi = C_freq[0][0]


cost = float('inf')

for j in range(mi, ma+1):
    tmp = 0
    for i, v in C.items():
        tmp += v*(j-i)**2
    cost = min(cost, tmp)
print(cost)


Failing test case input:
2
90 -4

Expected output:
4418


Actual output:
inf


Fixed submission (verdict: Accepted):

from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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

C = Counter(A)

C_freq = C.most_common()
ma = C_freq[-1][0]
mi = C_freq[0][0]


cost = float('inf')


for j in range(-100, 100+1):
    tmp = 0
    for i, v in C.items():
        tmp += v*(j-i)**2
    cost = min(cost, tmp)
print(cost)
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N  =int(input())
a = list(map(int,input().split()))
ans = (10**9)
for av in range(min(a),max(a)):
    Sum = 0
    for i in range(N):
        Sum += (a[i]-av)**2
    if Sum < ans:
        ans = Sum
print(ans)

Failing test case input:
4
-100 -100 -100 -100

Expected output:
0

Actual output:
1000000000


Fixed submission (verdict: Accepted):
N  =int(input())
a = list(map(int,input().split()))
ans = (10**9)
for av in range(min(a),max(a)+1):
    Sum = 0
    for i in range(N):
        Sum += (a[i]-av)**2
    if Sum < ans:
        ans = Sum
print(ans)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
a=list(map(int,input().split()))
ans=10**3
for i in range(-100,101):
    count=0
    for j in range(N):
        b=abs(i-a[j])
        b=b**2
        count+=b
    ans=min(ans,count)
print(ans)

Failing test case input:
2
87 -4

Expected output:
4141


Actual output:
1000


Fixed submission (verdict: Accepted):
N=int(input())
a=list(map(int,input().split()))
ans=10**9
for i in range(-100,101):
    count=0
    for j in range(N):
        b=abs(i-a[j])
        b=b**2
        count+=b
    ans=min(ans,count)
print(ans)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

total_costs = {}
if( len(list(set(A))) ):
    print(0)
else:
    for i in range(0, 100):
        cost = 0
        for a in A:
            cost += (a - i)*(a - i)
        total_costs[i] = cost
    print(min(total_costs.values()))

Failing test case input:
3
-18 3 0

Expected output:
258


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

total_costs = {}
if( len(set(A)) == 1 ):
    print(0)
else:
    for i in range(-100, 101):
        cost = 0
        for a in A:
            cost += (a - i)**2
        total_costs[i] = cost
    print(min(total_costs.values()))

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

max_a = max(a)
min_a = min(a)

sum_a = max(a) * len(a)
ans = 0

for i in range(min_a, max_a):
    s = sum([(j-i)**2 for j in a])
    if sum_a > s:
        sum_a = s
        ans = i

print(ans)

Failing test case input:
3
3 -1 5

Expected output:
19


Actual output:
0


Fixed submission (verdict: Accepted):
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)
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N = int(input())
A = list(map(int,input().split()))

sum = 0
result = 0

for i in A:
    sum+=i
ave = math.ceil(sum/len(A))

for i in A:
    result += pow(i-ave,2)

print(math.ceil(result))

Failing test case input:
3
3 0 7

Expected output:
25


Actual output:
26


Fixed submission (verdict: Accepted):
import math
N = int(input())
A = list(map(int,input().split()))

sum = 0
result = 0

for i in A:
    sum+=i
ave = round(sum/len(A))

for i in A:
    result += pow(i-ave,2)

print(round(result))

Problem: p04031
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)


Failing test case input:
3
-17 0 1

Expected output:
205


Actual output:
206


Fixed submission (verdict: Accepted):
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)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
import sys
from functools import reduce
input = sys.stdin.readline

def main():
    N = int(input())
    A = [int(c) for c in input().split()]
    mean_ceil = math.ceil(sum(A) / N)
    ans = reduce(lambda total, x: (x - mean_ceil) ** 2 + total, A, 0)

    print(ans)

main()

Failing test case input:
3
-25 2 -3

Expected output:
413


Actual output:
414


Fixed submission (verdict: Accepted):
import math
import sys
from functools import reduce
input = sys.stdin.readline

def fullsearch(a):
    for i in range(-100, 101):
        yield reduce(lambda total, x: (x - i) ** 2 + total, a, 0)

def main():
    input()
    A = [int(c) for c in input().split()]

    print(min(fullsearch(A)))

main()

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a_list=[int(i) for i in input().split()]

center=sum(a_list)
ans=0
for a in a_list:
    ans+=(a-center)**2
print(ans)

Failing test case input:
2
23 -4

Expected output:
365


Actual output:
545


Fixed submission (verdict: Accepted):
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)
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
2
203 -4

Expected output:
21425


Actual output:
90


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

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
n = int(input())
a = sorted(map(int,input().split()))
m = (a[0]+a[n-1])
ans = sys.maxsize
for i in range(5):
    x=m-2+i
    cost = 0
    for v in a:
        cost += ( x - v )**2
    ans = min(ans,cost)
print(ans)

Failing test case input:
3
0 -1 48

Expected output:
1569


Actual output:
4150


Fixed submission (verdict: Accepted):
import sys
n = int(input())
a = sorted(map(int,input().split()))
ans = sys.maxsize
for i in range(202):
    x = -100 + i
    cost = 0
    for v in a:
        cost += ( x - v )**2
    ans = min(ans,cost)
print(ans)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
mean = math.ceil(sum(l) / n)

for i in l:
  if not i == mean:
    ans += (i - mean)**2
print(ans)

Failing test case input:
3
3 0 7

Expected output:
25


Actual output:
26


Fixed submission (verdict: Accepted):
n = int(input())
l = list(map(int, input().split()))
ans = float('Inf')
i = -100
while i <= 100:
  temp = 0
  for j in l:
    temp += (j-i)**2
  ans = min(ans, temp)
  i += 1
print(ans)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
temp = input().rstrip().split(" ")
list1 = []
for i in range(N):
    list1.append(int(temp[i]))
list1.sort()
avg = round(sum(list1) / len(list1))
ans = 0
for i in range(N):
    print(ans)
    ans += (list1[i] - avg)**2
print(ans)

Failing test case input:
3
-16 1 -1

Expected output:
173


Actual output:
0
121
137
173


Fixed submission (verdict: Accepted):
N = int(input())
temp = input().rstrip().split(" ")
list1 = []
for i in range(N):
    list1.append(int(temp[i]))
list1.sort()
avg = round(sum(list1) / len(list1))
ans = 0
for i in range(N):
    ans += (list1[i] - avg)**2
print(ans)
Problem: p04031
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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()

Failing test case input:
3
-11 0 -1

Expected output:
74


Actual output:
101


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    a = list(map(int,input().split()))
    listcost = []
  
    for i in range(min(a),max(a)+1):
        cost = 0
        for j in a:
            if i != j:
                cost += (i - j) ** 2
        listcost.append(cost)
    print(min(listcost))
  
  
if __name__=='__main__':
  main()

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
L = [int(_) for _ in input().split()]
av = sum(L) 

done = []
total = 100000000000000000
tot2 = 0
for i in range(n):
    tot2 += abs(L[i] - av)**2
    if L[i] not in done:
        tot = 0
        goal = L[i]
        for j in range(n):
            tot += abs(L[j] - goal)**2
        if tot < total:
            total = tot
        done.append(L[i])

if len(done) == 1:
    print(0)
else:
    print(min(total, tot2))

Failing test case input:
3
2 -1 13

Expected output:
109


Actual output:
130


Fixed submission (verdict: Accepted):
n = int(input())
L = [int(_) for _ in input().split()]
L.sort()
total = 100000000000000000
num = 0
if L[0] == L[-1]:
    print(0)
else:
    for l in range(L[0], L[-1]):
        tot = 0
        for j in range(n):
            tot += abs(L[j] - l)**2
        if tot < total:
            num = l
            total = tot
            
    print(total)

Problem: p04031
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)))

Failing test case input:
3
-25 1 0

Expected output:
434


Actual output:
626


Fixed submission (verdict: Accepted):
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)))

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = [int(i) for i in input().split()]
s = int()
cost = 10000

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

print(cost)

Failing test case input:
2
203 -4

Expected output:
21425


Actual output:
10000


Fixed submission (verdict: Accepted):
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)
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
nums = input().split()
costs = []
if nums.count(nums[0]) != len(nums):
    for i in range(1, 101):
        sum = 0
        for num in nums:
            sum += (int(num) - i) ** 2
        costs.append(sum)
    ans = min(costs)
else:
    ans = 0
print(ans)

Failing test case input:
3
-25 1 0

Expected output:
434


Actual output:
677


Fixed submission (verdict: Accepted):
N = int(input())
nums = input().split()
costs = []
if nums.count(nums[0]) != len(nums):
    for i in range(-100, 101):
        sum = 0
        for num in nums:
            sum += (int(num) - i) ** 2
        costs.append(sum)
    ans = min(costs)
else:
    ans = 0
print(ans)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

print(n)
print(a)

costs = []

for i in range(-100, 101):
  cost = 0
  for j in range(n):
    cost += (a[j] - i) * (a[j] - i)
  costs.append(cost)

print(min(costs))

Failing test case input:
3
-20 2 -3

Expected output:
266


Actual output:
3
[-20, 2, -3]
266


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

costs = []

for i in range(-100, 101):
  cost = 0
  for j in range(n):
    cost += (a[j] - i) * (a[j] - i)
  costs.append(cost)

print(min(costs))

Problem: p04031
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)


Failing test case input:
3
-20 0 -3

Expected output:
233


Actual output:
25


Fixed submission (verdict: Accepted):
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)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = map(int, input().split())
m = round(sum(A) / N)
print(sum(list(map(lambda x: (x-m)**2,A))))


Failing test case input:
2
34 -2

Expected output:
648


Actual output:
0


Fixed submission (verdict: Accepted):
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)
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):





if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    z = (sum(a) + 1) 

    if z < 0:
        z -= 1

    if n == 1:
        print(0)
        exit()

    cost = 0

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

    print(cost)


Failing test case input:
2
87 -4

Expected output:
4141


Actual output:
7753


Fixed submission (verdict: Accepted):





if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    cost = float('inf')

    for z in range(-100, 100 + 1):
        tmp_cost = sum(((x - z) ** 2 for x in a))
        cost = min(cost, tmp_cost)

    print(cost)

Problem: p04031
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
3
3 0 5

Expected output:
13


Actual output:
10609


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

Problem: p04031
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
a=list(map(int,input().split()))
b=(max(a)+min(a))
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))

Failing test case input:
3
-20 1 -3

Expected output:
249


Actual output:
590


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

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
l = list(map(int,list(input().split())))
cost_min = (200**2)*100
cost = 0
for i in range(-100,101):
    for j in l:
        cost = (j - i)**2
        if cost < cost_min:
            cost_min = cost
print(cost_min)


Failing test case input:
3
-20 0 -3

Expected output:
233


Actual output:
0


Fixed submission (verdict: Accepted):
N = input()
l = list(map(int,list(input().split())))
cost_min = (200**2)*100
cost = 0
for i in range(-100,101):
    for j in l:
        cost += (j - i)**2
        
    if cost < cost_min:
        cost_min = cost
    cost = 0
print(cost_min)

Problem: p04031
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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(1,max(l)+1):
        te=0
        
        for j in l:
            te=te+(abs(j-i))**2
        
        x=min(x,te)
    print(x)        

Failing test case input:
3
-11 -2 -1

Expected output:
61


Actual output:
1000000007


Fixed submission (verdict: Accepted):
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)
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
arr = list(map(int,input().split()))
ans = 0
ave = int((sum(arr)/n) + 0.5)
for x in arr:
    ans += (x - ave) ** 2
print(ans)

Failing test case input:
3
-16 1 -1

Expected output:
173


Actual output:
178


Fixed submission (verdict: Accepted):
n = int(input())
arr = list(map(int,input().split()))
ave = round(sum(arr)/n)
arr = [(x-ave)**2 for x in arr]
print(sum(arr))

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

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

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

Failing test case input:
3
-1 0 14

Expected output:
141


Actual output:
142


Fixed submission (verdict: Accepted):
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)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
ans = 10**10
for i in range(-100,101):
    t = 0
    for j in a:
        t += (j-i)**2
        if t < ans:
            ans =t
print(ans)

Failing test case input:
3
-3 -1 23

Expected output:
419


Actual output:
0


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

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
*a, = map(int, input().split())
atai = math.ceil(sum(a) / n)
ans = 0
for x in a:
    if x == atai:
        pass
    else:
        ans += (x - atai) ** 2
print(ans)

Failing test case input:
3
3 -1 5

Expected output:
19


Actual output:
20


Fixed submission (verdict: Accepted):
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)

Problem: p04031
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

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

A = sum(list)

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)


Failing test case input:
3
1 -1 50

Expected output:
1669


Actual output:
0


Fixed submission (verdict: Accepted):

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

A = sum(list)
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)
Problem: p04031
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys


N = int(input())

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

cost = 10**18

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

print(cost)

Failing test case input:
3
-3 -1 21

Expected output:
355


Actual output:
1000000000000000000


Fixed submission (verdict: Accepted):
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)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import copy
n = int(input())
a = list(map(int, input().split()))
a_avg = int(sum(a)/len(a))
b = copy.copy(a)
while(len(set(b)) > 1):
    for i in range(len(a)):
        if b[i] > a_avg:
            b[i] -= 1
        if b[i] < a_avg:
            b[i] += 1
s = 0
for i in range(len(a)):
    s += (a[i]-b[i])**2
print(s)

Failing test case input:
3
-9 0 -2

Expected output:
45


Actual output:
46


Fixed submission (verdict: Accepted):

import copy
n = int(input())
a = list(map(int, input().split()))
a_avg = round(sum(a)/len(a))
b = copy.copy(a)
while(len(set(b)) > 1):
    for i in range(len(a)):
        if b[i] > a_avg:
            b[i] -= 1
        if b[i] < a_avg:
            b[i] += 1
s = 0
for i in range(len(a)):
    s += (a[i]-b[i])**2
print(s)

Problem: p04031
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)


Failing test case input:
2
32 -1

Expected output:
545


Actual output:
1089


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

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

print(ans)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

for i in range(n):
    mini.append(int(0))
    for j in range(n):
        mini[i]=mini[i]+(a[i]-a[j])**2
        if min(mini)<mini[i]:
            break

print(min(mini))


Failing test case input:
3
-5 2 0

Expected output:
26


Actual output:
29


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
mini=[]

for i in range(max(a)-min(a)+1):
    mini.append(int(0))
    for j in range(n):
        mini[i]=mini[i]+(i+min(a)-a[j])**2
        if min(mini)<mini[i]:
            break

print(min(mini))
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
if __name__ == '__main__':
    n = int(input())
    lst = list(map(int, input().split()))

    ans = 50*101
    for i in range(-100,101):
        print(i)
        mn = 0
        for c in lst:
            mn += (i-c)*(i-c)
        ans = min(ans,mn)

    print(ans)


Failing test case input:
3
-25 1 0

Expected output:
434


Actual output:
-100
-99
-98
-97
-96
-95
-94
-93
-92
-91
-90
-89
-88
-87
-86
-85
-84
-83
-82
-81
-80
-79
-78
-77
-76
-75
-74
-73
-72
-71
-70
-69
-68
-67
-66
-65
-64
-63
-62
-61
-60
-59
-58
-57
-56
-55
-54
-53
-52
-51
-50
-49
-48
-47
-46
-45
-44
-43
-42
-41
-40
-39
-38
-37
-36
-35
-34
-33
-32
-31
-30
-29
-28
-27
-26
-25
-24
-23
-22
-21
-20
-19
-18
-17
-16
-15
-14
-13
-12
-11
-10
-9
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
434


Fixed submission (verdict: Accepted):
if __name__ == '__main__':
    n = int(input())
    lst = list(map(int, input().split()))

    ans = (50*101)*(50*101)
    for i in range(-100,101):
        mn = 0
        for c in lst:
            mn += (i-c)*(i-c)
        ans = min(ans,mn)

    print(ans)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
common = int(sum(a) / n + 0.5)
cost = 0
for i in range(n):
  cost += (a[i] - common) ** 2
print(cost)

Failing test case input:
3
-17 0 0

Expected output:
193


Actual output:
194


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
mean = sum(a) / n
if mean >= -0.5:
  common = int(mean + 0.5)
else:
  common = int(mean - 0.5)
cost = 0
for i in range(n):
  cost += (a[i] - common) ** 2
print(cost)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import statistics
n = int(input())
a = [int(i) for i in input().split()]

m = ((sum(a)/n)*2 + 1) 


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


Failing test case input:
2
90 -4

Expected output:
4418


Actual output:
8290.0


Fixed submission (verdict: Accepted):
import statistics
n = int(input())
a = [int(i) for i in input().split()]

m = int(((sum(a)/n)*2 + 1) 


r = 0
for i in a:
  r += (i - m)**2
  
print(r)
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    ans = 10 * 5
    for i in range(min(A), max(A)+1):
        c = sum([(a-i)**2 for a in A])
        ans = min(ans, c)
    
    print(ans)


if __name__ == '__main__':
    main()

Failing test case input:
3
2 -1 13

Expected output:
109


Actual output:
50


Fixed submission (verdict: Accepted):
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    ans = 10 ** 7
    for i in range(min(A), max(A)+1):
        c = sum([(a-i)**2 for a in A])
        ans = min(ans, c)
    
    print(ans)


if __name__ == '__main__':
    main()

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
    print(0)

min_ans = 100000000000000000
for u in range(min(a), max(a)+1):
    ans = 0
    for i in a:
        ans += (u - i)**2
    if ans <= min_ans:
        min_ans = ans

print(int(min_ans))

Failing test case input:
4
-100 -100 -100 -100

Expected output:
0

Actual output:
0
0


Fixed submission (verdict: Accepted):
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)

Problem: p04031
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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()

Failing test case input:
3
2 -1 13

Expected output:
109


Actual output:
149


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    a = list(map(int,input().split()))
    listcost = []
  
    for i in range(min(a),max(a)+1):
        cost = 0
        for j in a:
            if i != j:
                cost += (i - j) ** 2
        listcost.append(cost)
    print(min(listcost))
  
  
if __name__=='__main__':
  main()

Problem: p04031
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def resolve():
	n = int(input())
	ans = 0
	a = list(map(int, input().split()))
	y = sum(a) / n
	for x in a:
		if x == y:
			continue
		ans += (x-y)**2
	print(round(ans))

resolve()

Failing test case input:
2
23 -2

Expected output:
313


Actual output:
312


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

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

resolve()
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
nlist= list(map(int,input().split()))

nmax = max(nlist)
nmin = min(nlist)

costs = []

for i in range(len(nlist)):
    p = 0
    for j in range(len(nlist)):
        p = p + (nlist[i]-nlist[j]) ** 2
    costs.append(p)
    
print(min(costs))
    

Failing test case input:
3
3 3 5

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
nlist= list(map(int,input().split()))

nmax = max(nlist)
nmin = min(nlist)

costs = []

for i in range(nmin,nmax + 1):
    p = 0
    for j in range(len(nlist)):
        p = p + (i-nlist[j]) ** 2
    costs.append(p)
    
print(min(costs))

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):





if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    z = (sum(a) + 1) 
    cost = 0

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

    print(cost)


Failing test case input:
3
-11 0 0

Expected output:
81


Actual output:
201


Fixed submission (verdict: Accepted):





if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    cost = float('inf')

    for z in range(-100, 100 + 1):
        tmp_cost = sum(((x - z) ** 2 for x in a))
        cost = min(cost, tmp_cost)

    print(cost)
Problem: p04031
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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))

Failing test case input:
3
-11 -2 -1

Expected output:
61


Actual output:
[27326, 26757, 26194, 25637, 25086, 24541, 24002, 23469, 22942, 22421, 21906, 21397, 20894, 20397, 19906, 19421, 18942, 18469, 18002, 17541, 17086, 16637, 16194, 15757, 15326, 14901, 14482, 14069, 13662, 13261, 12866, 12477, 12094, 11717, 11346, 10981, 10622, 10269, 9922, 9581, 9246, 8917, 8594, 8277, 7966, 7661, 7362, 7069, 6782, 6501, 6226, 5957, 5694, 5437, 5186, 4941, 4702, 4469, 4242, 4021, 3806, 3597, 3394, 3197, 3006, 2821, 2642, 2469, 2302, 2141, 1986, 1837, 1694, 1557, 1426, 1301, 1182, 1069, 962, 861, 766, 677, 594, 517, 446, 381, 322, 269, 222, 181, 146, 117, 94, 77, 66, 61, 62, 69, 82, 101, 126, 157, 194, 237, 286, 341, 402, 469, 542, 621, 706, 797, 894, 997, 1106, 1221, 1342, 1469, 1602, 1741, 1886, 2037, 2194, 2357, 2526, 2701, 2882, 3069, 3262, 3461, 3666, 3877, 4094, 4317, 4546, 4781, 5022, 5269, 5522, 5781, 6046, 6317, 6594, 6877, 7166, 7461, 7762, 8069, 8382, 8701, 9026, 9357, 9694, 10037, 10386, 10741, 11102, 11469, 11842, 12221, 12606, 12997, 13394, 13797, 14206, 14621, 15042, 15469, 15902, 16341, 16786, 17237, 17694, 18157, 18626, 19101, 19582, 20069, 20562, 21061, 21566, 22077, 22594, 23117, 23646, 24181, 24722, 25269, 25822, 26381, 26946, 27517, 28094, 28677, 29266, 29861, 30462, 31069, 31682, 32301, 32926]
61


Fixed submission (verdict: Accepted):
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))

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from decimal import *
n = int(input())
x = list(map(int, input().split()))
num = Decimal(str(sum(x)/n)).quantize(Decimal('0'), rounding=ROUND_DOWN)
num = int(num)
print(num)
cost=0
for i in range(n):
    cost += (x[i]-num)*(x[i]-num)
print(cost)

Failing test case input:
3
-25 1 0

Expected output:
434


Actual output:
-8
434


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

cost=0
for i in range(n):
    cost += (x[i]-num)*(x[i]-num)
print(cost)
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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(ans)

Failing test case input:
3
-20 1 -3

Expected output:
249


Actual output:
249.0


Fixed submission (verdict: Accepted):
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))

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a_list=[int(i) for i in input().split()]

center=int(sum(a_list)/n)
ans=0
for a in a_list:
    ans+=(a-center)**2
print(ans)

Failing test case input:
3
-16 0 -1

Expected output:
161


Actual output:
162


Fixed submission (verdict: Accepted):
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)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    ans = 10 * 10
    for i in range(min(A), max(A)+1):
        c = sum([(a-i)**2 for a in A])
        ans = min(ans, c)
    
    print(ans)


if __name__ == '__main__':
    main()

Failing test case input:
3
1 -1 50

Expected output:
1669


Actual output:
100


Fixed submission (verdict: Accepted):
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    ans = 10 ** 7
    for i in range(min(A), max(A)+1):
        c = sum([(a-i)**2 for a in A])
        ans = min(ans, c)
    
    print(ans)


if __name__ == '__main__':
    main()

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
dList = list(map(int,input().split()))

sD = sum(dList)/n
ig = int(sD)
po = sD-int(sD)

ad = 0
if po >= 0.5:
  ad = ig + 1
elif po != 0:
  ad = ig -1
else:
  ad = ig

result = 0
for i in range(len(dList)):
  result += (dList[i]-ad)**2

print(result)


Failing test case input:
3
-17 0 1

Expected output:
205


Actual output:
206


Fixed submission (verdict: Accepted):
n = int(input())
dList = list(map(int,input().split()))

sD = sum(dList)/n
ig = int(sD)
po = sD-int(sD)

ad = 0
if abs(po) >= 0.5:
  if sD >= 0:
    ad = ig + 1
  else:
    ad = ig -1
else:
  ad = ig

result = 0
for i in range(len(dList)):
  result += (dList[i]-ad)**2

print(result)