qyliang/CodeNanoFix huggingface dataset:
Buggy code:
s = list(input())

s.reverse()

print(''.join(s))

b = 0
ans = ''
for c in s:
    if c == 'B':
        b += 1
    else:
        if b > 0:
            b -= 1
            continue
        else:
            ans += c

ans = list(ans)
ans.reverse()
print(''.join(ans))



Fixed code:
s = list(input())
s.reverse()
b = 0
ans = ''

for c in s:
    if c == 'B':
        b += 1
    else:
        if b > 0:
            b -= 1
        else:
            ans += c

ans = list(ans)
ans.reverse()
print(''.join(ans))
Buggy code:
s = input()
x = ''
for i in s:
    if i == 'B':
        x += i
    else:
        x = x[:-1]
print(x)


Fixed code:
s = input()

t = ""
for i in s:
    if i == "B":
        if t:
            t = t[:-1]
    else:
        t += i

print(t)
Buggy code:
s=input()
a=''
for i in s:
    if i=='B':
        if len(a)!=0:a=a[:-1]
    else:a+=i
    print(a,i)
print(a)

Fixed code:
a=''
for i in input():
    if i=='B':
        if len(a)!=0:a=a[:-1]
    else:a+=i
print(a)
Buggy code:
s=str(input())
C= list(s)
list=[]
for I in range(len(C)):
    if I!='B':
        list.append(C[I])
    elif I=='B':
        list.pop()
 
print("".join(list))

Fixed code:
s=str(input())
C= list(s)
list=[]
for I in range(len(C)):
    if C[I]!='B':
        list.append(C[I])
    elif C[I]=='B' and len(list)!=0:
        list.pop()
 
print("".join(list))
Buggy code:
S = input()
ANS = ""
for i in range(len(S)):
  if S[i] == B:
    ANS = ANS[:-1]
  else:
    ANS += S[i]

print(ANS)

Fixed code:
S = input()
ANS = ""
for i in range(len(S)):
  if S[i] =="B":
    ANS = ANS[:-1]
  else:
    ANS += S[i]
 
print(ANS)
Buggy code:
from sys import stdin
from collections import deque
input = stdin.readline

s = input().rstrip()
d = deque([])

for i in s:
    if s != "B":
        d.append(s)
    else:
        if d:
            d.pop()
        else:
            pass

while d:
    p = d.popleft()
    print(p, end="")

print()


Fixed code:
from sys import stdin
from collections import deque
input = stdin.readline

s = input().rstrip()
d = deque([])

for i in s:
    if i != "B":
        d.append(i)
    else:
        if d:
            d.pop()
        else:
            pass

while d:
    print(d.popleft(), end="")

print()
Buggy code:
s=input()
ls=[]
for i in range(len(s)):
  if i!="B":
    ls.append(i)
  elif ls!=[]:
    del ls[-1]
print(*ls,sep="")

Fixed code:
s=input()
ls=[]
for i in range(len(s)):
  if s[i]!="B":
    ls.append(s[i])
  elif ls!=[]:
    del ls[-1]
print(*ls,sep="")
Buggy code:
keys = input()
outputs = []

for key in keys:
    if key == 'B':
        outputs.pop()
    else:
        outputs.append(key)

for output in outputs:
    print(output, end='')


Fixed code:
keys = input()
outputs = []

for key in keys:
    if key == 'B':
        if not outputs:
            pass
        else:
            outputs.pop()
    else:
        outputs.append(key)

for output in outputs:
    print(output, end='')
Buggy code:
s = input()
ans = []
for i in s:
    if i == 'B' and len(ans):
        ans.pop()
    else:
        ans.append(i)
print(''.join(ans))

Fixed code:
s = input()
ans = []
for i in s:
  if i == 'B':
    if len(ans):
      ans.pop()
  else:
    ans.append(i)
print(''.join(ans))
Buggy code:
t = ""
for x in input():
  if x == "B":
    t=t[:-1]
  else:
    t+=x
