qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import math
N = int(input())
x = []
s = input()
x = s.split()
y = len(x)
summ1 = 0
summ2 = 0
sr = 0
setx = set(x)
h = len(setx)
if N == 1:
    print("0")
else:
    if h == 0:
        print("0")
    else:
        for i in range(y):
            x[i] = int(x[i])
            sr = sr + x[i]
        PMA = math.ceil(sr//N)
        PMM = math.floor(sr//N)
        for i in range(y):
            summ1 = summ1 + ((x[i]-PMA)*(x[i]-PMA))
        for i in range(y):
            summ2 = summ2 + ((x[i] - PMM) * (x[i] - PMM))
        if summ2 > summ1:
            print(summ1)
        else:
            print(summ2)
        

Fixed code:
N = int(input())
x = []
s = input()
x = s.split()
y = len(x)
summ1 = 0
summ2 = 0
sr = 0
setx = set(x)
h = len(setx)
if N == 1:
    print("0")
else:
    if h == 0:
        print("0")
    else:
        for i in range(y):
            x[i] = int(x[i])
            sr = sr + x[i]
        PMA = (sr//N)+1
        PMM = sr//N
        for i in range(y):
            summ1 = summ1 + ((x[i]-PMA)*(x[i]-PMA))
        for i in range(y):
            summ2 = summ2 + ((x[i] - PMM) * (x[i] - PMM))
        if summ2 > summ1:
            print(summ1)
        else:
            print(summ2)
Buggy code:
N=int(input())
X=list(map(int,input().split()))
Min=10**10
for i in range(N):
    p=0
    for j in range(N):
        p+=(X[j]-i-1)**2
    if Min>p:
        Min=p
    print(p)
print(Min)

Fixed code:
N=int(input())
X=list(map(int,input().split()))
X.sort()
x_min=X[0]
x_max=X[N-1]
Min=10**10
for i in range(x_min,x_max+1):
    p=0
    for j in range(N):
        p+=(X[j]-i)**2
    if Min>p:
        Min=p
print(Min)
Buggy code:
N = int(input())
X = list(map(int, input().split()))
X.sort()
ans = 999999999
for i in range(1,100):
    tmp = 0
    for j in X:
        tmp += (i-j)**2
    if tmp < ans:
        ans = tmp
        ans = i
print(ans)

Fixed code:
N = int(input())
X = list(map(int, input().split()))
X.sort()
ans = 999999999
for i in range(1,100):
    tmp = 0
    for j in X:
        tmp += (i-j)**2
    if tmp < ans:
        ans = tmp
print(ans)
Buggy code:
N = int(input())
cc = list(map(int,input().split()))
count = 0
min_sum = float('inf')
for i in range(1,101):
  for j in cc:
    count += (i-j)**2
  min_sum = min(min_sum,count)
print(min_sum)
    
  

Fixed code:
N = int(input())
cc = list(map(int,input().split()))
min_sum = float('inf')
for i in range(1,101):
  count = 0
  for j in cc:
    count += (i-j)**2
  min_sum = min(min_sum,count)
print(min_sum)
Buggy code:
N = int(input())
X = list(map(int,input().split()))
M = round(sum(X)/N)
answer = 0
for i in X:
  answer +=(i-M)*2
print(answer)

Fixed code:
N = int(input())
X = list(map(int,input().split()))
M = round(sum(X)/N)
answer = 0
for i in X:
  answer +=(i-M)**2
print(answer)
Buggy code:
n=int(input())
x=list(map(int,input().split()))
res=10**6
for i in range(1,101):
  tmp = sum([(i-y)**2 for y in x])
  if res > tmp:
    res = tmp


Fixed code:
n=int(input())
x=list(map(int,input().split()))
res=10**6
for i in range(1,101):
  tmp = sum([(i-y)**2 for y in x])
  if res > tmp:
    res = tmp
print(res)
Buggy code:
N = int( input())
X = list( map( int, input().split()))

v_min = 10 ** 18
m = min( X )
M = max( X )
for i in range( m, M + 1):
  v = 0
  for x in X:
    x += ( i - x ) ** 2
  v_min = min( v, v_min )
print( v_min )
  



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

v_max = 10 ** 18
m = min( X )
M = max( X )
for i in range( m, M + 1 ):
  v = 0
  for x in X:
    v += ( x - i ) ** 2
  v_max = min( v, v_max )
print( v_max )
Buggy code:
n = int(input())
x = [int(x) for x in input().split()]
sum = 0
list = [] * n
for i in range(n):
    sum = 0
    for j in range(n):
        sum = sum + (x[j] - (i+1))**2
    list.append(sum)
print(min(list))

Fixed code:
n = int(input())
x = [int(x) for x in input().split()]
sum = 0
list = []
for i in range(1, 101):
    for j in range(n):
        sum += (x[j]-i)**2
    list.append(sum)
    sum = 0
print(min(list))
Buggy code:
import sys

def main():

    input = sys.stdin.buffer.readline
    n = int(input())
    x = list(map(int, input().split()))
    x.sort()
    mt = 10**10
    print(x)
    for ii in range(x[0],x[-1]+1):
        ans = 0
        for i in x:
            ans += (i-ii)**2
        mt = min(mt,ans)
    print(mt)    
    
if __name__ == "__main__":
    main()
    


Fixed code:
import sys

def main():

    input = sys.stdin.buffer.readline
    n = int(input())
    x = list(map(int, input().split()))
    x.sort()
    mt = 10**10
    for ii in range(x[0],x[-1]+1):
        ans = 0
        for i in x:
            ans += (i-ii)**2
        mt = min(mt,ans)
    print(mt)    
    
if __name__ == "__main__":
    main()
Buggy code:
N = int(input())
x = list(map(int,input().split()))

l=[]

for p in range(1,N+1):
  sum=0
  
  for i in range(N):
    sum += (x[i]-p)**2
  
  l.append(sum)
  
print(sorted(l)[0])

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

l=[]

for p in range(1,101):
  sum=0
  
  for i in range(N):
    sum += (x[i]-p)**2
  
  l.append(sum)
  
print(sorted(l)[0])
Buggy code:
N = input()
coordinate = list(map(int, input().split()))
result = 0
resultl = 0

for j in range(N):
    result += (1-coordinate[j])**2

for i in range(1,101):
    for k in range(N):
        resultl += (i-coordinate[k])**2

    if resultl < result:
        result = resultl
    resultl = 0

print(result)

Fixed code:
N = int(input())
coordinate = list(map(int, input().split()))
result = 0
resultl = 0
 
for j in range(N):
    result += (1-coordinate[j])**2
    
for i in range(1,101):
    for k in range(N):
        resultl += (i-coordinate[k])**2
 
    if resultl < result:
        result = resultl
    resultl = 0
    
print(result)
Buggy code:
N = int(input())
X = list(map(int, input().split()))

ans = 100 * N
P = 100
while P > 0:
    a = 0
    for x in X:
        a += (x - P) ** 2
    ans = min(ans, a)
    P -= 1
print(ans)

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

ans = []
P = 100
while P > 0:
    a = 0
    for x in X:
        a += (x - P) ** 2
    ans.append(a)
    P -= 1
print(min(ans))
Buggy code:
n=int(input())
X=[int(x) for x in input().split()]
ans=float("inf")
for p in range(1,101):
  s=0
  for x in X:
    s+=(p-x)^2
  ans=min(s,ans)
print(ans)


Fixed code:
n=int(input())
X=[int(x) for x in input().split()]
ans=float("inf")
for p in range(1,101):
  s=0
  for x in X:
    s+=(p-x)**2
  ans=min(s,ans)
print(ans)
Buggy code:
# C
import numpy as np
N = int(input())
X = np.array(list(map(int, input().split())))

P_floor = math.floor(np.sum(X)/N)
P_ceil = math.ceil(np.sum(X)/N)

ans = min(np.sum((X-P_floor)**2), np.sum((X-P_ceil)**2))

print(ans)

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

P_floor = math.floor(np.sum(X)/N)
P_ceil = math.ceil(np.sum(X)/N)

ans = min(np.sum((X-P_floor)**2), np.sum((X-P_ceil)**2))

print(ans)
Buggy code:
n=input()
Xs=list(map(int,input().split()))
Xs.sort()
a=Xs[0]
b=Xs[-1]
ans=inf
for p in range(a,b+1):
    m=0
    for x in Xs:
        m+=(x-p)**2
    if m<ans:
        ans=m
print(ans)


Fixed code:
n=int(input())
Xs=list(map(int,input().split()))
Xs.sort()
a=Xs[0]
b=Xs[-1]
ans=float("inf")
for p in range(a,b+1):
    m=0
    for x in Xs:
        m+=(x-p)**2
    if m<ans:
        ans=m
print(ans)
Buggy code:
N = int(input())
X = list(map(int, input().split()))
M = round(sum(X)/N)
ans = 0
for i in X:
    ans+=(i-M)*2
print(ans)

Fixed code:
N = int(input())
X = list(map(int, input().split()))
M = round(sum(X)/N)
answer = 0
for i in X:
    answer+=(i-M)**2
print(answer)
Buggy code:
import sys
input = sys.stdin.readline
N = int(input())
lists = list(input().split())
ave_sum = 0
for i in lists:
  ave_sum = ave_sum + int(i)
ave = int(ave_sum / N)
nijyo = 0
for i in lists:
  nijyo = nijyo + (int(i) - ave_sum) ** 2
print(str(nijyo))

Fixed code:
import sys
input = sys.stdin.readline
N = int(input())
lists = list(input().split())
ave_sum = 0
for i in lists:
  ave_sum = ave_sum + int(i)
ave = round(ave_sum / N)
nijyo = 0
for i in lists:
  nijyo = nijyo + (int(i) - ave) ** 2
print(str(nijyo))
Buggy code:
N=int(input())
A=[int(x) for x in input().rstrip().split()]
ave=sum(A)//len(A)
ans=0
print(ave)
if N/2<(sum(A)%len(A)):
  ave+=1

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


Fixed code:
N=int(input())
A=[int(x) for x in input().rstrip().split()]
ave=sum(A)//len(A)
ans=0

if N/2<(sum(A)%len(A)):
  ave+=1

for i in A:
  ans+=(i-ave)**2
print(ans)
Buggy code:
n = int(input())
hp = list(map(int,input().split()))
a = []
for i in range(0,n):
  s = 0
  for j in range(0,n):
    s+=(hp[j]-i-1)**2
  a.append(s)
  
print(min(a))

Fixed code:
n = int(input())
hp = list(map(int,input().split()))
a = []
for i in range(0,101):
  s = sum((hp[j]-i-1)**2 for j in range(0,n))
  a.append(s)

print(min(a))
Buggy code:
import sys
l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip()
nums = map(int, l.split())
a = sum(nums) / len(nums)
a1 = int(a)
a2 = int(a) + 1
def count(p):
    d = 0
    for n in nums:
        d += (n-p)**2
    return d
print(min(count(a1), count(a2)))


Fixed code:
import sys
l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip()
nums = list(map(int, l.split()))
a = sum(nums) / len(nums)
a1 = int(a)
a2 = int(a) + 1
def count(p):
    d = 0
    for n in nums:
        d += (n-p)**2
    return d
print(min(count(a1), count(a2)))
Buggy code:
import sys
l = sys.stdin.readline().strip()
n = int(l)
l = sys.stdin.readline().strip()
nums = map(int, l.split())
nums = sorted(nums)
start = nums[0]
end = nums[-1] + 1
mi = -1
def compute_dist(p):
  dist = 0
  for n in nums:
    dist += (n-p) ** 2
  return dist
for i in range(start, end):
  d = compute_dist(i)
  if d < mi:
    mi = d
print(mi)

Fixed code:
import sys
l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip()
nums = map(int, l.split())
nums = sorted(nums)
start = nums[0]
end = nums[-1] + 1
mi = float("INF")
def compute_dist(p):
  dist = 0
  for n in nums:
    dist += (n-p) ** 2
  return dist
for i in range(start, end):
  d = compute_dist(i)
  if d < mi:
    mi = d
print(mi)
Buggy code:
n=int(input())
x=list(map(int, input().split()))
min_=10**9
for i in range(min(x),max(x)+1,1):
  #print(i)
  sum_=0
  for j in range(n):
    sum_+=(x[j]-i)**2
  if sum_<min_: min_=sum_
  print(min_)
print(int(min_))

Fixed code:
n=int(input())
x=list(map(int, input().split()))
min_=10**9
for i in range(min(x),max(x)+1,1):
  #print(i)
  sum_=0
  for j in range(n):
    sum_+=(x[j]-i)**2
  if sum_<min_: min_=sum_
  #print(min_)
print(int(min_))
Buggy code:
N = int(input())
X = sorted(list(map(int, input().split())))
if N == 1:
    print(0)
else:
    r = X[-1] - X[0]
    ans = float("inf")
    for i in range(r+1):
      R = X[0] + i
      hp = 0
      for j in range(N):
        hp = hp + (R - X[j]) ** 2
 
        ans = min(hp, ans)
 
    print(ans)

Fixed code:
N = int(input())
X = sorted(list(map(int, input().split())))
if N == 1:
    print(0)
else:
    r = X[-1] - X[0]
    ans = float("inf")
    for i in range(r + 1):
        R = X[0] + i
        hp = 0
        for j in range(N):
            hp = hp + (R - X[j]) ** 2

        ans = min(hp, ans)

    print(ans)
Buggy code:
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))
cost = float("inf")
for i in range(101):
    cost = min(np.sum((X - i) ** 2))
print(cost)

Fixed code:
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))
cost = float("inf")
for i in range(101):
    cost = min(np.sum((X - i) ** 2), cost)
