qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N = int(input())
X = input().split()
X = [int(l) for l in X]

s = 0
for x in X:
    s += (x-1)**2

S = s

if N == 1:
    print(0)
else:
    m = max(X)
    n = min(X)
    for P in range(n,m+1):
        s = 0
        for x in X:
            s += (x-P)**2
        if s < S:
            S = s
	print(S)

Fixed code:
N = int(input())
X = input().split()
X = [int(l) for l in X]

s = 0
for x in X:
    s += (x-X[0])**2
S = s

if N == 1:
    print(S)
else:
    m = max(X)
    n = min(X)
    for P in range(n,m+1):
        s = 0
        for x in X:
            s += (x-P)**2
        if s < S:
            S = s
    print(S)
Buggy code:
N = int(input())
l = map(int, input().split())

mean = int(sum(l)/N)

stamina = 0

for p in l:
	stamina += (p - mean)**2
    
print(stamina)

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

mean = round(sum(l)/N)
stamina = 0

for p in l:
    stamina += (p - mean)**2

print(stamina)
Buggy code:
n=int(input())
l=list(map(int,input().split()))
       
f_ans=100000000000000
for i in l:
  ans=0
  for j in range(min(l),max(l)+1):
    ans+=(i-j)**2
    f_ans=min(ans,f_ans)
    
print(f_ans)
    
    

Fixed code:
n=int(input())
lis=list(map(int,input().split()))
       
f_ans=100000000000000
for i in range(min(lis),max(lis)+1):
  ans=0
  for l in lis:
    ans+=(i-l)**2
  f_ans=min(ans,f_ans)
    
print(f_ans)
Buggy code:
n=int(input())
xl=list(map(int,input().split()))
ans=[]
for i in range(xl[-1]-xl[0]+1):
    sum1=0
    for xi in xl:
        sum1+=(xi-xl[0]-i)**2
    ans.append(sum1)
print(ans)
print(min(ans))

Fixed code:
n=int(input())
xl=list(map(int,input().split()))
xl.sort()
ans=[]
for p in range(xl[-1]-xl[0]+1):
    sum1=0
    for xi in xl:
        sum1+=(xi-xl[0]-p)**2
    ans.append(sum1)
print(min(ans))
Buggy code:
import math
import numpy as np
N = int(input())
X = list(map(int,input().split()))
P = np.round(np.average(X))

print(np.dot(X,X) + P * P * N - 2 *np.sum(X)*P)


Fixed code:
import math
import numpy as np
N = int(input())
X = list(map(int,input().split()))
P = np.round(np.average(X))

print(int(np.dot(X,X) + P * P * N - 2 *np.sum(X)*P))
Buggy code:
n=int(input())
x=[i for i in map(int, input().split())]
ans=1000000000000000000000000000000000000000
x.sort()
print(n,x)

for i in range(x[n-1]):
  cnt=0
  for k in x:
    cnt= cnt+(k-i)**2
  ans=min(ans,cnt)
print(ans)

Fixed code:
n=int(input())
x=[i for i in map(int, input().split())]
ans=1000000000000000000000000000000000000000
x.sort()

for i in range(x[n-1]+1):
  cnt=0
  for k in x:
    cnt= cnt+(k-i)**2
  ans=min(ans,cnt)
print(ans)
Buggy code:
n = int(input())
lst = [int(x) for x in input().split()]

num = sum(lst)//n
sum1 = 0
sum2 = 0

for i in lst:
  sum1 += (i-num)**2
  sum2 += (i-num+1)**2
  
if sum1 < sum2:
  print(sum1)
else:
  print(sum2)

Fixed code:
n = int(input())
lst = [int(x) for x in input().split()]

num = sum(lst)//n
sum1 = 0
sum2 = 0

for i in lst:
  sum1 += (i-num)**2
  sum2 += (i-num-1)**2
  
if sum1 < sum2:
  print(sum1)
else:
  print(sum2)
Buggy code:
"""Boot-camp-for-Beginners_002_C_Rally_19-August-2020.py"""
import numpy as np
import sys

N=int(input())
X = list(map(int,input().split()))
print(X)
s=0
for i in range(len(X)):
    s+=X[i]
