qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n = int(stdin.readline().rstrip())
x = [int(x) for x in stdin.readline().rstrip().split()]

p = int(sum(x)/n)
q = p+1

a = sum([(i-p)**2 for i in x])
b = sum([(i-q)**2 for i in x])

print(p,q,a,b)

print(min([a,b]))


Fixed code:
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n = int(stdin.readline().rstrip())
x = [int(x) for x in stdin.readline().rstrip().split()]

p = int(sum(x)/n)
q = p+1

a = sum([(i-p)**2 for i in x])
b = sum([(i-q)**2 for i in x])

print(min([a,b]))
Buggy code:
N = int(input())
X = list(map(int, input().split()))

hp_sums = []

for i in range(max(X)):
    P = i+1
    distance_list = list(map(lambda x: (x-P)**2, X))
    print(distance_list)
    hp_sum = sum(distance_list)
    hp_sums.append(hp_sum)

print(min(hp_sums))

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

hp_sums = []

for i in range(max(X)):
    P = i+1
    distance_list = list(map(lambda x: (x-P)**2, X))
    hp_sum = sum(distance_list)
    hp_sums.append(hp_sum)

print(min(hp_sums))
Buggy code:
def atcoder2():
    a = [list(map(int,input().split())) for l in range(2)]

    n= a[0][0]
    x_l = a[1]

    P = sum(x_l)/n

    print(a,n)
    print(P)
    if P - int(P) >= 0.5:
        add= 1
    else:
        add = 0

    P = int(P)+add
    
    print(P)

    result = 0
    for Xi in x_l:
        result = result + (Xi-P)**2 

    print(result)
    return 


atcoder2()

Fixed code:

def atcoder2():
    a = [list(map(int,input().split())) for l in range(2)]

    n= a[0][0]
    x_l = a[1]

    P = sum(x_l)/n

    # print(a,n)
    # print(P)
    if P - int(P) >= 0.5:
        add= 1
    else:
        add = 0

    P = int(P)+add
    
    # print(P)

    result = 0
    for Xi in x_l:
        result = result + (Xi-P)**2 

    print(result)
    return 


atcoder2()
Buggy code:
import numpy as np

def calc(X, p):
  ans = 0
  for x in X:
    ans += (x-p)**2   
  print(ans)
  
n = int(input())
X = list(map(int, input().split()))

p = np.mean(X)
p1 = np.floor(p)
p2 = np.ceil(p)

if p <= p1 + 0.5:
  calc(X, p1)
else:
  calc(X, p2)

Fixed code:
import numpy as np

def calc(X, p):
  ans = 0
  for x in X:
    ans += (x-p)**2   
  print(int(ans))
  
n = int(input())
X = list(map(int, input().split()))

p = np.mean(X)
p1 = np.floor(p)
p2 = np.ceil(p)

if p <= p1 + 0.5:
  calc(X, p1)
else:
  calc(X, p2)
Buggy code:
N = int(input())
xlist = list(map(int, input().split()))
p = sum(xlist) // N
s = 0
for x in xlist:
    s += (x-p)**2
print(s)

Fixed code:
N = int(input())
xlist = list(map(int, input().split()))
p = round(sum(xlist) / N)
s = 0
for x in xlist:
    s += (x-p)**2
print(s)
Buggy code:
n = int(input())
temp = [int(s) for s in input().split()]
rarry = 0
min = 100000007
min_temp = 0
print(max(temp))
for n_ in range(max(temp) + 1):
    for i in temp:
        min_temp += ((i - n_) ** 2)
    #print(min_temp)
    if(min > min_temp):
        min = min_temp
    min_temp = 0


print("{}".format(str(min)))

Fixed code:
n = int(input())
temp = [int(s) for s in input().split()]
rarry = 0
min = 100000007
min_temp = 0
for n_ in range(100):
    for i in temp:
        min_temp += ((i - n_) ** 2)
    #print(min_temp)
    if(min > min_temp):
        min = min_temp
    min_temp = 0