print(cost)
Buggy code:
import numpy as np
N = int(input())
x = [int(i) for i in input().split() ]

each = 0
loss = 0
ll = []
k = 0

for k in range(min(x), max(x)):
      for j in range(len(x)):
            each = np.power((x[j]-k), 2)
            loss += each
      ll.append(loss)
  
print(min(ll))

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

each = 0
loss = 0
ll = []

for k in range(min(x), max(x)+1):
      for j in range(len(x)):
            each = np.power((x[j]-k), 2)
            loss += each
      ll.append(loss)
      loss = 0
  
print(min(ll))
Buggy code:
n=int(input())
l=list(map(int,input(),split()))

s=min(l)
g=max(l)
ans=0
for k in range (n):
  ans+=(l[k]-s)**2

for i in range(s+1,g+1):
  hyp=0
  for j in range (n):
    hyp+=(l[j]-i)**2
  if hyp<ans:
    ans=hyp
    
print (ans)

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

s=min(l)
g=max(l)
ans=0
for k in range (n):
  ans+=(l[k]-s)**2

for i in range(s+1,g+1):
  hyp=0
  for j in range (n):
    hyp+=(l[j]-i)**2
  if hyp<ans:
    ans=hyp
    
print (ans)
Buggy code:
N = int(input())
X = list(map(int, input().split()))