P=int(s/N)

Sum_round_down=0
Sum_round_up=0
for i in range(len(X)):
    Sum_round_down+=(P-X[i])**2
    Sum_round_up+=(P+1-X[i])**2
if(Sum_round_down>=Sum_round_up):
    Sum=Sum_round_up
else:
    Sum=Sum=Sum_round_down
print(int(Sum))

Fixed code:
"""Boot-camp-for-Beginners_002_C_Rally_19-August-2020.py"""
import numpy as np
import sys

N=int(input())
X = list(map(int,input().split()))
s=0
for i in range(len(X)):
    s+=X[i]
P=int(s/N)

Sum_round_down=0
Sum_round_up=0
for i in range(len(X)):
    Sum_round_down+=(P-X[i])**2
    Sum_round_up+=(P+1-X[i])**2
if(Sum_round_down>=Sum_round_up):
    Sum=Sum_round_up
else:
    Sum=Sum=Sum_round_down
print(int(Sum))
Buggy code:
n = int(input().strip())
L = list(map(int, input().strip().split()))
ans=10**6+1
for p in range(max(L[-1])+1):
    tmp=0
    for x in L:
        tmp+=(x-p)**2
    ans=min(ans,tmp)
print(ans)

Fixed code:
n = int(input().strip())
L = list(map(int, input().strip().split()))
ans=10**6+1
for p in range(max(L)+1):
    tmp=0
    for x in L:
        tmp+=(x-p)**2
    ans=min(ans,tmp)
print(ans)
Buggy code:
n=int(iinput())
a=list(map(int,input().split()))

ans=99999999
for i in range(1,101):
  d=0
  for x in a:
    d+=(a-i)*(a-i)
  ans=min(ans,d)
print(ans)
    
  

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

ans=99999999
for i in range(1,101):
  d=0
  for x in a:
    d+=(x-i)*(x-i)
  ans=min(ans,d)
print(ans)
Buggy code:
N = int(input())
X=list(map(int, input().split())) 
print(X)
X_max = max(X)
X_min = min(X)

answerlist = []
for i in range(X_min,X_max):
  newX = [(n-i)**2 for n in X]
  print(newX)
  total = sum(newX)
  answerlist.append(total)
  
print(min(answerlist))

Fixed code:
N = int(input())
X=list(map(int, input().split())) 
X_max = max(X)
X_min = min(X)
 
answerlist = []
for i in range(X_min,X_max+1):
  newX = [(n-i)**2 for n in X]
  total = sum(newX)
  answerlist.append(total)
  
print(min(answerlist))
Buggy code:
import numpy as np
n = int(input())
X = list(map(int, input().split()))
a = sum(X)
b = sum(X[i]**2 for i in range(n))
m = np.floor(a/n)
if m + 1/2 <= a/n:
  m += 1
else:
  break
s = n*(m**2) - 2*a*m + b
print(int(s))


Fixed code:
import numpy as np
n = int(input())
X = list(map(int, input().split()))
a = sum(X)
b = sum(X[i]**2 for i in range(n))
m = np.floor(a/n)
if m + 1/2 <= a/n:
  m += 1
s = n*(m**2) - 2*a*m + b
print(int(s))
Buggy code:
N = int(input())
X = list(map(int,input().split()))
#ans = 10000
ls = []
for i in range(1,100):
    sum = 0
    for j in range(N):
        #sum += (X[j]-i)**2
        ls.append((X[j]-i)**2)
    #ans = min(ans,sum)
print(min(ls))


Fixed code:
N = int(input())
X = list(map(int,input().split()))
#ans = 10000
ls = []
for i in range(1,100):
    sum = 0
    for j in range(N):
        sum += (X[j]-i)**2
    ls.append(sum)
    #print(ls)
    #ans = min(ans,sum)
print(min(ls))
Buggy code:
n = int(input())
X = list(map(int, input().split()))

sum = 0
for x in X:
    sum += x
avg = sum // n

ans = 0
for x in X:
    ans += pow((x-avg), 2)
print(ans)

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

sum = 0
for x in X:
    sum += x
avg = round(sum / n)

ans = 0
for x in X:
    ans += pow((x-avg), 2)
