ZhenlongDai/ACPR huggingface dataset:
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=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)

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())
a = list(map(int,input().split()))
b = list(set(a))
ans = (10**9)
for av in range(min(a),max(a)):
    Sum = 0
    for i in range(N):
        Sum += a[i]**2-2*a[i]*av+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):
import statistics
n = int(input())
a = [int(i) for i in input().split()]

m = statistics.mean(a)
m = int(m) + 1 if m % 1 > 0.5 else int(m)
r = 0
for i in a:
  r += (i - m)**2
  
print(r)


Failing test case input:
3
-25 3 -1

Expected output:
459


Actual output:
460


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):
n = int(input())
a = [int(i) for i in input().split()]

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

print(ans)


Failing test case input:
2
136 -2

Expected output:
9522


Actual output:
70


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

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

print(ans)

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

Failing test case input:
3
-5 2 0

Expected output:
26


Actual output:
38


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):
N = int(input())
a = list(map(int,input().split()))
a.sort()
c = ((a[-1]-a[0])+1)

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

Failing test case input:
3
1 -1 48

Expected output:
1538


Actual output:
5006


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

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, 10):
        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
-12 0 -1

Expected output:
89


Actual output:
174


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())
c=list(map(int,input().split()))
minans=1000000000
for j in range(101):
  ans=0
  for i in range(n):
    ans+=(c[i]-j)**2
  minans=min(ans,minans)
print(minans)  
  

Failing test case input:
3
-18 3 0

Expected output:
258


Actual output:
333


Fixed submission (verdict: Accepted):
n=int(input())
c=list(map(int,input().split()))
minans=1000000000
for j in range(-101,101):
  ans=0
  for i in range(n):
    ans+=(c[i]-j)**2
  minans=min(ans,minans)
print(minans)

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):
        mn = 0
        for c in lst:
            mn += (i-c)*(i-c)
        ans = min(ans,mn)

    print(ans)


Failing test case input:
2
136 -1

Expected output:
9385


Actual output:
5050


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

cost=0
for i in range(n):
    cost += (x[i]-num)*(x[i]-num)
print(cost)

Failing test case input:
3
3 -1 0

Expected output:
9


Actual output:
10


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()))
a.sort()
minc = 100000000
for i in a:
    count = 0
    for j in a:
        count += (j - i)** 2
    minc = min(minc, count)

print(minc)

Failing test case input:
3
-20 2 -3

Expected output:
266


Actual output:
314


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
a.sort()
minc = 100000000
for i in range(a[0], a[-1] + 1):
    count = 0
    for j in a:
        count += (i - j)** 2
    minc = min(minc, count)

print(minc)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools
import math
n=int(input())
a=list(map(int,input().split()))
ave=round(sum(a)/n)

count=0
for i in range(n):
	count+=(a[i]-ave)**2
print(count)
print(round(-1.6))


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

Expected output:
21


Actual output:
21
-2


Fixed submission (verdict: Accepted):
import itertools
import math
n=int(input())
a=list(map(int,input().split()))
ave=round(sum(a)/n)

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

Problem: p04031
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
a = list(map(int,input().split()))
ans = 10**9
for i in range(N):
    ansa = 0
    for j in range(N):
        ansa += (a[i]-a[j])**2
    ans = min(ans,ansa)
print(ans)

Failing test case input:
2
23 -2

Expected output:
313


Actual output:
625


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

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

for a_i in range(min(a), max(a)+1):
    cost_sum = 0
    for a_j in a:
        cost_sum += ((a_j - a_i) ** 2)

print(cost_sum)


Failing test case input:
3
-17 0 0

Expected output:
193


Actual output:
289


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

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

print(min(cost))

Problem: p04031
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
l=list(map(int,input().split()))
a=min(l)
b=max(l)
d=a+b
if d%2:
  d=(d+1)
else:
  d=d
c=0
for i in l:
  if i!=d:
    c=c+(d-i)**2
print(c)
    

Failing test case input:
3
-11 0 0

Expected output:
81


Actual output:
201


Fixed submission (verdict: Accepted):
n=int(input())
l=list(map(int,input().split()))
k=[]
a=min(l)
b=max(l)
for i in range(a,b+1):
  c=0
  for j in range(n):
    c=c+(l[j]-i)**2
  k.append(c)