print("{}".format(str(min)))
Buggy code:
n = int(input())
x = list( map(int,input().split()) )

print(max(x),min(x))

min_hp = 1000000000000000
for p in range(min(x),max(x)+1):
    hp = 0
    for i in x:
        hp +=(i-p)**2
        # print(p,i,hp)
    if min_hp > hp:
        min_hp = hp

print(min_hp)

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

#print(max(x),min(x))

min_hp = 1000000000000000
for p in range(min(x),max(x)+1):
    hp = 0
    for i in x:
        hp +=(i-p)**2
        # print(p,i,hp)
    if min_hp > hp:
        min_hp = hp

print(min_hp)
Buggy code:
n = input()
s = map(int,input().split())
m = 10000000
for p in range(0,101):
  t = 0
  for x in s:
    t+=(x-p)**2
  m = min(t,m)
print(m)

Fixed code:
n = input()
s = list(map(int,input().split()))
m = 10000000
for p in range(0,101):
  t = 0
  for x in s:
    t+=(x-p)**2
  m = min(t,m)
print(m)
Buggy code:
import math
N = int(input())
X = list(map(int,input().split()))

A = math.ceil(sum(X)/N)
B = math.floor(sum(X)/N)

a = 0
b = 0

for i in X:
  a += (i-A)**2
  
for _ in X:
  b += (i-B)**2
  
print(min(a,b))

  
  
  




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

A = math.ceil(sum(X)/N)
B = math.floor(sum(X)/N)

a = 0
b = 0

for i in X:
  a += (i-A)**2
  
for _ in X:
  b += (_-B)**2
  
print(min(a,b))
Buggy code:
n = int(input())
index = list(map(int, input().split()))
energy = []
for p in range(1, n+1):
    sum = 0
    for xi in index:
        sum += (xi-p)**2
    energy.append(sum)
print(min(energy))

Fixed code:
n = int(input())
index = list(map(int, input().split()))
energy = []
for p in range(min(index), max(index)+1):
    sum = 0
    for xi in index:
        sum += (xi-p)**2
    energy.append(sum)
print(min(energy))
Buggy code:
#156_c
n = int(input())
x_lis = [int(x) for x in input().split()]
 

s = []
for pos in range(min(x_lis),max(x_lis)+1):

    tir = []
    for x in x_lis:
        tir.append((x - pos)**2)
    s.append(sum(tir))
print(s)
        

print(min(s))

Fixed code:
#156_c
n = int(input())
x_lis = [int(x) for x in input().split()]
 

s = []
for pos in range(min(x_lis),max(x_lis)+1):

    tir = []
    for x in x_lis:
        tir.append((x - pos)**2)
    s.append(sum(tir))
        

print(min(s))
Buggy code:
N = int(input())
in = list(map(int, input.split()))

P = round(sum(in)/N)

sum = 0
for i in range(N):
  sum += (in[i] - P)**2
  
print(sum)

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

P = round(sum(numbers)/N)

sum = 0
for i in range(N):
  sum += (numbers[i] - P)**2

print(sum)
Buggy code:
n = int(input())
x = list(map(int,input().split()))
j = max(x)
m = 0
y = True

for p in range(n):
    if x[0] != x[i]:
        y = False

if y:
    print(0)
    exit(0)

for p in range(j):
    c = 0
    z = 0
    for i in range(n):
        z = x[i] - p
        c = c + (z * z)
    
    if m == 0:
        m = c
    else:
        if m > c:
            m = c

print(m)

Fixed code:
n = int(input())
x = list(map(int,input().split()))
j = max(x)
m = 0
y = True

for i in range(n):
    if x[0] != x[i]:
        y = False

if y:
    print(0)
    exit(0)

for p in range(j):
    c = 0
    z = 0
    for i in range(n):
        z = x[i] - p
        c = c + (z * z)
    
    if m == 0:
        m = c
    else:
        if m > c:
            m = c