print(ans)
Buggy code:

n = int(input())
x = list(map(int,input().split()))
x.sort()
cnt = 0
min = 0

for i in range(x[0], x[-1] + 1):
    for j in range(n):
        cnt += (x[j] - i) ** 2

    if i == x[0]:
        minimum = cnt

    minimum = min([minimum, cnt])
    cnt = 0

print(minimum)


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

x.sort()
cnt = 0
minimum = 0
for i in range(x[0], x[-1] + 1):
    for j in range(n):
        cnt += (x[j] - i) ** 2

    if i == x[0]:
        minimum = cnt

    minimum = min([minimum, cnt])
    cnt = 0

print(minimum)
Buggy code:
import collections
n = int(input())
x = list(map(int, input().split()))

del x[n:]

print(x)

now = float('inf')
new = 0

for i in range(100):
  new = 0
  for j in range(len(x)):
    new += (x[j] - (i + 1))** 2
  if new < now:
    now = new

print(now)


Fixed code:
import collections
n = int(input())
x = list(map(int, input().split()))

del x[n:]

# print(x)

now = float('inf')
new = 0

for i in range(100):
  new = 0
  for j in range(len(x)):
    new += (x[j] - (i + 1))** 2
  if new < now:
    now = new

print(now)
Buggy code:
import numpy as np
import collections
from sys import stdin


def get_result(data):
    N, X = data[0][0], data[1:][0]
    X = np.array(X)
    max_X = max(X)
    tmp = np.zeros(max_X)
    for i in range(max_X):
        tmp[i] = np.sum((X - i) ** 2)
    return min(tmp)

if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


Fixed code:
import numpy as np
import collections
from sys import stdin


def get_result(data):
    N, X = data[0][0], data[1:][0]
    X = np.array(X)
    max_X = max(X)
    tmp = np.zeros(max_X + 1)
    for i in range(max_X + 1):
        tmp[i] = np.sum((X - i) ** 2)
    return int(min(tmp))

if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)
Buggy code:
N = int(input())
List = list(map(int, input().split()))
s = 0
t = 0

for i in range(100):
  for j in range(N):
    t += (List[j]-i-1)**2

  if s>t:
    s = t

print(t)


Fixed code:
N = int(input())
List = list(map(int, input().split()))
s = 1000000000000000000000
t = 0

for i in range(100):
  for j in range(N):
    t += (List[j]-i-1)**2

  if s>t:
    s = t
    t = 0
  else:
    t = 0

print(s)
Buggy code:
import numpy as np
n=int(input())
x=np.fromstring(input(),int,sep=' ')
print(x)
p=0
hoge=np.inf
for i in range(1,np.max(x)+1):
    sux=sum((x-i)**2)
    if sux<hoge:
        p=i
        hoge=sux
print(hoge)

Fixed code:
import numpy as np
n=int(input())
x=np.fromstring(input(),int,sep=' ')
p=0
hoge=np.inf
for i in range(1,np.max(x)+1):
    sux=sum((x-i)**2)
    if sux<hoge:
        p=i
        hoge=sux
print(hoge)
Buggy code:
n = int(input())
X = list(map(int, input().split()))
ans = 0

for i in range(1,101):
  tmp = 0
  for x in X:
    if i == 1:
      ans += (i - x)**2
    else:
      tmp += (i - x)**2
      if tmp < ans:
        ans = tmp
    
print(ans)

Fixed code:
n = int(input())
xl = list(map(int, input().split()))
ans = 0
for x in xl:
  ans += (x-1)**2

for i in range(2, 101):
  tmp = 0
  for x in xl:
    tmp += (x-i)**2
  if tmp < ans:
    ans = tmp

print(ans)
Buggy code:
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))
best_score = None
for i in range(np.min(X), np.max(X)+1):
    score = np.sum(np.power(X - i, 2))
    if best_score is None:
        best_score = score
    elif best_score > score:
        best_score = score

Fixed code:
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))
best_score = None
for i in range(np.min(X), np.max(X)+1):
    score = np.sum(np.power(X - i, 2))
    if best_score is None:
        best_score = score
    elif best_score > score:
        best_score = score