ans = 10**18
ans_ = 0

for P in range(-N, N + 1):
    ans_ = 0
    for x in X:
        ans_ += (x - P) ** 2
        ans = min(ans, ans_)

print(ans)


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

ans = 10**18
ans_ = 0

for P in range(1, max(X) + 1):
    ans_ = 0
    for x in X:
        ans_ += (x - P) ** 2
    ans = min(ans, ans_)

print(ans)
Buggy code:
n = int(input())

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

ans = float('inf')

for i in range(1,101):
  ans_temp = 0
  for j in x:
    ans_temp += (x-i)**2
  ans = min(ans,ans_temp)
print(ans)

Fixed code:
n = int(input())

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

ans = float('inf')

for i in range(1,101):
  ans_temp = 0
  for j in x:
    ans_temp += (j-i)**2
  ans = min(ans,ans_temp)
print(ans)
Buggy code:
N=int(input())
X=list(map(int,input().split()))
ans = 100000000
res = 0
for i in range(N):
  for j in range(1,100):
    res += (X[i]-j)**2
  ans=min(ans,res)
print(ans)

Fixed code:
N=int(input())
X=list(map(int,input().split()))
ans = 100000000
for j in range(1,100):
  res = 0
  for i in range(N):
    res += (X[i]-j)**2
  ans=min(ans,res)