print(min(k))
Problem: p04031
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n= int(input())
a = list(map(int,input().split()))
from collections import defaultdict

d = defaultdict(int)

for i in range(n):
    d[a[i]] += 1

ans = []

for i in range(1,101):
    cnt = 0
    for j in d.keys():
        cnt += d[j]*(i-j)**2
    ans.append(cnt)

print(min(ans))


Failing test case input:
3
-25 3 -1

Expected output:
459


Actual output:
684


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

d = defaultdict(int)

for i in range(n):
    d[a[i]] += 1

ans = []

for i in range(-100,101):
    cnt = 0
    for j in d.keys():
        cnt += d[j]*(i-j)**2
    ans.append(cnt)

print(min(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(result)

Failing test case input:
3
-1 0 14

Expected output:
141


Actual output:
142


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 (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys


N = int(input())

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


if a.count(a[0]) == len(a):
    sys.exit()

cost = []


for i in range(1, 101):
    _cost=0
    for j in range(len(a)):    
        
        _cost += (a[j]-i)**2
    cost.append(_cost)

print(min(cost))

Failing test case input:
3
-20 1 -3

Expected output:
249


Actual output:
457


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

Failing test case input:
2
87 -4

Expected output:
4141


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split(' ')))
ans = []
if A.count(A[0]) == len(A):
    print(0)
    exit(0)
for i in range(-100,101):
    cost = 0
    for j in range(N):
        if A[j] == i:
            continue
        else:
            cost += (A[j] - i)**2
    ans.append(cost)
import heapq
heapq.heapify(ans)
print(heapq.heappop(ans))
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N = int(input())
an = list(map(int,input().split()))
ave  = math.ceil(sum(an)/N)
ans = 0

for i in an:
    ans += (i-ave)**2

print(ans)

Failing test case input:
3
2 10 1

Expected output:
49


Actual output:
50


Fixed submission (verdict: Accepted):
N = int(input())
an = list(map(int,input().split()))
ave  = round((sum(an)/N),0)
ans = 0

for i in an:
    ans += (i-ave)**2

print(int(ans))

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

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

mean = math.ceil(sum(a) / n)

ans = 0

for i in a:
  ans += (i-mean) ** 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 = list(map(int,input().split()))

mean = round(sum(a) / n)

ans = 0

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

print(ans)

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
q = sum(a) / n
if (q * 10) % 10 >= 5:
    q = int(q) + 1
else:
    q = int(q)

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

print(num)


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

Expected output:
21


Actual output:
26


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

for i in range(-101, 101, 1):
    rec = 0
    for j in range(n):
        rec += (i - a[j]) ** 2
    num = min(num, rec)

print(num)

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

Failing test case input:
2
80 -3

Expected output:
3445


Actual output:
0


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

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 = statistics.mean(a)
m = int(m) + 1 if m % 1 >= 0.5 else int(m)
r = 0
for i in a:
  r += (i - m)**2
  
print(r)


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

Expected output:
2269


Actual output:
2275


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

Failing test case input:
2
165 -4

Expected output:
14281


Actual output:
10000


Fixed submission (verdict: Accepted):
n = int(input())
listA = list(map(int, input().split()))
a = 0
b =  100000000
for i in range(min(listA), max(listA)+1):
  for j in range(n):
    a = a + (listA[j]-i)**2
  if a<b:
    b=a
  a=0
print(b)

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

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

Expected output:
61


Actual output:
0


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

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

ans = sum([abs(i) 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)

Failing test case input:
2
86 0

Expected output:
3698


Actual output:
86


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):
input()
a = list(map(int, input().split()))
for i in range(min(a),max(a)+1):
    cost_min = 0 if i == min(a) else cost_min
    cost = 0
    for e in a:
        add_cost = abs((e - i)) ** 2
        cost_min += add_cost if i == min(a) else 0
        cost += add_cost if i != min(a) else 0
    print(cost)
    if not i == min(a) and cost_min > cost:
        cost_min = cost
print(cost_min)

Failing test case input:
3
-25 2 -1

Expected output:
438


Actual output:
0
1206
1113
1026
945
870
801
738
681
630
585
546
513
486
465
450
441
438
441
450
465
486
513
546
585
630
681
738
438


Fixed submission (verdict: Accepted):
input()
a = list(map(int, input().split()))
for i in range(min(a),max(a)+1):
    cost_min = 0 if i == min(a) else cost_min
    cost = 0
    for e in a:
        add_cost = abs((e - i)) ** 2
        cost_min += add_cost if i == min(a) else 0
        cost += add_cost if i != min(a) else 0
    if not i == min(a) and cost_min > cost:
        cost_min = cost
print(cost_min)
Problem: p04031
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys


N = int(input())

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


if a.count(a[0]) == len(a):
    sys.exit()

cost = 10**18

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

print(cost)

Failing test case input:
3
0 -1 39

Expected output:
1041


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 math
n=int(input())
a=list(map(int,input().split()))
ave=math.ceil(sum(a)/n)
ans=0
for i in a:
    ans+=(i-ave)**2
print(ans)


Failing test case input:
3
-17 0 0

Expected output:
193


Actual output:
194


Fixed submission (verdict: Accepted):
import math
n=int(input())
a=list(map(int,input().split()))
ave=round(sum(a)/n,0)
ans=0
for i in a:
    ans+=(i-ave)**2
print(int(ans))

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


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

Expected output:
61


Actual output:
62


Fixed submission (verdict: Accepted):
from math import *
n=int(input())
l=list(map(int,input().split()))
s=ceil(sum(l)/n)
ss=s-1
c=0
x=0
for i in range(n):
    c+=(s-l[i])**2
for i in range(n):
    x+=(ss-l[i])**2
print(min(c,x))

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N = int(input())
    A = list(int(x) for x in input().split())
    avg1 = (sum(A)+1)
    avg2 = (sum(A))
    ans1 = 0
    ans2 = 0

    for a in A:
        ans1 += (a - avg1)**2

    for a in A:
        ans2 += (a - avg2)**2

    print(min(ans1, ans2))

if __name__ == '__main__':
    main()

Failing test case input:
2
45 -2

Expected output:
1105


Actual output:
2029


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    A = list(int(x) for x in input().split())
    ans = float('inf')


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

        if ans_tmp < ans:
            ans = ans_tmp

    print(int(ans))

if __name__ == '__main__':
    main()

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A =[int(x) for x in input().split()]
result=float('inf')
for i in range(max(A)):
  s=0
  for j in range(N):
    s += (i-A[j])**2
  result=min(result,s)
print(result)

Failing test case input:
3
-24 1 0

Expected output:
401


Actual output:
577


Fixed submission (verdict: Accepted):
N = int(input())
A =[int(x) for x in input().split()]
result=float('inf')
for i in range(min(A),max(A)+1):
  s=0
  for j in range(N):
    s += (i-A[j])**2
  result=min(result,s)
print(result)
Problem: p04031
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

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

Expected output:
61


Actual output:
62


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

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(e) for e in input().split()]
ans = float("inf")
MIN, MAX = min(a), max(a)
for i in range(MIN, MAX+1):
    cost = 0
    for j in a:
        cost = cost + (i-j)**2
    ans = min(ans, cost)