print(len(t))

Fixed code:
t = ""
for x in input():
  if x == "B":
    t=t[:-1]
  else:
    t+=x
print(t)
Buggy code:
a = str(input())

b = list(a)

c = len(b)

strs = []

for i in range(c):
  if b[i] == 'B':
    if i == 0 or len(strs) == 0 or b[i-1] == 'B':
      continue
    else:
      strs = strs[:1]
  else:
    strs.append(b[i])

print(''.join(strs))


Fixed code:
a = str(input())

b = list(a)

c = len(b)

strs = []

for i in range(c):
  if b[i] == 'B':
      strs = strs[:-1]
  else:
    strs.append(b[i])

print(''.join(strs))
Buggy code:
S = input()

F = []
for ch in S:
  if ch == "B" and len(F) > 0:
    F.pop()
  else:
    F.append(ch)
    
print("".join(F))

Fixed code:
S = input()

F = []
for ch in S:
  if ch == "B": 
    if len(F) > 0:
      F.pop()
  else:
    F.append(ch)
    
print("".join(F))
Buggy code:
y=""
a=str(input())
print(len(a))
for i in range (len(a)):
    if a[i]=="B":
        y=y[:-1]
    else:
        y=y+a[i]
print(y)

Fixed code:
y=""
a=str(input())
for i in range (len(a)):
    if a[i]=="B":
        y=y[:-1]
    else:
        y=y+a[i]
print(y)
Buggy code:
s = input()
ans = ""
for i in s
  if i == "B":
    if len(ans) > 0:
      ans = ans[:-1]
    else:
      ans = ans
  else:
    ans = ans + c
print(ans)

Fixed code:
s = input()
ans = ""
for i in s:
  if i == "B":
    if len(ans) > 0:
      ans = ans[:-1]
  else:
    ans = ans + i
print(ans)
Buggy code:
s = input()
ans = []
for c in s:
    if (c == 'B'):
        if (len(ans) > 0):
            ans.pop(-1)
    else:
        ans.append(c)

print(str(ans))


Fixed code:
s = input()
ans = []
for c in s:
    if (c == 'B'):
        if (len(ans) > 0):
            ans.pop(-1)
    else:
        ans.append(c)

print(''.join(ans))
Buggy code:
s = list(input())
size = len(s)
print(s)
ans = []
for i in range(size) :
    if s[i] ==  "B":
        ans.pop(-1)
    else: ans.append(s[i])

b = "".join(ans)
print(b)

Fixed code:
s = list(input())
size = len(s)
ans = []
for i in range(size) :
    if len(ans) >= 1 :
        if s[i] ==  "B" :
            ans.pop(-1)
        else : ans.append(s[i])

    elif s[i] != "B" : ans.append(s[i])

b = "".join(ans)
print(b)
Buggy code:
# coding: utf-8
import sys


def main(argv=sys.argv):

  inputs_ = list(input())

    string_ = []

    for input_ in inputs_:

        if input_ == 'B':

            if not string_ == []:
              
                string_.pop(-1)

        else:

            string_.append(input_)

    print(''.join(string_))

    return 0


if __name__ == '__main__':
    sys.exit(main())


Fixed code:
# coding: utf-8
import sys


def main(argv=sys.argv):
  
    inputs_ = list(input())

    string_ = []

    for input_ in inputs_:

        if input_ == 'B':

            if not string_ == []:
              
                string_.pop(-1)

        else:

            string_.append(input_)

    print(''.join(string_))

    return 0


if __name__ == '__main__':
    sys.exit(main())
Buggy code:
words="010B"
s=""
for word in words:
    if word=="B":
        s=s[:-1]
    else:
        s=s+word
print(s)

Fixed code:
words=input()
s=""
for word in words:
    if word=="B":
        s=s[:-1]
    else:
        s=s+word
print(s)
Buggy code:
s = list(input())