print(ans)
Buggy code:
n = int(input())
x = [int(i) for i in input().split()]
ans = 100100100
for i in range(1,101) :
    s = 0
    for o in x :
        s+=(i-x)*(i-x)
    ans = min(ans,s)
print(ans)

Fixed code:
n = int(input())
x = [int(i) for i in input().split()]
ans = 100100100
for i in range(1,101) :
    s = 0
    for o in x :
        s+=(i-o)*(i-o)
    ans = min(ans,s)
print(ans)
Buggy code:
import sys
n = int(sys.stdin.readline())
li = list(map(int, sys.stdin.readline().split()))
min = 0
for k in li:
    min += (k-i) ** 2
i = 2
while i <= 100:
  s = 0
  for k in li:
    s += (k-i) ** 2
  if s < min:
    min = s
  i += 1
print(min)
    

Fixed code:
import sys
n = int(sys.stdin.readline())
li = list(map(int, sys.stdin.readline().split()))
min = 0
for k in li:
    min += (k-1) ** 2
i = 2
while i <= 100:
  s = 0
  for k in li:
    s += (k-i) ** 2
  if s < min:
    min = s
  i += 1
print(min)
Buggy code:
N = int(input())

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

a = sum(X) / N
integer = int(a)
f = a - i

if f < 0.5:
    P = integer