print(m)
Buggy code:
n = int(input())
x_lis = list(map(int, input().split()))
ans = 0
avg = sum(x_lis)/n
if avg - int(avg) >= 0.5:
    avg = int(avg) + 1
else:
    avg = int(avg)
print(avg)
for x in x_lis:
    ans += (x - avg)**2
print(ans)

Fixed code:
n = int(input())
x_lis = list(map(int, input().split()))
ans = 0
avg = sum(x_lis)/n
if avg - int(avg) >= 0.5:
    avg = int(avg) + 1
else:
    avg = int(avg)
for x in x_lis:
    ans += (x - avg)**2
print(ans)
Buggy code:
n = int(input())
x_list = list(map(int, input().split()))
ans_list = [sum([(x - p) ** 2 for x in x_list]) for p in range(min(x_list), max(x_list)) + 1]
print(sorted(ans_list)[0])

Fixed code:
n = int(input())
x_list = list(map(int, input().split()))
ans_list = [sum([(x - p) ** 2 for x in x_list]) for p in range(min(x_list), max(x_list) + 1)]
print(sorted(ans_list)[0])
Buggy code:
N=int,input()
X=list(map(int,input().split()))
def P(n):
    return sum([(X[i]-n)**2 for i in range(0,N)])
l=[P(i) for i in range(1,101)]
print(min(l))


Fixed code:
N=int(input())
X=list(map(int,input().split()))
def P(n):
    return sum([(X[i]-n)**2 for i in range(0,N)])
l=[P(i) for i in range(1,101)]
print(min(l))
Buggy code:
    x.append(int(input()))N = int(input())
x = []
hp = []
xa = 0
hpsum = 0

x = [int(e) for e in input().split()]
for i in range(N):
    xa += x[i]



xa = xa / N

if xa % 1 < 0.5:
    xa = int(xa / 1)
elif xa % 1 >= 0.5:
    xa = int(xa / 1 + 1)

for j in range(N):
    hp.append((x[j]-xa)*(x[j]-xa))
    hpsum += hp[j]

print(int(hpsum))

Fixed code:
N = int(input())
x = []
hp = []
xa = 0
hpsum = 0

x = [int(e) for e in input().split()]
for i in range(N):
    xa += x[i]



xa = xa / N

if xa % 1 < 0.5:
    xa = int(xa / 1)
elif xa % 1 >= 0.5:
    xa = int(xa / 1 + 1)

for j in range(N):
    hp.append((x[j]-xa)*(x[j]-xa))
    hpsum += hp[j]

print(int(hpsum))
Buggy code:
def rally(n, x):
    if not len(x) == n:
        return "==== pleas input based on n times in one line ===="
    else:
        new_list = []
        for i in x:
            r = (i - n)**2
            new_list.append(r)
        return sum(new_list)
n = int(input())
x = list(map(int, input().split())) #input based on n
print(rally(n, x))

Fixed code:
def rally(n, x):
    if not len(x) == n:
        return "==== pleas input based on n times in one line ===="
    else:
        mini = round(sum(x)/n)
        new_list = []
        for i in x:
            r = (i - mini)**2
            new_list.append(r)
        return (sum(new_list))


n = int(input())
x = list(map(int, input().split())) #input based on n
print(rally(n, x))
Buggy code:
N = int(input())
X = list(map(int, input().split()))

mid = round(sum(X) / 7)
hoge = 0
for i in X:
    hoge += (i - mid)** 2
    
print(hoge)

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

mid = round(sum(X) / N)
hoge = 0
for i in X:
    hoge += (i - mid)** 2
    
print(hoge)
Buggy code:
N = int(input())
A = list(map(int, input().split()))

average = sum(A) // N
ans1 = 0
for i in A:
    ans1 += (i-average)**2
ans2 = 0
for i in A:
    ans2 += (i-average)**2
ans = min(ans1, ans2)

print(ans)


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

average = sum(A) // N
ans1 = 0
for i in A:
    ans1 += (i-average)**2