ans = []
for e in s:
    if e == "B" and len(ans) > 0:
        ans.pop(-1)
    else:
        ans.append(e)

print(ans)

Fixed code:
s = list(input())

ans = []
for e in s:
    if e == "B":
        if len(ans) > 0:
            ans.pop(-1)
    else:
        ans.append(e)

print("".join(ans))
Buggy code:
n = input()
s=""
for i in range(len(n)):
    if(n[i]=="B" and s != ""):
        s=s[:-1]
    else:
        s+=n[i]
print(s)
        


Fixed code:
n = input()
s=""
for i in range(len(n)):
    if(n[i]=="B"):
        if(s != ""):
            s=s[:-1]
    else:
        s+=n[i]
print(s)
Buggy code:
def b(x):
  if x=='':return''
  else:return x[:-1]
s,ans=input(),''
for i in range(len(s)):
  if s[i]!='B':ans=b(ans)
  else:ans+=s[i]
print(ans)

Fixed code:
def b(x):
  if x=='':return''
  else:return x[:-1]
s,ans=input(),''
for i in range(len(s)):
  if s[i]=='B':ans=b(ans)
  else:ans+=s[i]
print(ans)
Buggy code:
A =input()
B=""
for i in range(len(A)):
    if i==0:
        if A[i]!="B":
            B= B+A[i]
    else:
        if A[i] !="B":
            B=B+A[i]
        else:
            B = B[:i-2]
print(B)


            


Fixed code:
A =input()
B=""
for i in range(len(A)):
    if i==0:
        if A[i]!="B":
            B= B+A[i]
    else:
        if A[i] !="B":
            B=B+A[i]
        else:
            B = B[:(len(B)-1)]
print(B)
Buggy code:
s = input()
a = []

for _ in s:
    if _ == 'B':
        a = a[:-1]
    else:
        a += _

print(a)

Fixed code:
s = input()
a = ''

for _ in s:
    if _ == 'B':
        a = a[:-1]
    else:
        a += _

print(a)
Buggy code:
def main():
    s=input()
    li=[]
    for i in range(len(s)):
        if(s[i]!='B'):
            li.append(s[i])
        else:
            if(len(li)!=0):
                li.pop()
    for i in range(len(li)):
        print(i,end='')

main()


Fixed code:
def main():
    s=input()
    li=[]
    for i in range(len(s)):
        if(s[i]!='B'):
            li.append(s[i])
        else:
            if(len(li)!=0):
                li.pop()
    for i in li:
        print(i,end='')

main()
Buggy code:
s = input()
res = ""
for i in range(len(s)):
  if s[i] == "B":
    if res != "":
      res = res[:len(s)-1]
  else:
    res += s[i]
print(res)

Fixed code:
s = input()
res = ""
for i in range(len(s)):
  if s[i] == "B":
    if res != "":
      res = res[:len(res)-1]
  else:
    res += s[i]
print(res)
Buggy code:
s = input()
b = []

for i in s:
    if i == 'B':
        print('e')
        if len(b) != 0:
            b.pop()
    else:
        b.append(i)
    
print(''.join(b))

Fixed code:
s = input()
b = []

for i in s:
    if i == 'B':
        if len(b) != 0:
            b.pop()
    else:
        b.append(i)
    
print(''.join(b))
Buggy code:
s=input()
a=[]
def b(x):
  if len(x)!=0:
    x=x[:len(x)-1]
  return x
for i in range(len(s)):
  if s[i]=='B':
    a=b(a)
  else:
    a.append(s[i])
print(a)

Fixed code:
s=input()
a=[]
def b(x):
  if len(x)!=0:
    x=x[:len(x)-1]
  return x
for i in range(len(s)):
  if s[i]=='B':
    a=b(a)
  else:
    a.append(s[i])
for _ in range(len(a)):
  print(a[_],end='')
Buggy code:
s=input()
ans=""
for x in s:
  if x == 'B' and len(ans)>0:
    ans=ans[:len(ans)-1]
  else:
    ans+=x