else:
    P = integer + 1

total = 0
for i in X:
    total += (i - P) ** 2

print(total)

Fixed code:
N = int(input())
 
X = list(map(int, input().split()))
 
a = round((sum(X) / N), 3)
integer = int(a)
f = a - integer
 
if f < 0.5:
    P = integer
else:
    P = integer + 1
 
total = 0
for i in X:
    total += (i - P) ** 2
 
print(total)
Buggy code:
N = int(input())
X = list(map(int, input().split()))
small = 10000000
temp = 0
p_max = max(X)

for p in range(1, p_max + 1):
  for i in range(N):
    temp += (X[i] - p)**2
    
  if temp < small:
    small = temp
    
print(small)


Fixed code:
N = int(input())
X = list(map(int, input().split()))
small = 10000000
temp = 0
p_max = max(X)

for p in range(1, p_max + 1):
  for i in range(N):
    temp += (X[i] - p)**2
    
  if temp < small:
    small = temp
  
  temp = 0
  
print(small)
Buggy code:
import math

N = int(input())
Xi = list(map(int, input().split(" ")))

Xi_min = min(Xi)
Xi_max = max(Xi)

ans = math.inf
print("-----")
for i in range(Xi_min, Xi_max+1):
    tmp = 0
    for j in range(N):
        tmp += pow(Xi[j] - i, 2)
    if tmp < ans:
        ans = tmp

print(ans)

Fixed code:
import math

N = int(input())
Xi = list(map(int, input().split(" ")))

Xi_min = min(Xi)
Xi_max = max(Xi)

ans = 999999999
for i in range(Xi_min, Xi_max+1):
    tmp = 0
    for j in range(N):
        tmp += pow(Xi[j] - i, 2)
    if tmp < ans:
        ans = tmp

print(ans)
Buggy code:
def main():
    print("solve abc156 C")
    n = int(input())
    x = [int(i) for i in input().split()]
    min_x = round(sum(x) / n)
    ans = sum([(min_x - i)**2 for i in x])
    print(ans)

if __name__ == "__main__":
    main()


Fixed code:
def main():
    n = int(input())
    x = [int(i) for i in input().split()]
    min_x = round(sum(x) / n)
    ans = sum([(min_x - i)**2 for i in x])
    print(ans)

if __name__ == "__main__":
    main()
Buggy code:
N = int(input())
X = list(map(int, input().split()))

Xmax = max(X)
Xmin = min(X)

ans = 0
ans_sum = 0

for P in range(Xmin,Xmax+1):
  for i in range(N):
    cal = (X[i] - P)**2
    ans_sum = ans_sum + cal
  if P == Xmin:
    ans = ans_sum
    ans_sum = 0
  elif ans >= ans_sum:
    ans = ans_sum
  else :
    ans_sum = 0