print(cost)

Failing test case input:
2
23 -2

Expected output:
313


Actual output:
625


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(e) for e in input().split()]
ans = float("inf")
MIN, MAX = min(a), max(a)
for i in range(MIN, MAX+1):
    cost = 0
    for j in a:
        cost = cost + (i-j)**2
    ans = min(ans, cost)
print(ans)

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

Failing test case input:
3
-11 0 0

Expected output:
81


Actual output:
146


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

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

Failing test case input:
3
3 -1 5

Expected output:
19


Actual output:
20


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

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
nums = list(map(int, input().split(' ')))
tmp = 0
max = 10**100
for i in nums:
    for j in nums:
        tmp += (j-i)**2
    if max > tmp:
        max = tmp
    tmp = 0
print(max)

Failing test case input:
2
86 0

Expected output:
3698


Actual output:
7396


Fixed submission (verdict: Accepted):
N = int(input())
nums = list(map(int, input().split(' ')))
temp = 0
cost = []
for i in range(-100, 101):
    for j in nums:
        temp += (j-i)**2
    cost.append(temp)
    temp = 0
print(min(cost))
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def cin():
	return map(int,input().split())

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))

import math

a = cino()
l = cina()
s = sum(l)

if s>0:
    s = math.ceil(s/len(l))