print(best_score)
Buggy code:
n = int(input())
x = list(map(int, input().split()))
xmin = min(x)
xmax = max(x)
hp = 10e10
for p in range(xmin, xmax+1):
    temp = 0
    for xi in x:
        temp += (xi-p)*(xi-p)
    hp = min(temp,)
print(hp)

Fixed code:
n = int(input())
x = list(map(int, input().split()))
xmin = min(x)
xmax = max(x)
hp = 10e10
for p in range(xmin, xmax+1):
    temp = 0
    for xi in x:
        temp += (xi-p)*(xi-p)
    hp = min(temp, hp)
print(hp)
Buggy code:
N = int(input())
Xs = list(map(int,input().split()))
ans = 0
ansCandidate = 0
for j in range(min(Xs),max(Xs)):
    ansCandidate = 0
    for i in range(N):
        ansCandidate += (Xs[i] - j)**2
    print(ansCandidate)
    if j == min(Xs):
        ans = ansCandidate
    ans = min(ans,ansCandidate)
print(ans)


Fixed code:
N = int(input())
Xs = list(map(int,input().split()))
ans = 0
ansCandidate = 0
for j in range(min(Xs),max(Xs)):
    ansCandidate = 0
    for i in range(N):
        ansCandidate += (Xs[i] - j)**2
    if j == min(Xs):
        ans = ansCandidate
    ans = min(ans,ansCandidate)
print(ans)
Buggy code:
import math

N = int(input())
xs = [int(i) for i in input().split()]
p = sum(xs) / len(xs)

print(sum([math.pow(x-p, 2) for x in xs]))

Fixed code:
import math

N = input()
xs = [int(i) for i in input().split()]
p = round(sum(xs)/len(xs))

print(int(sum(math.pow(x-p, 2) for x in xs)))
Buggy code:
n=int(input())
l=list(map(int,input().split()))
su=0
for i in range(n):
  su+=l[i]
su=su//n
ans=0
for i in range(n):
  ans+=(l[i]-su)**2
print(ans)

Fixed code:
n=int(input())
l=list(map(int,input().split()))
su=0
for i in range(n):
  su+=l[i]
su=round(su/n)
ans=0
for i in range(n):
  ans+=(l[i]-su)**2
print(ans)
Buggy code:
n = int(input())
X = list(map(int,input().split)())
ans = 10**100
for i in range(1,101):
  count = 0
  for j in X:
    count += (i-j)*2
  ans = min(ans,count)
print(ans)

Fixed code:
n = int(input())
X = list(map(int,input().split()))
ans = 10**100
for i in range(1,101):
  count = 0
  for j in X:
    count += (i-j)**2
  ans = min(ans,count)
print(ans)
Buggy code:
n = int(input())
xs = [int(elem) for elem in input().split()]

min_ = min(xs)
max_ = max(xs)
result = []
for p in range(min_, max_+1):
  print(p)
  res = 0
  for x in xs:
    res += (x - p) ** 2
  result.append(res)
print(min(result))

Fixed code:
n = int(input())
xs = [int(elem) for elem in input().split()]
 
min_ = min(xs)
max_ = max(xs)
result = []
for p in range(min_, max_+1):
  res = 0
  for x in xs:
    res += (x - p) ** 2
  result.append(res)
print(min(result))
Buggy code:
n=int(input())
x=list(map(int,input().split()))
a=sum(x)//n
ans=0
anss=0
for i in x:
  ans=ans+(i-a)**2
a=a+1
for i in x:
  anss=anss+(i-a)**2
if anss < ans:
  ans=anss
print(ans,a)

Fixed code:
n=int(input())
x=list(map(int,input().split()))
a=sum(x)//n
ans=0
anss=0
for i in x:
  ans=ans+(i-a)**2
a=a+1
for i in x:
  anss=anss+(i-a)**2
if anss < ans:
  ans=anss
print(ans)
Buggy code:
n=int(input())
x=list(map(int,input().split()))
x.sort()
ans=float("Inf")
for i in range(x[0],x[n-1]+1):
  print(i)
  cal=0
  for j in range(0,n):
    cal=cal+(x[j]-temp)**2
  ans=min(ans,cal)