ans2 = 0
for i in A:
    ans2 += (i-average-1)**2
ans = min(ans1, ans2)

print(ans)
Buggy code:
n = int(input())
x = list(map(int,input().split()))
ans = 100000000
for p in x:
    hp = 0
    for i in range(n):
        hp += (x[i] - p)**2
    ans = min(ans,hp)

print(ans)


Fixed code:
n = int(input())
x = list(map(int,input().split()))
ans = 100000000
for p in range(101):
    hp = 0
    for i in range(n):
        hp += (x[i] - p)**2
    ans = min(ans,hp)

print(ans)
Buggy code:
N= int(input())
X = list(map(int, input().split()))
mean = X.sum()/N
ans = 0 
for i in range(N):
  ans += (X[i] - mean)**2
  
print(ans)




Fixed code:
N= int(input())
X = list(map(int, input().split()))
mean = round(sum(X)/N)
ans = 0 
for i in range(N):
  ans += (X[i] - mean)**2
  
print(ans)
Buggy code:
N = int(input())
X = list(map(int,input().split()))
ans = []

for i in range(min(X),max(X)+1):
    ans.append(cnt)
    cnt = 0
    for j in X:
        cnt += (j-i)**2
    #ans.append(cnt)
        
print(min(ans))            
        

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

for i in range(min(X),max(X)+1):
    cnt = 0
    for j in X:
        cnt += (j-i)**2
    ans.append(cnt)
        
print(min(ans))
Buggy code:
# coding: utf-8
 
a = int(input())
b=list(map(int,input().split()))
sum = 0

for i in range(a):
    sum += b[i]


ans_pre = sum/a
ans = round(ans_pre)

print(ans)

Fixed code:
# coding: utf-8
 
a = int(input())
b=list(map(int,input().split()))
sum = 0
 
for i in range(a):
    sum += b[i]
  
ans_pre = sum/a
ans = round(ans_pre)

sum = 0 

for i in range(a):
    sum += (b[i]-ans)**2

print(sum)
Buggy code:
n = int(input())
x = list(map(int, input().split()))
ans = 10 ** 9
for p in range(1, n+1):
    cnt = 0
    for i in x:
        cnt += (i-p)**2
    ans = min(ans, cnt)
print(ans)

Fixed code:
n = int(input())
x = list(map(int, input().split()))
ans = 10 ** 9
for p in range(0, 101):
    cnt = 0
    for i in x:
        cnt += (i-p)**2
    ans = min(ans, cnt)
print(ans)
Buggy code:
N = input()
X = list( map(int, input().split()))
X.sort()

min_a = X[0]
max_a = X[-1]
mid = (min + max) // 2

sum_min = 0
sum_max = 0
    
def calc(x, min, max):
    mid = (min + max) // 2
    sum_min = 0
    sum_max = 0
    for value in x:
        sum_min += (value - min) ** 2
        sum_max += (value - max) ** 2
    
    if abs(min - max) <= 1:
        if sum_min < sum_max:
            return int(sum_min)
        else:
            return int(sum_max)
    elif sum_min < sum_max:
        return calc(x, min, mid)
    else:
        return calc(x, mid, max)
    
    return -1
    
ans = calc(X, min_a, max_a)
print(ans)

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

min_a = X[0]
max_a = X[-1]

sum_min = 0
sum_max = 0
    
def calc(x, min, max):
    mid = (min + max) // 2
    sum_min = 0
    sum_max = 0
    for value in x:
        sum_min += (value - min) ** 2
        sum_max += (value - max) ** 2
    
    if abs(min - max) <= 1:
        if sum_min < sum_max:
            return int(sum_min)
        else:
            return int(sum_max)
    elif sum_min < sum_max:
        return calc(x, min, mid)
    else:
        return calc(x, mid, max)
    
    return -1
    
ans = calc(X, min_a, max_a)
print(ans)
Buggy code:
import numpy as np