print(ans)
  
  

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

Xmax = max(X)
Xmin = min(X)

ans = 0
ans_sum = 0

for P in range(Xmin,Xmax+1):
  for i in range(N):
    cal = (X[i] - P)**2
    ans_sum = ans_sum + cal
  if P == Xmin:
    ans = ans_sum
    ans_sum = 0
  elif ans >= ans_sum:
    ans = ans_sum
    ans_sum = 0
  else :
    ans_sum = 0
print(ans)
Buggy code:
N = int(input())
X = list(map(int, input().split()))


ans = float("inf")
for i in range(N):
    conf_site = X[i]
    total = sum([(x - conf_site)**2 for x in X])
    ans = min(ans, total)

print(ans)

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


ans = float("inf")
for i in range(1,101):
    conf_site = i
    total = sum([(x - conf_site)**2 for x in X])
    ans = min(ans, total)

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

ans = 0

for i in range(max(x)):
    a = 0
    for j in range(n):
        a += (x[j]-i-1)**2
        print(j)
    if i == 0:
        ans += a
    else:
        ans = min(a, ans)

print(ans)

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

ans = 0

for i in range(max(x)):
    a = 0
    for j in range(n):
        a += (x[j]-i-1)**2
    if i == 0:
        ans += a
    else:
        ans = min(a, ans)

print(ans)
Buggy code:
N=int(input())
X=list(map(int,input().split()))
ans=10**9

for i in range(1,101):
  temp=0
  for j in range(N):
    temp+=(X[i]-j)**2
  else:
    ans=min(ans,temp)
print(ans)

Fixed code:
N=int(input())
X=list(map(int,input().split()))
ans=10**9
 
for i in range(1,101):
  temp=0
  for j in range(N):
    temp+=(X[j]-i)**2
  else:
    ans=min(ans,temp)
print(ans)
Buggy code:
N=int(input())
X=list(map(int,input().split()))
c=0
d=sum(X)/N
for i in X:
   c+=(i-d)**2
print(c)

Fixed code:
N=int(input())
X=list(map(int,input().split()))
c=0
d=round(sum(X)/N)
for i in X:
   c+=(i-d)**2
print(c)
Buggy code:
def resolve():
    n = int(input())
    x_list = list(map(int, input().split()))
    mn =　10**9
    for i in range(1, max(x_list)+1):
        sm = 0
        for x in x_list:
            sm += (x-i)**2
        if mn > sm:
            mn = sm  
    print(mn)
resolve()

Fixed code:
def resolve():
    n = int(input())
    x_list = list(map(int, input().split()))
    mn = 10**9
    for i in range(1, max(x_list)+1):
        sm = 0
        for x in x_list:
            sm += (x-i)**2
        if mn > sm:
            mn = sm  
    print(mn)
resolve()
Buggy code:
n = int(input())
x = list(map(int, input().split()))
t = round(sum(x) / N)
p = 0
for i in x:
    p += ((i-t)**2)
print(p)

Fixed code:
n = int(input())
x = list(map(int, input().split()))
t = round(sum(x) / n)
p = 0
for i in x:
    p += ((i-t)**2)
print(p)
Buggy code:
def main(n, x):
    ans = []

    for p in range(1, n + 101):
        t = 0
        for _x in x:
            t += (_x - p) ** 2

        ans.append(t)

    print(min(ans))


if __name__ == "__main__":
    n = int(input())
    x = list(map(int, input().split()))


Fixed code:
def main(n, x):
    ans = []

    for p in range(1, n + 101):
        t = 0
        for _x in x:
            t += (_x - p) ** 2

        ans.append(t)

    print(min(ans))


if __name__ == "__main__":
    n = int(input())
    x = list(map(int, input().split()))

    main(n, x)
Buggy code:
N = int(input())
X = list(map(int, input().split()))

total = 0
m = round(sum(X) / N)
print(m)
for i in X:
    total += (m - i) ** 2
print(total)

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

total = 0
m = round(sum(X) / N)

for i in X:
    total += (m - i) ** 2