print(ans)

Fixed code:
n=int(input())
x=list(map(int,input().split()))
x.sort()
ans=float("Inf")
for i in range(x[0],x[n-1]+1):
  temp=i
  cal=0
  for j in range(0,n):
    cal=cal+(x[j]-temp)**2
  ans=min(ans,cal)
print(ans)
Buggy code:
N=int(input())
X=list(map(int,input().split()))
A=sum(X)
y=N*((round(A/N)-A/N)**2)-(A**2)/N
B=sum([i**2 for i in X])
print(y+B)

Fixed code:
N=int(input())
X=list(map(int,input().split()))
A=sum(X)
y=N*((round(A/N)-A/N)**2)-(A**2)/N
B=sum([i**2 for i in X])
print(int(y+B))
Buggy code:
# -*- coding: utf-8 -*-
n = int(input())
x = list(map(int, input().split()))

left = min(x)
right = max(x)

min_cost = 100000000000000
min_pos=-1

for i in range(left,right+1):
  cost=0
  for j in range(n):
    cost = cost + (x[j]-i)*(x[j]-i)
  if min_cost>cost:
    min_cost=cost
    min_pos=i

print(min_pos)

Fixed code:
# -*- coding: utf-8 -*-
n = int(input())
x = list(map(int, input().split()))

left = min(x)
right = max(x)

min_cost = 100000000000000
min_pos=-1

for i in range(left,right+1):
  cost=0
  for j in range(n):
    cost = cost + (x[j]-i)*(x[j]-i)
  if min_cost>cost:
    min_cost=cost
    min_pos=i

print(min_cost)
Buggy code:
N = int(input())
X = list(map(int, input().split(' ')))

s = 0
for xi in X:
    s += xi
si = round(s / N)
ps = 0
for xi in X:
    ps += int(math.pow(xi-si, 2))
print(ps)

Fixed code:
import math
N = int(input())
X = list(map(int, input().split(' ')))

s = 0
for xi in X:
    s += xi
si = round(s / N)
ps = 0
for xi in X:
    ps += int(math.pow(xi-si, 2))
print(ps)
Buggy code:
N=number=int(input())
X_list=list(map(int, input().split()))

X_min=min(X_list)
X_max=max(X_list)
for i in range(X_min,X_max):
    sum_pow=0
    for j in range(1,N):
        sum_pow+=(X_list[j]-i)**2
    if i==X_min:
        min_pow=sum_pow
    if min_pow>sum_pow:
        min_pow=sum_pow
print(min_pow)

Fixed code:
N=number=int(input())
X_list=list(map(int, input().split()))
min_pow=0
if N==1:
    print("0")
else:
    X_min=min(X_list)
    X_max=max(X_list)
    for i in range(X_min,X_max):
        sum_pow=0
        for j in range(N):
            sum_pow+=(X_list[j]-i)**2
        if i==X_min:
            min_pow=sum_pow
        if min_pow>sum_pow:
            min_pow=sum_pow
    print(min_pow)
Buggy code:
N = int(input())
X = list(map(int,input().split()))
tmp = 0
mi =100000000000
for i in range(1,101):
  for k in range(N):
    tmp = (X[k] - i)**2
  if tmp < mi:
    mi = tmp
print(mi)

Fixed code:
N = int(input())
X = list(map(int,input().split()))
tmp = 0
mi =100000000000
for i in range(1,101):
  for k in range(N):
    tmp += (X[k] - i)**2
  if tmp < mi:
    mi = tmp
  tmp = 0
print(mi)
Buggy code:
import numpy as np

N=int(input())
X=np.zeros(N)
X=list(map(int,input().split()))

print(np.mean(X))
print(int(np.mean(X)))
if np.mean(X)-int(np.mean(X))>=0.5:
    count=int(np.mean(X))+1
else:
    count=int(np.mean(X))    

result=0
for i in range(N):
    result+=(X[i]-count)*(X[i]-count)
print(result)

Fixed code:
import numpy as np

N=int(input())
X=np.zeros(N)
X=list(map(int,input().split()))

if np.mean(X)-int(np.mean(X))>=0.5:
    count=int(np.mean(X))+1