else:
    s = math.floor(s/len(l))
ans = 0
for i in l:
    ans += (i-s)**2

print(ans)



Failing test case input:
3
3 0 13

Expected output:
93


Actual output:
94


Fixed submission (verdict: Accepted):
def cin():
	return map(int,input().split())

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))

a = cino()
l = cina()
ans = 10**18
for i in range(-100,101):
    cost = 0
    for j in range(len(l)):
        cost += (i-l[j])**2
    ans = min(ans,cost)
print(ans)

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

check=float('inf')
for i in range(-100,101):
    check2=0
    for j in a:
        check2+=(i-j)**2
    if check>check2:
        check=check2
        ans=i

print(ans)

Failing test case input:
3
-12 0 -1

Expected output:
89


Actual output:
-4


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

check=float('inf')
for i in range(-100,101):
    ans=0
    for j in a:
        ans+=(i-j)**2
    if check>ans:
        check=ans

print(check)

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

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


min_cost = 200*100

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

print(min_cost)

Failing test case input:
2
203 -4

Expected output:
21425


Actual output:
20000


Fixed submission (verdict: Accepted):

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


min_cost = 111*(200**2)

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

print(min_cost)

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

avg = sum(A) 
ans = 0
for i, a in enumerate(A):
    ans += (a - avg) ** 2

print(ans)


Failing test case input:
3
1 -1 48

Expected output:
1538


Actual output:
4610


Fixed submission (verdict: Accepted):
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)
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import ceil
n=int(input())
A=list(map(int,input().split()))
ave=ceil(sum(A)/n)
print(sum(list(map(lambda x:(x-ave)**2,A))))


Failing test case input:
3
-11 0 0

Expected output:
81


Actual output:
82


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

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


Failing test case input:
3
-11 0 0

Expected output:
81


Actual output:
242


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

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

y = 20000
for i in range(min(l), max(l) + 1):
    x = 0
    for j in range(n):
        x += (l[j] - i)**2
    y = min(y, x)

print(y)

Failing test case input:
2
203 -4

Expected output:
21425


Actual output:
20000


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

y = 4*10**6
for i in range(min(l), max(l) + 1):
    x = 0
    for j in range(n):
        x += (l[j] - i)**2
    y = min(y, x)

print(y)

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


Failing test case input:
3
-13 2 -1

Expected output:
126


Actual output:
129


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):
n = int(input())
a = list(int(i) for i in input().split())
def costcalc(x):
  a2 = 0
  for i in range(n):
    a2 += (a[i]-x)**2
  return a2

cost = 10*15
for i in range(201):
  check = i-100
  cost = min(cost,costcalc(check))
print(cost)

Failing test case input:
3
-17 0 0

Expected output:
193


Actual output:
150


Fixed submission (verdict: Accepted):
n = int(input())
a = list(int(i) for i in input().split())
def costcalc(x):
  a2 = 0
  for i in range(n):
    a2 += (a[i]-x)**2
  return a2

cost = 10**15
for i in range(201):
  check = i-100
  cost = min(cost,costcalc(check))
  
print(cost)
Problem: p04031
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import math
N = int(input())
a = list(map(int,input().split()))
ave = math.ceil(sum(a)/len(a))
ans = 0
for i in a:
    ans += (i-ave)**2
print(ans)


Failing test case input:
3
-24 1 0

Expected output:
401


Actual output:
402


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

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

maxi = max(a)
mini = min(a)
ceiling = math.ceil((maxi + mini) / 2)
floor = math.floor((maxi + mini) / 2)

ceil_sum = sum([(item - ceiling) ** 2 for item in a])
floor_sum = sum([(item - floor) ** 2 for item in a])

print(min(ceil_sum, floor_sum))

Failing test case input:
3
-3 -1 23

Expected output:
419


Actual output:
459


Fixed submission (verdict: Accepted):
import math
N = int(input())
a = [int(_) for _ in input().split()]

floor = math.floor(sum(a) / len(a))
ceil = math.ceil(sum(a) / len(a))

ceil_sum = sum([(item - ceil) ** 2 for item in a])
floor_sum = sum([(item - floor) ** 2 for item in a])

print(min(ceil_sum, floor_sum))

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


done = []
total = 100000000000000000
tot2 = 0
for i in range(n):
    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])
        