print(ans)

Fixed code:
s=input()
ans=""
for x in s:
  if x == 'B' and len(ans)>0:
    ans=ans[:len(ans)-1]
  else:
    if x != 'B':
      ans+=x
print(ans)
Buggy code:
s = input()
output_s = ""

for i in s:
  if i == "B" and len( output_s) != 0:
    output_s = output_s[0:len( output_s)-1]
  else:
    output_s += i
    
print(output_s)

Fixed code:
s = input()
output_s = ""

for i in s:
  if i == "B" and len( output_s) != 0:
    output_s = output_s[0:len( output_s)-1]
  elif i != "B":
    output_s += i
  
print(output_s)
Buggy code:
def myAnswer(s:list)->str:
   ans = []
   for string in s:
      if(string == "B"):
         if(ans == []):
            continue
         else:
            ans.pop()
      else:
         ans.append(string)
   print(ans)
   return "".join(ans)

def modelAnswer():
   return
def main():
   s = list(input())
   print(myAnswer(s))
if __name__ == '__main__':
   main()

Fixed code:
def myAnswer(s:list)->str:
   ans = []
   for string in s:
      if(string == "B"):
         if(ans == []):
            continue
         else:
            ans.pop()
      else:
         ans.append(string)

   return "".join(ans)

def modelAnswer():
   return
def main():
   s = list(input())
   print(myAnswer(s))
if __name__ == '__main__':
   main()
Buggy code:
S = input()
stack = []

for s in S:
  if s == 'B':
    stack.pop()
  else:
    stack.append(s)
    
    
print(*stack, sep = '')

Fixed code:
S = input()
stack = []

for s in S:
  if s == 'B':
    if stack:stack.pop()
  else:
    stack.append(s)
    
    
print(*stack, sep = '')
Buggy code:
inst = input()
buf = []
for s in inst:
  if s == "B" and len(buf) != 0:
    del buf[-1]
  else:
    buf.append(s)
print(buf)

Fixed code:
inst = input()
buf = []
for s in inst:
  if s == "B":
    if len(buf) != 0:
      del buf[-1]
  else:
    buf.append(s)
print("".join(buf))
Buggy code:
N = int(input())
an = list(map(int,input().split()))
ave  = round((sum(an)/N),0)
print(ave)
ans = 0

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

print(inst(ans))

Fixed code:
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))
Buggy code:
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)

Fixed code:
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)
Buggy code:
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)

Fixed code:
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)
Buggy code:
N = int( input())
A = list( map( int, input().split()))
ans = 10**6
for i in range(N):
    a = A[i]
    cost = 0
    for j in range(N):
        cost += (A[j]-a)**2
    ans = min( ans, cost)
print(ans)

Fixed code:
N = int( input())
A = list( map( int, input().split()))
ans = 10**6
for a in range(-100, 101):
    cost = 0
    for j in range(N):
        cost += (A[j]-a)**2
    ans = min( ans, cost)
print(ans)
Buggy code:
N = int(input())
A = list(map(int,input().split()))

R = []

for i in range(min(A), max(A)):
    cost = 0
    for j in range(len(A)):
        cost += (i - A[j])**2
    R.append(cost)

print(min(R))


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

R = []

for i in range(min(A), max(A)):
    cost = 0
    for j in range(len(A)):
        cost += (i - A[j])**2
    R.append(cost)

if R == []:
    print(0)
else:
    print(min(R))
Buggy code:
n = int(input())
a = list(map(int,input().split()))

b = mean(a)//1

co = 10**9
su = 0
for k in range(3):
    for i in a:
        su += abs(i-b+(k-1)) ** 2
    co = min(co,su)
    su = 0

print(co)

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

b = sum(a)//n

co = 10**9
su = 0
for k in range(3):
    for i in a:
        su += abs(i-b+(k-1)) ** 2
    co = min(co,su)
    su = 0

print(co)
Buggy code:
n = int(input())
a = list(map(int,input().split()))