print(total)
Buggy code:
N = int(input())
X = list(map(int,input().split()))
ans = 1000000000000000
for i in range(1,101):
    hp=0
    for j in range(N):
        B = (X[j]-i) ** 2
        hp+=B
    print(hp)
    if ans > hp:
        ans=hp

print(ans)
        


Fixed code:
N = int(input())
X = list(map(int,input().split()))
ans = 1000000000000000
for i in range(1,101):
    hp=0
    for j in range(N):
        B = (X[j]-i) ** 2
        hp+=B
    if ans > hp:
        ans=hp

print(ans)
Buggy code:
def main():
    N = int(input())
    X = list(map(int, input().split()))
    r = min((x - p) ** 2 for x in X for p in range(1, 101))
    print(r)


main()


Fixed code:
def main():
    N = int(input())
    X = list(map(int, input().split()))
    r = min(sum((x - p) ** 2 for x in X) for p in range(1, 101))
    print(r)


main()
Buggy code:
N = int(input().rstrip())

A = [int(n) for n in input().rstrip().split(' ')]

ans = []
for i in range(1, N+1):
  temp = 0
  for j in range(len(A)):
    temp += (A[j]-i)**2
  ans.append(temp)

print(min(ans))

Fixed code:
N = int(input().rstrip())
 
A = [int(n) for n in input().rstrip().split(' ')]
 
ans = []
for i in range(1, 100+1):
  temp = 0
  for j in range(len(A)):
    temp += (A[j]-i)**2
  ans.append(temp)
print(min(ans))
Buggy code:
n = input()
x = list(map(int,input().split()))
ans = sys.maxsize

# i = min(x)
# while i <= max(x):
for i in range(min(x),max(x)+1,1):
    tmp = sum(map(lambda p: (p-i)**2,x))
    if ans > tmp:
        ans = tmp
    # i += 1
print(ans)

Fixed code:
import sys

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

# i = min(x)
# while i <= max(x):
for i in range(min(x),max(x)+1,1):
    tmp = sum(map(lambda p: (p-i)**2,x))
    if ans > tmp:
        ans = tmp
    # i += 1
print(ans)
Buggy code:
N = int(input())
X = list(map(int, input().split()))
P = sum(X) // N
result1 = 0
result2 = 0

for x in X:
  result1 += (x - P)**2
  result2 += (x - P - 1)**2

if result1 < result2:
  result = result1
elif result1 > result2:
  result = result2


print(result)

Fixed code:
N = int(input())
X = list(map(int, input().split()))
P = sum(X) // N
result1 = 0
result2 = 0

for x in X:
  result1 += (x - P)**2
  result2 += (x - P - 1)**2

if result1 <= result2:
  result = result1
elif result1 > result2:
  result = result2


print(result)
Buggy code:
a=int(input())
li = list(map(int,input().split()))

dis = [0]*a
for p in range(a):
    for i in range(a):
        dis[p] += (li[i]-(p+1))**2
        
print(min(dis))

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

dis2 = [0]*100
for p in range(100):
    dis = 0
    for i in range(a):
        dis += (li[i]-(p+1))**2
    dis2[p] = dis
print(min(dis2))
Buggy code:
n = int(input())
x = list(map(int, input().split()))
print(x)
min_ans = 1e9
for i in range(100):
    ans = sum([(i + 1 - j) ** 2 for j in x])
    min_ans = min(ans, min_ans)

print((min_ans))

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

min_ans = 1e9
for i in range(100):
    ans = sum([(i + 1 - j) ** 2 for j in x])
    min_ans = min(ans, min_ans)

print(min_ans)
Buggy code:
N=int(input())

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

X.sort()
P=0
print(X)
min=10000000000
while P <= X[-1]:
    power=0
    for j in range(len(X)):
        power=power+(X[j]-P)**2

    if power<=min:
        min=power

    P=P+1


print(min)

Fixed code:
N=int(input())

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

X.sort()

min=10000000000
for P in range(100):

    power=0
    for j in range(len(X)):
        power=power+(X[j]-P)**2

    if power<=min:
        min=power

    P=P+1


print(min)