def main(n, xs):
    minx = min(xs)
    maxx = max(xs)
    ress = []

    for x in range(minx, maxx+1):
        res = sum((xs - x) ** 2)
        ress.append(res)

    res = min(ress)
    return res

if __name__ == "__main__":
    cin = input()
    n = int(cin.split(" ")[0])
    cin = input()
    xs = np.array([], dtype="int")

    for i in range(n):
        xs = np.append(xs, int(cin.split(" ")[i]))
    print(xs)
    cout = main(n, xs)
    print(cout)

Fixed code:
import numpy as np

def main(n, xs):
    minx = min(xs)
    maxx = max(xs)
    ress = []

    for x in range(minx, maxx+1):
        res = sum((xs - x) ** 2)
        ress.append(res)

    res = min(ress)
    return res

if __name__ == "__main__":
    cin = input()
    n = int(cin.split(" ")[0])
    cin = input()
    xs = np.array([], dtype="int")

    for i in range(n):
        xs = np.append(xs, int(cin.split(" ")[i]))
    cout = main(n, xs)
    print(cout)
Buggy code:
# Initializing variables
people = int(input())
coordinates = list(map(int, input().split()))
max_ = max(coordinates)
min_ = min(coordinates)
ans = 0

# Calculating the minimum total of stamina
for i in range(min_, max_ + 1):
    currentMin = 0
    for j in range(people):
        currentMin += (coordinates[j] - i) ** 2
        print("coordinates[j]: " + str(coordinates[j]))
        print("J loop currentMin: " + str(currentMin))
        print("J: " + str(j))
        print("i in J loop:" + str(i))
        print()
    print("CurrentMin: " + str(currentMin))
    if i == min_:
        ans = currentMin
        print("if i == min_: " + str(ans))
        print()
    elif currentMin < ans:
        ans = currentMin
        print("elif currentMin < ans: " + str(ans))
        print()

print(ans)

# Check out my Youtube channel! https://www.youtube.com/channel/UCMOKVyAbTZOpKikTrX5dy_A



Fixed code:
# Initializing variables
people = int(input())
coordinates = list(map(int, input().split()))
max_ = max(coordinates)
min_ = min(coordinates)
ans = 0

# Calculating the minimum total of stamina
for i in range(min_, max_ + 1):
    currentMin = 0
    for j in range(people):
        currentMin += (coordinates[j] - i) ** 2
    if i == min_:
        ans = currentMin
    elif currentMin < ans:
        ans = currentMin
        
print(ans)

# Check out my Youtube channel! https://www.youtube.com/channel/UCMOKVyAbTZOpKikTrX5dy_A
Buggy code:
n = int(input())
x = list(map(int, input().split()))

l = min(x)
r = max(x)
ans = 100 ** 3
for i in range(l, r + 1):
    vit = sum(abs(xi - i) ** 2 for xi in x)
    print(i, vit)
    ans = min(ans, vit)
print(ans)


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

l = min(x)
r = max(x)
ans = 100 ** 3
for i in range(l, r + 1):
    vit = sum(abs(xi - i) ** 2 for xi in x)
    ans = min(ans, vit)
print(ans)
Buggy code:
from decimal import Decimal, ROUND_HALF_UP
N = int(input())
X = [int(i) for i in input().split()]

ans = 0
X_mean = Decimal(str(sum(X) / N))
X_mean = X_mean.quantize(Decimal('0'), rounding=ROUND_HALF_UP)
print(X_mean)

for i in range(N):
    ans += (X[i] - X_mean) ** 2

print(ans)


Fixed code:
from decimal import Decimal, ROUND_HALF_UP

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

ans = 0
X_mean = Decimal(str(sum(X) / N))
X_mean = X_mean.quantize(Decimal('0'), rounding=ROUND_HALF_UP)

for i in range(N):
    ans += (X[i] - X_mean) ** 2

print(ans)
Buggy code:
x = list(map(int,input().split()))
ans = []
if len(set(x)) == 1:
    print(0)