avg = round(sum(a)/n)

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

print (avg)

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

avg = round(sum(a)/n)

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

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


Fixed code:
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)
Buggy code:
def two_int():
    N, K = map(int, input().split())
    return N,K

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

def one_str():
    return input()

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

N=one_int()
X=many_int()

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

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

print(min_num)

Fixed code:
def two_int():
    N, K = map(int, input().split())
    return N,K

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

def one_str():
    return input()

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

N=one_int()
X=many_int()

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

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

print(min_sum)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
ans=10**9
for i in a:
    tmp=0
    for j in range(n):
        tmp+=(i-a[j])**2
    ans=min(tmp,ans)
print(ans)


Fixed code:
n=int(input())
a=list(map(int,input().split()))
ans=10**9
for i in range(-100,101):
    tmp=0
    for j in range(n):
        tmp+=(i-a[j])**2
    ans=min(tmp,ans)
print(ans)
Buggy code:
n = int(input())
A = list(map(int,input().split()))
ans = []
for i in range(-100,101):
    c = 0
    for a in A:
        c += (i-a)**2
        ans.append(c)

print(min(ans))

Fixed code:
n = int(input())
A = list(map(int,input().split()))
ans = []
for i in range(-100,101):
    c = 0
    for a in A:
        c += (i-a)**2
    ans.append(c)

print(min(ans))
Buggy code:
from functools import reduce

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

end = max(a)
ansAry = []

b = min(a)
while(True):
    suma = []
    for i in range(0,len(a)):
        if b == a[i]:
            pass
        else:
            suma.append((a[i] - b)*(a[i] - b))
    ansAry.append(reduce(lambda x,y:x+y,suma))
    b += 1
    if b == end:
        break

print(min(ansAry))

Fixed code:
from functools import reduce

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

end = max(a)
ansAry = []

b = min(a)
while(True):
    suma = []
    for i in range(0,len(a)):
        if b == a[i]:
            pass
        else:
            suma.append((a[i] - b)*(a[i] - b))

    try:
        ansAry.append(reduce(lambda x,y:x+y,suma))
    except:pass

    if b == end:
        break
    b += 1

if len(ansAry) > 0:
    print(min(ansAry))
else:
    print(0)
Buggy code:
def examC():
    N = I()
    a = LI()
    lower = min(a)
    L = (max(a)-min(a))
    cur = [0]*L
    for i in range(L):
        for j in range(N):
            cur[i] +=(a[j]-(i+lower))**2
    ans = min(cur)
    print(ans)

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Fixed code:
def examC():
    N = I()
    a = LI()
    lower = min(a)
    L = (max(a)-min(a))
    cur = [0]*L
    for i in range(L):
        for j in range(N):
            cur[i] +=(a[j]-(i+lower))**2
    if cur:
        ans = min(cur)
    else:ans = 0
    print(ans)

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()
Buggy code:
l_si = input().split(" ")
l_si_i = [int(s) for s in l_si]

sm = sum(l_si_i)
av = round(sm /dv)
ret = 0

for it in l_si_i:
  ret = ret + (it -av) **2


print(ret)

Fixed code:

dv = int(input())
l_si = input().split(" ")
l_si_i = [int(s) for s in l_si]

sm = sum(l_si_i)
av = round(sm /dv)
ret = 0

for it in l_si_i:
  ret = ret + (it -av) **2


print(ret)
Buggy code:
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)


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


Fixed code:
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)
Buggy code:
import statistics as st
import math
int(input())
s = list(map(int, input().split()))
md = math.floor(st.mean(s))
mu = avedown + 1
sd = 0
su = 0
for i in range(0, len(s)):
    sd = sd + (s[i] - md) ** 2
    su = su + (s[i] - mu) ** 2
print(min(sd, su))

Fixed code:
import statistics as st
import math
int(input())
s = list(map(int, input().split()))
md = math.floor(st.mean(s))
mu = md + 1
sd = 0
su = 0
for i in range(0, len(s)):
    sd = sd + (s[i] - md) ** 2
    su = su + (s[i] - mu) ** 2