av = sum(done)
for i in range(n):
    tot2 += abs(L[i] - av)**2
    
if len(done) == 1:
    print(0)
else:
    print(min(total, tot2))

Failing test case input:
3
-3 -1 21

Expected output:
355


Actual output:
488


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.4.3), verdict: Wrong Answer):
import math
N=int(input())
a=list(map(int,input().split()))

Q=0
for i in a:
    Q+=(i-math.ceil(sum(a)/len(a)))**2
print(Q)

Failing test case input:
3
3 -1 5

Expected output:
19


Actual output:
20


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

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

unique_numbers = list(set(numbers))
if len(unique_numbers) == 1:
  print(0)
  exit(0)

s = sum(numbers)
t = math.floor(s/2)

r = 0
for num in numbers:
  r += abs((num - t) * 2)
  
print(r)


Failing test case input:
3
1 -1 21

Expected output:
296


Actual output:
62


Fixed submission (verdict: Accepted):

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

unique_numbers = list(set(numbers))
if len(unique_numbers) == 1:
  print(0)
  exit(0)

min_num = min(numbers)
max_num = max(numbers)

results = []
for i in range(min_num, max_num):
  r = 0
  for num in numbers:
    r += abs((num - i) ** 2)
  results.append(r)

min_r = min(results)
print(min_r)

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

diff,ans=100000,100000


for x in range(min(a),max(a)+1):
    crnt=0
    for aa in a:
        crnt+=(aa-x)**2
    if crnt<diff:
        ans=crnt

print(ans)

Failing test case input:
3
-25 2 -3

Expected output:
413


Actual output:
754


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

ans=10**10
for x in range(min(a),max(a)+1):
    crnt=0
    for aa in a:
        crnt+=(aa-x)**2
    if crnt<ans:
        ans=crnt

print(ans)

Problem: p04031
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
mini=10**29 
n=int(input())
l=[int(i) for i in input().split()]
for i in l:
    sm=0  
    for j in l:
        sm+=(i-j)*(i-j)
    mini=min(mini,sm)
print(mini)

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

Expected output:
61


Actual output:
82


Fixed submission (verdict: Accepted):
mini=10**29 
n=int(input())
l=[int(i) for i in input().split()]
for i in range(min(l)-19,max(l)+3):
    sm=0  
    for j in l:
        sm+=(i-j)*(i-j)
    mini=min(mini,sm)
print(mini)

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

a_ave=a[0]+a[-1]
if a_ave%2==0:
    num=a_ave
else:
    num=a_ave
ans=0
for i in range(n):
    ans+=(num-a[i])**2
print(ans)

Failing test case input:
2
23 -1

Expected output:
288


Actual output:
530


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

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

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

Failing test case input:
3
-13 2 -1

Expected output:
126


Actual output:
100


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.8.2), verdict: Wrong Answer):
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) :
            
            for j in range(n) :
                cost[i] = cost[i] + (al[j] - i) ** 2
                
        print(min(cost))



if __name__ == '__main__':
    main()


Failing test case input:
3
-16 1 -1

Expected output:
173


Actual output:
258


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



if __name__ == '__main__':
    main()

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

ans = 9999

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


Failing test case input:
2
165 -4

Expected output:
14281


Actual output:
9999


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

ans = 9999999999

for i in range(-100, 101):
    sumof = 0
    for j in a:
        sumof += (i - j)*(i - j)
    ans = min(ans, sumof)
    
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)
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)


Failing test case input:
3
-17 0 2

Expected output:
218


Actual output:
518


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 (Python (3.4.3), verdict: Wrong Answer):
from statistics import mean 
import math
n=int(input())
arr=[int(x) for x in input().split()]
a=math.ceil(mean(arr))
s=0
for x in arr:
    s=s+((x-a)**2)
print(s)

Failing test case input:
3
-25 3 -1

Expected output:
459


Actual output:
460


Fixed submission (verdict: Accepted):
from statistics import mean 
import math
n=int(input())
arr=[int(x) for x in input().split()]
a=math.ceil(mean(arr))
b=math.floor(mean(arr))
s1=0
s2=0
for x in arr:
    s1=s1+((x-a)**2)
    s2=s2+((x-b)**2)
print(min(s1,s2))

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

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