else:
    count=int(np.mean(X))    

result=0
for i in range(N):
    result+=(X[i]-count)*(X[i]-count)
print(result)
Buggy code:
import statistics

N = int(input())
X = [int(i) for i in input().split()]
X.sort()
mid = statistics.mean(X)
ans = 0
ans1 = 0
ans2 = 0
print(mid)
for i in range(N):
    ans1 += (X[i] - int(mid)) ** 2
    ans2 += (X[i] - int(mid) - 1) ** 2
ans = min(ans1, ans2)

print(ans)

Fixed code:
import statistics

N = int(input())
X = [int(i) for i in input().split()]
X.sort()
mid = statistics.mean(X)
ans = 0
ans1 = 0
ans2 = 0

for i in range(N):
    ans1 += (X[i] - int(mid)) ** 2
    ans2 += (X[i] - int(mid) - 1) ** 2
ans = min(ans1, ans2)

print(ans)
Buggy code:
N=int(input())
X=list(map(int,input().split()))
E=[]
e=0
for i in range(min(X),max(X)+1):
    for j in range(len(X)):
        e+=(X[j]-i)**2
    E.append(e)
    e=0
print(E)
print(min(E))
        

Fixed code:
N=int(input())
X=list(map(int,input().split()))
E=[]
e=0
for i in range(min(X),max(X)+1):
    for j in range(len(X)):
        e+=(X[j]-i)**2
    E.append(e)
    e=0
print(min(E))
Buggy code:
N=int(input())
X_list=map(int,input().split(" "))

def kyori(x,y):
    return (x-y)**2

ave=sum(X_list)//N
av2=ave+1
print(min([sum([kyori(x,ave) for x in X_list]),sum([kyori(x,av2) for x in X_list])]))



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

def kyori(x,y):
    return (x-y)**2

ave=sum(X_list)//N
av2=ave+1
c1=sum([kyori(x,ave) for x in X_list])
c2=sum([kyori(x,av2) for x in X_list])
print(min([c1,c2]))
Buggy code:
n = int(input())
X = list(int(x)for x in input().split())
ams = []
for p in range(min(X),max(X)):
  total = 0
  for x in X:
    total += (x-p)**2
  ans.append(total)
print(min(ans))

Fixed code:
n = int(input())
X = list(int(x)for x in input().split())
ans = []
for p in range(min(X),max(X)+1):
  total = 0 
  for x in X:
    total += (x-p)**2
  ans.append(total)