print(min(sd, su))
Buggy code:
mini=10**29 
n=int(input())
l=[int(i) for i in input().split()]
i=sum(l)//n 
for z in range(1):
    sm=0  
    for j in l:
        sm+=(i-j)*(i-j)
    mini=min(mini,sm)
print(mini)

Fixed code:
mini=10**29 
n=int(input())
l=[int(i) for i in input().split()]
i = round(sum(l) / n )
for z in range(1):
    sm=0  
    for j in l:
        sm+=(i-j)*(i-j)
    mini=min(mini,sm)
print(mini)
Buggy code:
import math

from decimal import Decimal, ROUND_HALF_UP


def quantize(f):
    return int(Decimal(str(f)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))


def check(n, numbers):
    average = sum(numbers) / n
    average = quantize(average)
    costs = [int(math.pow(n - average, 2)) for n in numbers]
    return sum(costs)


def main():
    N = int(input())
    numbers = map(int, input().split())
    print(check(n=N, numbers=numbers))


if __name__ == '__main__':
    main()


Fixed code:
import math

from decimal import Decimal, ROUND_HALF_UP


def quantize(f):
    return int(Decimal(str(f)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))


def check(n, numbers):
    average = sum(numbers) / n
    average = quantize(average)
    costs = [int(math.pow(n - average, 2)) for n in numbers]
    return sum(costs)


def main():
    N = int(input())
    numbers = list(map(int, input().split()))
    print(check(n=N, numbers=numbers))


if __name__ == '__main__':
    main()
Buggy code:
n,a=open(0);*a,=map(int,a.split());print(min(sum((i-j-99)**2for j in a)for i in range(201)))

Fixed code:
n,a=open(0);*a,=map(int,a.split());print(min(sum((i-j-100)**2for j in a)for i in range(201)))
Buggy code:
N=int(input())
A=[]
A=list(map(int,list(input().split())))
S=[0]*201

for k in range(-100,100):
    for i in range(N):
        B=k-A[i]
        S[k]+=B*B
    if S[k-1]>S[k]:
        C=S[k]
print(C)

Fixed code:
N=int(input())
A=[]
A=list(map(int,list(input().split())))
S=[0]*201

C=10**7
for k in range(0,201):
    for i in range(N):
        B=(k-100)-A[i]
        S[k]+=B*B
    if C>S[k]:
        C=S[k]
print(C)
Buggy code:
#ABC043C
n=int(input())
a = list(map(int, input().split()))
h=sum(a)//len(a)
sum_a=0
for i in range(len(a)):
    sum_a=sum_a+(a[i]-h)**2
print(int(sum_a))

Fixed code:
#ABC043C
n=int(input())
a = list(map(int, input().split()))
h=round(sum(a)/len(a))
sum_a=0
for i in range(len(a)):
    sum_a=sum_a+(a[i]-h)**2
print(int(sum_a))
Buggy code:
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()))

Fixed code:
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()))
Buggy code:
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)


Fixed code:
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()
Buggy code:
N = int(input())
l = list(map(int,input().split()))
l_ans = [[] for _ in range(100)]

for i in range(100):
    sum = 0

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

    l_ans[i] = sum

print(min(l_ans))

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

for i in range(-100,101):
    sum = 0

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

    l_ans[i+100] = sum

print(min(l_ans))
Buggy code:
_ = input()
a = list(map(int, input().split()))
ans = 10 ** 18
for val in range(-200, 200):
  curr = 0
  for it in a:
    curr += (it - val) ** 2
    ans = min(ans, curr)
    print(ans)

Fixed code:
_ = input()
a = list(map(int, input().split()))
ans = 10 ** 18
for val in range(-200, 200):
    curr = 0
    for it in a:
        curr += (it - val) ** 2
    ans = min(ans, curr)
print(ans)