Failing test case input:
2
203 -4

Expected output:
21425


Actual output:
20100


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

ans = 100100100
for i in range(-100, 101):
    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):
a=int(input())
b=list(map(int,input().split()))
cost=999999
for i in range(min(b),max(b)):
    c=0
    for j in b:
        c=c+(i-j)**2
    if c<cost:
        cost=c
print(cost)

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

Expected output:
0

Actual output:
999999


Fixed submission (verdict: Accepted):
a=int(input())
b=list(map(int,input().split()))
cost=9999999
for i in range(min(b),max(b)+1):
    c=0
    for j in b:
        c=c+(i-j)**2
    if c<cost:
        cost=c
print(cost)
Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
if __name__ == '__main__':
    n = int(input())
    lst = list(map(int, input().split()))

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

    print(ans)


Failing test case input:
2
23 -4

Expected output:
365


Actual output:
100


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





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

    if z < 0 and sum(a) % n != 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:
3
-16 1 -1

Expected output:
173


Actual output:
174


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 (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
ans = 10**10
L = list(map(int,input().split()))
for i in range(-101,101): 
  tmp = 0
  for x in L:
    tmp += (ans - x) ** 2
  ans = min(ans,tmp)
print(ans)

Failing test case input:
3
-19 0 0

Expected output:
241


Actual output:
10000000000


Fixed submission (verdict: Accepted):
N = int(input())
ans = 10**10
L = list(map(int,input().split()))
for i in range(-101,101): 
  tmp = 0
  for x in L:
    tmp += (i - x) ** 2
  ans = min(ans,tmp)
print(ans)

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

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

X = math.ceil(sum(a) / n)

P = 0

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

print(P)

Failing test case input:
3
-16 2 0

Expected output:
195


Actual output:
196


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

Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(i) for i in input().split()]
cons = int(sum(A)/N)
ans = 0 
for i in range(N):
  ans += (A[i] - cons)**2 

print(ans)

Failing test case input:
3
2 -1 13

Expected output:
109


Actual output:
110


Fixed submission (verdict: Accepted):
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)
Problem: p02994
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, L = map(int, input().split())
aji = [L + i for i in range(N)]
if 0 not in aji:
  print(sum(aji)-min(aji))
else:
  print(sum(aji))
  

Failing test case input:
3 -88

Expected output:
-175


Actual output:
-173


Fixed submission (verdict: Accepted):
N, L = map(int, input().split())
aji = [L + i for i in range(N)]
print(sum(aji) - min(aji, key=abs))

Problem: p02994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, l = list(map(int ,input().split()))
sumApple = sum(range(l,l+n))
aMin = 10000
for i in range(n):
    if abs(l + i) < aMin:
        aMin = abs(l + i)
print(sumApple - aMin)

Failing test case input:
5 -6

Expected output:
-18


Actual output:
-22


Fixed submission (verdict: Accepted):
n, l = list(map(int ,input().split()))
sumApple = sum(range(l,l+n))
aMin = 10000
for i in range(1,n + 1):
    if abs(l + i - 1) < abs(aMin):
        aMin = (l + i - 1)
print(sumApple - aMin)

Problem: p02994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import copy
N, L = map(int, input().split())

taste = list(range(1, N+1))
for a in range(0, N):
    taste[a] = taste[a] + L - 1

abs_taste = copy.deepcopy(taste)

for a in range(0, N):
    abs_taste[a] = abs(abs_taste[a])

print(sum(taste))


Failing test case input:
16 -50

Expected output:
-645


Actual output:
-680


Fixed submission (verdict: Accepted):
import copy
N, L = map(int, input().split())

taste = list(range(1, N+1))
for a in range(0, N):
    taste[a] = taste[a] + L - 1

abs_taste = copy.deepcopy(taste)

for a in range(0, N):
    abs_taste[a] = abs(abs_taste[a])

taste.pop(abs_taste.index(min(abs_taste)))


print(sum(taste))

Problem: p02994
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

n,l = map(int,input().split())
ans=0
for i in range(1,n+1):
    if i == 1:
        continue
    else:
        ans+=(l+i-1)
print(ans)

Failing test case input:
23 -50

Expected output:
-869


Actual output:
-847


Fixed submission (verdict: Accepted):