else: 
    for p in range(min(x), max(x)):
        meter = 0
        for xi in x:
            meter += pow((xi-p),2)
        ans.append(meter)
    print(min(ans))

Fixed code:
n = int(input())
x = list(map(int,input().split()))
ans = []
if len(set(x)) == 1:
    print(0)
else: 
    for p in range(min(x), max(x)):
        meter = 0
        for xi in x:
            meter += pow((xi-p),2)
        ans.append(meter)
    print(min(ans))
Buggy code:
import math

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

s = sum(x)

ans = 0
a = round(s/n)

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

print(a)
print(ans)

Fixed code:
import math

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

s = sum(x)

ans = 0
a = round(s/n)

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

print(ans)
Buggy code:
#2
N = int(input())
an = list(map(int,input().split()))
Min = 10**10

for i in range(1,102):
    k = 0
    for j in an:
        k += (j-i)**2
    print(k)
    if Min >k:
        Min = k
        
print(Min)
        

Fixed code:
#2
N = int(input())
an = list(map(int,input().split()))
Min = 10**10

for i in range(1,102):
    k = 0
    for j in an:
        k += (j-i)**2
    if Min >k:
        Min = k
        
print(Min)
Buggy code:
def ans(p, x):
    a = 0
    for i in x:
        a += (i - p)**2
    return a

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

p = sum(x)//n

print(min(ans(p), ans(p+1)))


Fixed code:
def ans(p, x):
    a = 0
    for i in x:
        a += (i - p)**2
    return a

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

p = sum(x)//n

print(min(ans(p, x), ans(p+1, x)))
Buggy code:
N = int(input())

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

max_x = max(x_list)
min_x = min(x_list)

each_value_list = []
min_value = 10e1000
for i in range(min_x, max_x + 1):
    print(i)
    tmp_sum = 0
    for x in x_list:
        tmp_sum += (x - i)**2
    if min_value > tmp_sum:
        min_value = tmp_sum

print(min_value)

Fixed code:
N = int(input())

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

max_x = max(x_list)
min_x = min(x_list)

each_value_list = []
min_value = 10e1000
for i in range(min_x, max_x + 1):
    tmp_sum = 0
    for x in x_list:
        tmp_sum += (x - i)**2
    if min_value > tmp_sum:
        min_value = tmp_sum

print(min_value)
Buggy code:
n = int(input())
x = list(map(int, input().split()))
x.sort()
sigmaList = list()
for p in range(x[0], x[n]):
    sigma = 0
    for i in range(n):
        sigma += (x[i] - p) ** 2
    sigmaList.append(sigma)

print(min(sigmaList))


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

min = 0
result = 0
for i in range(N):
    for j in X:
        print(j)
        result += (i + 1 - j) ** 2
    if min > result:
        min = result
    if min == 0:
        min = result
    result = 0

print(min)

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

min = 1000000
result = 0
for i in range(100):
    for j in X:
        result += (i + 1 - j) ** 2
    if min > result:
        min = result
    result = 0

print(min)
Buggy code:
import numpy as np

def resolve():
    input()
    x = list(map(int, input().split()))
    m = round(np.median(x))
    sum = 0
    for val in x:
        sum += (val - m) ** 2
    print(sum)

if __name__ == '__main__':
    resolve()

Fixed code:
import numpy as np

def resolve():
    input()
    x = list(map(int, input().split()))
    m = int(round(np.mean(x)))
    sum = 0
    for val in x:
        sum += (val - m) ** 2
    print(sum)

if __name__ == '__main__':
    resolve()
Buggy code:
N = int(input())
X = list(map(int,input().split()))
avex = round(sum(X)/N)
print(avex)
sumX = 0
for x in X:
    print(x)
    sumX = sumX + (x - 20) ** 2
    
print(sumX)

Fixed code:
N = int(input())
X = list(map(int,input().split()))
avex = round(sum(X)/N)
sumX = 0