print(min(ans))
Buggy code:
n = int(input())
x = list(map(int, input().split())

res = 0
r = round(sum(x)/len(x))
for i in x:
    res +=(i-p)**2
print(res)

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

res = 0

r = round(sum(x)/len(x))
for i in x:
    res += (i-r)**2
print(res)
Buggy code:
n = int(input())
xxx = list(map(int, input().split()))
ans = 0
for p in range(1, 101):
    tmp = sum((x - p) ** 2 for x in xxx)
    ans = min(ans, tmp)
print(ans)


Fixed code:
n = int(input())
xxx = list(map(int, input().split()))
ans = 10**10
for p in range(1, 101):
    tmp = sum((x - p) ** 2 for x in xxx)
    ans = min(ans, tmp)
print(ans)
Buggy code:
N = int(input())
X = list(map(int, input().split())

def D(X,a):
	ans = 0
	for i in range(len(a)):
		ans += (x - a[i])**2
	return ans

for i in range(0,101):
	if D(i,X) < D(i+1,X):
		print(D(i,X))
		break

Fixed code:
N=int(input())
X=list(map(int,input().split()))
def D(x,a):
	ans=0
	for i in range(len(a)):
		ans+=(x-a[i])**2
	return ans
for i in range(0,101):
	if D(i,X)<D(i+1,X):
		print(D(i,X))
		break
Buggy code:
N = int(input())
X = list(map(int, input().split()))

ans = []
count = 0

for i in range(1,N+1):
    number = 0
    count = 0
    for j in X:
        number = number + ((j-i)**2)
        count = count + 1
        if N == count:
            ans.append(number)

print(ans)

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

ans = []
count = 0

for i in range(0,101):
    number = 0
    count = 0
    for j in X:
        number = number + ((j-i)**2)
        count = count + 1
        if N == count:
            ans.append(number)

print(min(ans))
Buggy code:
n = int(input())
x = list(map(int,input().split()))
min_energy = 250000
for i range(0,101):
  energy = 0
  for k range(n):
    energy += (x[k]-1)**2
  if energy < min_energy:
    min_energy = energy
print(min_energy)


Fixed code:
n = int(input())
x = list(map(int,input().split()))
m_energy = 250000
for i in range(1,101):
  energy = 0
  for k in range(n):
    energy += (x[k]-i)**2
  if energy < m_energy:
    m_energy = energy
print(m_energy)
Buggy code:
import statistics
n=int(input())
x=[int(_) for _ in input().split()]
mid=int(statistics.mean(x))
mmid=mid-1
cnt=0
cntm=0
for i in range(len(x)):
  cnt+= (x[i]-mid)**2
  cntm+=(x[i]-mmid)**2
print(min(cnt,cntm,cntp))
  

Fixed code:
import statistics
n=int(input())
x=[int(_) for _ in input().split()]
mid=int(statistics.mean(x))
mmid=mid-1
pmid=mid+1
cnt=0
cntm=0
cntp=0
for i in range(len(x)):
  cnt+= (x[i]-mid)**2
  cntm+=(x[i]-mmid)**2
  cntp+=(x[i]-pmid)**2
print(min(cnt,cntm,cntp))
Buggy code:
n = int(input())
x = list(map(int,input.split()))

ans = 100000

for i in range(100):
    result = 0
    for j in x:
        result += (j - i )**2
    ans = min(result, ans)
        
print(ans)


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

ans = 10000000

for i in range(100):
    result = 0
    for j in x:
        result += (j - i )**2
    ans = min(result, ans)
        
print(ans)
Buggy code:
import sys
input = sys.stdin.readline

N = int(input())
X = [int(x) for x in input().split()]
P = int(sum(X)/N)
total = 0
for x in X:
  kyori = (x - P) * (x - P)
  total += kyori
print(total)

Fixed code:
import sys
input = sys.stdin.readline

N = int(input())
X = [int(x) for x in input().split()]
P = int(sum(X) / N + 0.5)
total = 0
for x in X:
  kyori = (x - P) * (x - P)
  total += kyori
print(total)
Buggy code:
N=int(input())
people=[]
cost=[]
 
people=list(map(int,input().split()))

for p in range(len(people)):
    cost.append(0)
    for person in people:
      cost[-1]+=(person-(p+1))**2
print(min(cost))

Fixed code:
N=int(input())
people=[]
cost=[]
 
people=list(map(int,input().split()))

for p in range(101):
    cost.append(0)
    for person in people:
      cost[-1]+=(person-(p+1))**2

print(min(cost))
Buggy code:
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def calc_sum_of_power(N, coord):
    spot = round(sum(coord)/N)
    return sum([(x - spot)**2 for x in coord])

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

if __name__ == "__main__":
    try:
        assert calc_sum_of_power(2, [1, 4]) == 5
        assert calc_sum_of_power(7, [14, 14, 2, 13, 56, 2, 37]) == 2354
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()


Fixed code:
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def calc_sum_of_power(N, coord):
    spot = round(sum(coord)/N)
    return sum([(x - spot)**2 for x in coord])

def main():
    N = int(input())
    coord = list(map(int, input().split()))
    print(calc_sum_of_power(N, coord))

if __name__ == "__main__":
    try:
        assert calc_sum_of_power(2, [1, 4]) == 5
        assert calc_sum_of_power(7, [14, 14, 2, 13, 56, 2, 37]) == 2354
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()
Buggy code:
import sys
import math
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
x = sum(a) // n
ans = 0
for i in a:
    ans += (i - x) * (i - x)
print(ans)

Fixed code:
import sys
import math
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
x = sum(a) // n
ans = 0
for i in a:
    ans += (i - x) * (i - x)
x = math.ceil(sum(a) / n)
ans2 = 0
for i in a:
    ans2 += (i - x) * (i - x)
print(min(ans, ans2))