n,l = map(int,input().split())
ans=0
for i in range(1,n+1):
    ans+=(l+i-1)
if l+n-1 < 0:
    print(ans-(l+n-1))
elif l+n-1 >= 0 and l <= 0:
    print(ans)
else:
    print(ans-l)

Problem: p02994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, L = map(int, input().split() )

if L > -1:
  N_eat = 1
elif N+L-1 < 1:
  N_eat = N
else:
  N_eat = 1-L
 
pie = N*(N+1)/2 +N*(L-1) - (L + N_eat-1) 
print("{}".format(pie) )

Failing test case input:
38 4

Expected output:
851


Actual output:
851.0


Fixed submission (verdict: Accepted):
N, L = map(int, input().split())
 
if L > -1:
  N_eat = 1
elif N+L-1 < 1:
  N_eat = N
else:
  N_eat = 1-L
 
pie = N*(N+1)/2 +N*(L-1) - (L + N_eat-1) 
print(int(pie) )
Problem: p02994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,l=map(int, input().split())

mi=l
ma=l+n-1

if mi <= 0 and 0 <= ma:
    print(int((mi+ma)*n/2))
else:
    print(int((mi+ma)*n/2-abs(min(mi, ma))))

Failing test case input:
18 -124

Expected output:
-1972


Actual output:
-2203


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

mi=l
ma=l+n-1

if mi <= 0 and 0 <= ma:
    print(int((mi+ma)*n/2))
elif abs(mi) < abs(ma):
    print(int((mi+ma)*n/2-mi))
else:
    print(int((mi+ma)*n/2-ma))

Problem: p02994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,l=map(int,input().split())
a=0
b=1000
for i in range(l,l+n):
  a+=i
  if b>abs(i):
    b=i
print(a-b)

Failing test case input:
5 -16

Expected output:
-58


Actual output:
-54


Fixed submission (verdict: Accepted):
n,l=map(int,input().split())
a=0
b=1000
for i in range(l,l+n):
  a+=i
  if abs(b)>abs(i):
    b=i
print(a-b)

Problem: p02994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from functools import reduce

Input = input()

n, l = Input.split(' ')
n, l = int(n), int(l)


def ni_taste(i,l=l):
    return l+i-1

taste_list = [ni_taste(i) for i in range(1, n+1)] 
taste_abs_list = [abs(abs_taste) for abs_taste in taste_list]
print( reduce((lambda x, y: x + y), taste_list) - min(taste_abs_list)  )


Failing test case input:
5 -29

Expected output:
-110


Actual output:
-160


Fixed submission (verdict: Accepted):
from functools import reduce

Input = input()

n, l = Input.split(' ')
n, l = int(n), int(l)


def ni_taste(i,l=l):
    return l+i-1

taste_list = [ni_taste(i) for i in range(1, n+1)] 
taste_abs_list = [abs(abs_taste) for abs_taste in taste_list]

print( reduce((lambda x, y: x + y), taste_list) - taste_list[taste_abs_list.index(min(taste_abs_list))] ,end='' )

Problem: p02994
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,l=map(int,input().split())
s=n*l+n*(n+1)/2-n
d2=n**2
x=0
for i in range(n):
    s1=s-i-l
    d=abs(s-s1)
    if d<d2:
        d2=d
        x=i
print(s-l-x)

Failing test case input:
16 -50

Expected output:
-645


Actual output:
-645.0


Fixed submission (verdict: Accepted):
n,l=map(int,input().split())
s=n*l+n*(n+1)/2-n
d2=100000000000000000
x=0
for i in range(n):
    s1=s-i-l
    d=abs(s-s1)
    if d<d2:
        d2=d
        x=i
print(int(s-l-x))

Problem: p02994
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
[n,l] = [int(i) for i in input().split()]
taste = []
for i in range(n):
  taste.append(l + i - 1)
a = 100000000
for i in range(n):
  if abs(taste[i]) < a:
    a = taste[i]
print(sum(taste) - a)

Failing test case input:
13 -8

Expected output:
-26


Actual output:
-30


Fixed submission (verdict: Accepted):
[n,l] = [int(i) for i in input().split()]
taste = []
for i in range(n):
  taste.append(l + i)
a = 100000000
for i in range(n):
  if abs(taste[i]) < abs(a):
    a = taste[i]
print(sum(taste) - a)