for x in X:
    sumX = sumX + (x - avex) ** 2    
print(sumX)
Buggy code:
import math
import numpy as np
n= int(input())
l = list(map(int,input().split()))

ans = 0
me = int(round(np.mean(l)))
print(me)
for i in range(n):
  ans += (l[i]-me)**2
print(ans)

Fixed code:
import math
import numpy as np
n= int(input())
l = list(map(int,input().split()))

ans = 0
me = int(round(np.mean(l)))
#print(me)
for i in range(n):
  ans += (l[i]-me)**2
print(ans)
Buggy code:
import numpy as np
N = int(input())
X = np.array([x for x in map(int,input().split())])

ans_candidate = int((X**2).sum()-(X.sum())**2/N)

if ((X-ans_candidate)**2).sum() < ((X-(ans_candidate+1))**2).sum():
    ans = ans_candidate
else:
    ans = ans_candidate+1

print(ans)

Fixed code:
import numpy as np
N = int(input())
X = np.array([x for x in map(int,input().split())])

P = int(X.sum()/N)

if ((X-P)**2).sum() < ((X-(P+1))**2).sum():
    ans = ((X-P)**2).sum()
else:
    ans = ((X-(P+1))**2).sum()

print(ans)
Buggy code:
N = input()
X = list(map(int, input().split()))
for p in range(1, max(X)):
    for x in X:
        x_sum=0
        x_sum+=(x-p)**2
    ans = min(ans, x_sum)
print(ans)

Fixed code:
N = int(input())
X = list(map(int, input().split()))
ans = float("inf")
for p in range(1, max(X)+1):
    x_sum=0
    for x in X:
        x_sum+=(x-p)**2
    ans = min(ans, x_sum)
print(ans)
Buggy code:
def main():
    N = int(input())
    X = list(map(int, input().split(" ")))
    calc = [0]*max(X)
    for i in range(max(X)):
        for j in range(N):
            calc[i] += (X[j] - (i+1))**2

        print(calc)
    print(min(calc))

if __name__ == '__main__':
    main()

Fixed code:
def main():
    N = int(input())
    X = list(map(int, input().split(" ")))
    calc = [0]*max(X)
    for i in range(max(X)):
        for j in range(N):
            calc[i] += (X[j] - (i+1))**2

        #print(calc)
    print(min(calc))

if __name__ == '__main__':
    main()
Buggy code:
import numpy as np
n = int(input())
x = input().split()
x = np.array(x,dtype='int')
m = x.sum()
v = (x**2).sum()
pm = int(np.round(m/n))
n * pm**2 - 2*pm*m + v

Fixed code:
import numpy as np
n = int(input())
x = input().split()
x = np.array(x,dtype='int')
m = x.sum()
v = (x**2).sum()
pm = int(np.round(m/n))
print(n * pm**2 - 2*pm*m + v)
Buggy code:
n = int(input())
x = list(map(int, input().split()))
mi = 10**6
for i in range(1, n+1):
    tmp = 0
    for j in x:
        tmp += (i-j)**2
    mi = min(tmp, mi)
print(mi)

Fixed code:
n = int(input())
x = list(map(int, input().split()))
mi = 10**6
for i in range(min(x), max(x)+1):
    tmp = 0
    for j in x:
        tmp += (i-j)**2
    mi = min(tmp, mi)
print(mi)
Buggy code:
N=int(input())
a=list(map(int,input().split()))
s=[]
for i in range(101):
  for j in range(0,len(a)):
    m=0
    m+=(a[j]-i)**2
    s.append(m)
print(min(s))    

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

res = float('inf')

for i in range(min(X, 1), max(X, 100) + 1):
    tmp = 0
    for x in X:
        tmp += (i - x) ** 2

    res = min(tmp, res)

print(res)

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

res = float('inf')

for i in range(-100, 101):
    tmp = 0
    for x in X:
        tmp += (i - x) ** 2

    res = min(tmp, res)

print(res)