qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import copy
def getPrimes(n):
    res = {}
    for i in range(2, n+1):
        if n % i == 0:
            res[i] = 0
            while n % i == 0:
                res[i] = res[i] + 1
                n = n // i
        if i * i > n:
            break;
        
    if n != 1:
        res[n] = 1
    return res

def add(a, b):
    res = copy.deepcopy(a)
    for i in b:
        if i in res:
            res[i] = res[i] + b[i]
        else:
            res[i] = b[i]
    return res

N = int(input())
cnt = {}
for i in range(1, N+1):
    cnt = add(cnt, getPrimes(i))

num = []
for i in cnt:
    num.append(cnt[i])
num.sort()
print(num)
ans  = 0
for i in range(len(num)):
    for j in range(len(num)):
        for k in range(j + 1, len(num)):
            if i == j or i == k:
                continue
            if num[i] >= 2 and num[j] >= 4 and num[k] >= 4:
                ans = ans + 1
                
for i in range(len(num)):
    for j in range(len(num)):
        if i != j and num[i] >= 2 and num[j] >= 24:
            ans = ans + 1
            
for i in range(len(num)):
    for j in range(len(num)):
        if i != j and num[i] >= 4 and num[j] >= 14:
            ans = ans + 1
            
for i in range(len(num)):
    if num[i] >= 74:

        
        ans = ans + 1
print(ans)




Fixed code:
import copy
def getPrimes(n):
    res = {}
    for i in range(2, n+1):
        if n % i == 0:
            res[i] = 0
            while n % i == 0:
                res[i] = res[i] + 1
                n = n // i
        if i * i > n:
            break;
        
    if n != 1:
        res[n] = 1
    return res

def add(a, b):
    res = copy.deepcopy(a)
    for i in b:
        if i in res:
            res[i] = res[i] + b[i]
        else:
            res[i] = b[i]
    return res

N = int(input())
cnt = {}
for i in range(1, N+1):
    cnt = add(cnt, getPrimes(i))

num = []
for i in cnt:
    num.append(cnt[i])
num.sort()
ans  = 0
for i in range(len(num)):
    for j in range(len(num)):
        for k in range(j + 1, len(num)):
            if i == j or i == k:
                continue
            if num[i] >= 2 and num[j] >= 4 and num[k] >= 4:
                ans = ans + 1
                
for i in range(len(num)):
    for j in range(len(num)):
        if i != j and num[i] >= 2 and num[j] >= 24:
            ans = ans + 1
            
for i in range(len(num)):
    for j in range(len(num)):
        if i != j and num[i] >= 4 and num[j] >= 14:
            ans = ans + 1
            
for i in range(len(num)):
    if num[i] >= 74:

        
        ans = ans + 1
print(ans)
Buggy code:
n=int(input())
e=[0]*(n+1)
for i in range(2,n+1):
    cur=i
    for j in range(2,i+1):
        while cuur%j==0:
            e[j]+=1
            cur//=j
def num(m):
    return len(list(filter(lambda  x: x>=m-1,e)))

print(num(75)+num(25)*(num(3)-1)+num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)


Fixed code:
# coding: utf8

n = int(input())
e = [0] * (n + 1)

for i in range(2, n + 1):
    cur = i
    for j in range(2, i + 1):
        while cur % j == 0:
            e[j] += 1
            cur //= j

def num(m):
    return len(list(filter(lambda x: x >= m-1, e)))
    
print(num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1) + num(5) * (num(5) -1) * (num(3) -2) // 2 )
Buggy code:
def find_prime_factor(num):
    if num & 1 == 0:
        return 2
    for i in range(3, int(num ** (1 / 2)) + 1):
        if num % i == 0:
            return i
    return num


def prime_factorization(num):
    subtract = num
    result = []
    while subtract > 1:
        factor = find_prime_factor(subtract)
        result.append(factor)
        subtract //= factor
    return result


n = int(input())

# prime and prime's power.
power = {}
for i in range(1, n + 1):
    for prime in prime_factorization(i):
        if prime in power:
            power[prime] += 1
        else:
            power[prime] = 1

count75 = 0
count25 = 0
count15 = 0
count5 = 0
count3 = 0
for count in power.values():
    if count >= 74:
        count75 += 1
    elif count >= 24:
        count25 += 1
    elif count >= 14:
        count15 += 1
    elif count >= 4:
        count5 += 1
    elif count >= 2:
        count3 += 1

print(count75, count25, count15, count5, count3)

sum25 = count75 + count25
sum15 = count75 + count25 + count15
sum5 = count75 + count25 + count15 + count5
sum3 = count75 + count25 + count15 + count5 + count3
ans = count75 + sum25 * (sum3 - 1) + sum15 * (sum5 - 1) + (sum5 * (sum5 - 1) * (sum3 - 2)) // 2

print(ans)

Fixed code:
def find_prime_factor(num):
    if num & 1 == 0:
        return 2
    for i in range(3, int(num ** (1 / 2)) + 1):
        if num % i == 0:
            return i
    return num


def prime_factorization(num):
    subtract = num
    result = []
    while subtract > 1:
        factor = find_prime_factor(subtract)
        result.append(factor)
        subtract //= factor
    return result


n = int(input())

# prime and prime's power.
power = {}
for i in range(1, n + 1):
    for prime in prime_factorization(i):
        if prime in power:
            power[prime] += 1
        else:
            power[prime] = 1

count75 = 0
count25 = 0
count15 = 0
count5 = 0
count3 = 0
for count in power.values():
    if count >= 74:
        count75 += 1
    elif count >= 24:
        count25 += 1
    elif count >= 14:
        count15 += 1
    elif count >= 4:
        count5 += 1
    elif count >= 2:
        count3 += 1

sum25 = count75 + count25
sum15 = count75 + count25 + count15
sum5 = count75 + count25 + count15 + count5
sum3 = count75 + count25 + count15 + count5 + count3
ans = count75 + sum25 * (sum3 - 1) + sum15 * (sum5 - 1) + (sum5 * (sum5 - 1) * (sum3 - 2)) // 2

print(ans)
Buggy code:
N = int(input())
lim = 1
for i in range(N): lim *= (i+1)
Prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,\
    53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

Ans = 0
for i in range(23):
    for j in range(i+1, 24):
        for k in range(j+1, 25):
            a, b, c = Prime[i], Prime[j], Prime[k]
            d, e, f = (a**4)*(b**4)*(c**2), (a**4)*(b**2)*(c**4), (a**2)*(b**4)*(c**4)
            if d <= lim and lim%d == 0: Ans += 1
            if e <= lim and lim%e == 0: Ans += 1
            if f <= lim and lim%f == 0: Ans += 1
for i in range(24):
    for j in range(i+1, 25):
        a, b = Prime[i], Prime[j]
        d, e, f, g = (a**24)*(b**2), (a**2)*(b**24), (a**4)*(b**14), (a**14)*(b**4)
        if d <= lim and lim%d == 0: Ans += 1
        if e <= lim and lim%e == 0: Ans += 1
        if f <= lim and lim%f == 0: Ans += 1
        if g <= lim and lim%g == 0: Ans += 1
print(Ans)

Fixed code:
N = int(input())
lim = 1
for i in range(N): lim *= (i+1)
Prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,\
    53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

Ans = 0
for i in range(23):
    for j in range(i+1, 24):
        for k in range(j+1, 25):
            a, b, c = Prime[i], Prime[j], Prime[k]
            d, e, f = (a**4)*(b**4)*(c**2), (a**4)*(b**2)*(c**4), (a**2)*(b**4)*(c**4)
            if d <= lim and lim%d == 0: Ans += 1
            if e <= lim and lim%e == 0: Ans += 1
            if f <= lim and lim%f == 0: Ans += 1
for i in range(24):
    for j in range(i+1, 25):
        a, b = Prime[i], Prime[j]
        d, e, f, g = (a**24)*(b**2), (a**2)*(b**24), (a**4)*(b**14), (a**14)*(b**4)
        if d <= lim and lim%d == 0: Ans += 1
        if e <= lim and lim%e == 0: Ans += 1
        if f <= lim and lim%f == 0: Ans += 1
        if g <= lim and lim%g == 0: Ans += 1
for i in range(5):
    if Prime[i] ** 74 <= lim and lim % (Prime[i]**74) == 0: Ans += 1
print(Ans)
Buggy code:
import itertools

N = int(input())
b = [False] * 101
prime = []
b[1] = True

for i in range(2, 101):
    if b[i]:
        continue
    k = i + i
    while k < 101:
        b[k] = True
        k += i

    prime.append(i)

p = [[0] * len(prime) for i in range(N + 1)]

for i in range(1, N + 1):
    n = i
    for j in range(len(prime)):
        while n % prime[j] == 0:
            p[i][j] += 1
            n //= prime[j]

pp = [0] * len(prime)

for i in range(len(prime)):
    for j in range(1, N + 1):
        pp[i] += p[j][i]

ans = 0

for x in pp:
    if x == 74:
        ans += 1

for a in list(itertools.combinations(range(len(prime)), 2)):
    if pp[a[0]] >= 24 and pp[a[1]] >= 2:
        ans += 1
    if pp[a[0]] >= 2 and pp[a[1]] >= 24:
        ans += 1
    if pp[a[0]] >= 14 and pp[a[1]] >= 4:
        ans += 1
    if pp[a[0]] >= 4 and pp[a[1]] >= 14:
        ans += 1

for a in list(itertools.combinations(range(len(prime)), 3)):
    if pp[a[0]] >= 2 and pp[a[1]] >= 4 and pp[a[2]] >= 4:
        ans += 1
    if pp[a[0]] >= 4 and pp[a[1]] >= 2 and pp[a[2]] >= 4:
        ans += 1
    if pp[a[0]] >= 4 and pp[a[1]] >= 4 and pp[a[2]] >= 2:
        ans += 1

print(ans)

Fixed code:
import itertools

N = int(input())
b = [False] * 101
prime = []
b[1] = True

for i in range(2, 101):
    if b[i]:
        continue
    k = i + i
    while k < 101:
        b[k] = True
        k += i

    prime.append(i)

p = [[0] * len(prime) for i in range(N + 1)]

for i in range(1, N + 1):
    n = i
    for j in range(len(prime)):
        while n % prime[j] == 0:
            p[i][j] += 1
            n //= prime[j]

pp = [0] * len(prime)

for i in range(len(prime)):
    for j in range(1, N + 1):
        pp[i] += p[j][i]

ans = 0

for x in pp:
    if x >= 74:
        ans += 1

for a in list(itertools.combinations(range(len(prime)), 2)):
    if pp[a[0]] >= 24 and pp[a[1]] >= 2:
        ans += 1
    if pp[a[0]] >= 2 and pp[a[1]] >= 24:
        ans += 1
    if pp[a[0]] >= 14 and pp[a[1]] >= 4:
        ans += 1
    if pp[a[0]] >= 4 and pp[a[1]] >= 14:
        ans += 1

for a in list(itertools.combinations(range(len(prime)), 3)):
    if pp[a[0]] >= 2 and pp[a[1]] >= 4 and pp[a[2]] >= 4:
        ans += 1
    if pp[a[0]] >= 4 and pp[a[1]] >= 2 and pp[a[2]] >= 4:
        ans += 1
    if pp[a[0]] >= 4 and pp[a[1]] >= 4 and pp[a[2]] >= 2:
        ans += 1

print(ans)
Buggy code:
import statistics
n = int(input())
a = list(map(int,input().split()))
s = statistics.mean(a)
print(s)
c = float("inf")
d = i
for i in range(n):
    if c!= min(abs(s-a[i]),c):
        c = s-a[i]
        d = i
print(d)

Fixed code:
import statistics
n = int(input())
a = list(map(int,input().split()))
s = statistics.mean(a)
c = float("inf")
for i in range(n):
    if c!=min(abs(s-a[i]),c):
        c = abs(s-a[i])
        d = i
print(d)
Buggy code:
a=int(input())
f = list(map(int,input().split()))
b=[]
ave=sum(f)/a
for i in f:
    diff=abs(i-ave)
    b.append(diff)
print(b)
print(b.index(min(b)))

Fixed code:
a=int(input())
f = list(map(int,input().split()))
b=[]
ave=sum(f)/a

for i in f:
    diff=abs(i-ave)
    b.append(diff)
print(b.index(min(b)))
Buggy code:
N = int(input())
A = list(map(int,input().split()))
ave = sum(A) / N
ans = 0
a = 10**10
for i in range(N):
  if abs(A[i] - ave) < a:
    ans = i
print(ans)

Fixed code:
N = int(input())
A = list(map(int,input().split()))
ave = sum(A) / N
ans = 0
a = 10**10
for i in range(N):
  if abs(A[i] - ave) < a:
    a = abs(A[i] - ave)
    ans = i
print(ans)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
INF = float("inf")
ave = sum(A)/N
MIN = INF

for i in range(N):
  if abs(A[i]-ave) <= MIN:
    ans = i
print(i)
    

Fixed code:
N = int(input())
A = list(map(int,input().split()))
INF = float("inf")
ave = sum(A)/N
MIN = INF
#print(ave)
for i in range(N):
  if abs(A[i]-ave) < MIN:
    ans = i
    MIN = abs(A[i]-ave)
    #print(ans,i)
    
print(ans)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
mean = sum(a) / n
INF = 10**5
flg = INF
for i in range(n):
  if abs(mean - a[i]) < flg:
    idx = i
print(idx)

Fixed code:
n = int(input())
a = list(map(int, input().split()))
mean = sum(a) / n
INF = 10**5
flg = INF
for i in range(n):
  if abs(mean - a[i]) < flg:
    idx = i
    flg = abs(mean - a[i])
print(idx)
Buggy code:
N=int(input())
A=list(map(int,input().split()))
t=sum(a)
for i in range(N):
  A[i]=abs(A[i]*N-t)
dif = min(A)
for i in range(N):
  if dif==A[i]:
    print(i)
    break

Fixed code:
N=int(input())
A=list(map(int,input().split()))
t=sum(A)
for i in range(N):
  A[i]=abs(A[i]*N-t)
dif = min(A)
for i in range(N):
  if dif==A[i]:
    print(i)
    break
Buggy code:
n =int(input())
a=[int(x) for x in input().split()]
 
s=sum(a)
ans=0
diff=abs(s-a[0]*n)
for i in range(len(a)):
  if diff>abs(s-a[i]*n):
    diff= abs(s-a[i]*n)
    ans=i
print(i)

Fixed code:
n =int(input())
a=[int(x) for x in input().split()]
 
s=sum(a)
ans=0
diff=abs(s-a[0]*n)
for i in range(n):
  if diff>abs(s-a[i]*n): 
    diff= abs(s-a[i]*n)
    ans=i
print(ans)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
mu = sum(A) / N
diff = 1000
ans = 0
for a in A:
  if abs(a - mu) < diff:
    diff = abs(a - mu)
    ans = a

print(ans)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
mu = sum(A) / N
diff = 1000
ans = 0
for i, a in enumerate(A):
  if abs(a - mu) < diff:
    diff = abs(a - mu)
    ans = i

print(ans)
Buggy code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = LI()
    av = sum(a)/n
    aa = list(map(lambda x: abs(x - av), a))
    aa = list(zip(aa, range(n)))
    aa.sort()
    print(aa[1])
    return


#main
if __name__ == '__main__':
    solve()


Fixed code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = LI()
    av = sum(a)/n
    aa = list(map(lambda x: abs(x - av), a))
    aa = list(zip(aa, range(n)))
    aa.sort()
    print(aa[0][1])
    return


#main
if __name__ == '__main__':
    solve()
Buggy code:
n = int(input())
numlist = list(map(int, input().split()))
cal = 0
for i in numlist:
  cal = cal + i
ave = cal / (n)
dummy = abs(numlist[0]-ave)
index = 0
count = 0
for j in numlist:
  kyori = abs(j-ave)
  if dummy > kyori:
    dummy = kyori
    index = count
  count = count + 1 
print(index+1)

Fixed code:
n = int(input())
numlist = list(map(int, input().split()))
cal = 0
for i in numlist:
  cal = cal + i
ave = cal / (n)
dummy = abs(numlist[0]-ave)
index = 0
count = 0
for j in numlist:
  kyori = abs(j-ave)
  if dummy > kyori:
    dummy = kyori
    index = count
  count = count + 1 
print(index)
Buggy code:
N = int(input())

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

goke = 0
ans = 0

for i in range(len(a)):
    goke += a[i]

ave = goke / N

ans = 0
for i in range(len(a)):
    print(ave-a[ans])
    print(ave-a[i])
    if abs(ave-a[ans]) > abs(ave - a[i]):
        ans = i


print(ans)

Fixed code:
N = int(input())

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

goke = 0
ans = 0

for i in range(len(a)):
    goke += a[i]

ave = goke / N

ans = 0
for i in range(len(a)):
    if abs(ave-a[ans]) > abs(ave - a[i]):
        ans = i


print(ans)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
tmp = max(a)
ave = sum(a)/n
ans = 0
for i in range(n):
  if tmp < abs(ave - a[i]):
    ans = i
    ave = abs(ave - a[i])
print(ans)


Fixed code:
n=int(input())
a=list(map(int,input().split()))
ave=sum(a)/n
ans=0
dif=100
for i in range(n):
    tmp=abs(ave-a[i])
    if tmp<dif:
        ans=i
        dif=tmp
print(ans)
Buggy code:
N = int(input())
A = list(map(int, input().split()))

# avg = sum(A) / N
sum_a = sum(a)
ans = float('inf')
ansf = -1
for i, ai in enumerate(A):
    # diff = abs(ai - avg)
    diff = abs(N * ai - sum_a)
    if diff < ans:
        ans = diff
        ansf = i

print(ansf)

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

# avg = sum(A) / N
sum_a = sum(A)
ans = float('inf')
ansf = -1
for i, ai in enumerate(A):
    # diff = abs(ai - avg)
    diff = abs(N * ai - sum_a)
    if diff < ans:
        ans = diff
        ansf = i

print(ansf)
Buggy code:
a = int(input())
b = list(map(int,input().split()))
c = sum(b)/a
d = []
for i in b:
    d.append(abs(i-c))
    print(d)
print(d.index(min(d)))

Fixed code:
d = []
a=int(input())
b = list(map(int,input().split()))
c = sum(b)/a
for i in b:
  d.append(abs(c - i))
e = min(d)
print(d.index(e))
Buggy code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    m = sum(a)/n
    f = {}
    for i in range(n):
        if not a[i] in f:
            f[a[i]] = i
    a = list(set(a))
    a.sort()
    i = bisect.bisect_left(a,m)-1
    if abs(m-a[i]) < abs(a[i+1]-m):
        print(f[a[i]])
    elif abs(m-a[i]) < abs(a[i+1]-m):
        print(min(f[a[i]],f[a[i+1]]))
    else:
        print(f[a[i+1]])
    return

#Solve
if __name__ == "__main__":
    solve()


Fixed code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    m = sum(a)/n
    f = {}
    for i in range(n):
        if not a[i] in f:
            f[a[i]] = i
    a = list(set(a))
    a.sort()
    i = bisect.bisect_left(a,m)-1
    if abs(m-a[i]) < abs(a[i+1]-m):
        print(f[a[i]])
    elif abs(m-a[i]) == abs(a[i+1]-m):
        print(min(f[a[i]],f[a[i+1]]))
    else:
        print(f[a[i+1]])
    return

#Solve
if __name__ == "__main__":
    solve()
Buggy code:
N = int(input())
A = list(map(int,input().split()))
ave = sum(A)/N
ans = 0
sa = 10**9
for i in range(N):
    t = i+1
    x = max(A[i]-ave,ave-A[i])
    if x < sa:
        sa = x
        ans = t
print(ans)

Fixed code:
N = int(input())
A = list(map(int,input().split()))
ave = sum(A)/N
ans = 0
sa = 10**9
for i in range(N):
    x = max(A[i]-ave,ave-A[i])
    if x < sa:
        sa = x
        ans = i
print(ans)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
avg = sum(a)/n
difmin = 10**18
for i in range(n):
  if difmin>abs(a[i]-avg):
    difmin = abs(a[i]-avg)
    ans = i
print(i)

Fixed code:
n = int(input())
a = list(map(int,input().split()))
avg = sum(a)/n
difmin = 10**18
for i in range(n):
  if difmin>abs(a[i]-avg):
    difmin = abs(a[i]-avg)
    ans = i
print(ans)
Buggy code:
N = int(input())
a = list(map(int,input().split()))

b = []
s = int(sum(a)/len(a))
for i in range(len(a)):
    b.append(abs(a[i]-s)

print(b.index(min(b)))


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

b = []
s = (sum(a)/len(a))
for i in range(len(a)):
    b.append(abs(a[i]-s))

print(b.index(min(b)))
Buggy code:
n,*a=map(int,open(0).read().split());print(asorted((abs(a[i]-sum(a)/n),i)for i in range(n))[0][1])

Fixed code:
n,*a=map(int,open(0).read().split());print(sorted((abs(a[i]-sum(a)/n),i)for i in range(n))[0][1])
Buggy code:
n = int(input())
A = list(map(int, input().split()))

S = sum(A)
d = 10**14
for i, a in enumerate(A):
  if abs(a*N-S) < d:
    d = abs(a*N-S)
    ind = i
    
print(ind)

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

S = sum(A)
d = 10**14
for i, a in enumerate(A):
  if abs(a*n-S) < d:
    d = abs(a*n-S)
    ind = i
    
print(ind)
Buggy code:
import numpy as np
N = int(input())
alist = np.array(list(map(int, input().split())))
mean = sum(alist) / N
alist = alist - mean
print(np.argmin(alist))


Fixed code:
import numpy as np
N = int(input())
alist = np.array(list(map(int, input().split())))
mean = sum(alist) / N
alist = np.abs(alist - mean)
print(np.argmin(alist))
Buggy code:
N=int(input())
A=list(map(int,input().split()))
sum=0
for i in range(N):
  sum+=A[i]
sum
ans=0
for i in range(N):
  A[i]=abs(A[i]*N-sum)
  if(A[i]<A[ans]):
    ans=i
print(ans+1)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
m = sum(A)
ans = 0
for i in range(N):
  if abs(A[i]*N - m) < abs(A[ans]*N - m):
    ans = i    
print(ans)
Buggy code:
N= int(input())
A= list(map(int,input().split()))

Ave = sum(A)/len(A)
# print('Ave:',Ave)
abs_distance = list()

abs_distance.append(int(abs(A[i]-Ave)) for i in range(N))
# for i in range(N):
#     abs_distance.append(int(abs(A[i]-Ave)))
#     # print(int(abs(A[i]-Ave*N)))
# # print(abs_distance)

print(abs_distance.index(min(abs_distance)))

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

Ave = sum(A)/len(A)
abs_distance = list()

for i in range(N):
    abs_distance.append(abs(A[i]-Ave))

print(abs_distance.index(min(abs_distance)))
Buggy code:
N=int(input())
a=[int(i) for i in input().split()]

ave=(sum(a)/N)

ave_a=[abs(i-ave) for i in a]
print(ave_a)

ans=101
thum=101
for i in range(N):
    if ave_a[i]<thum:
        thum=ave_a[i]
        ans=i

print(ans)

Fixed code:
N=int(input())
a=[int(i) for i in input().split()]

ave=(sum(a)/N)

ave_a=[abs(i-ave) for i in a]

ans=101
thum=101
for i in range(N):
    if ave_a[i]<thum:
        thum=ave_a[i]
        ans=i

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

ave_a = sum(a) / n
dist = 1000007
flamenum = 0

for i in range(n):
    if abs(a[i] - ave_a) < dist:
        dist = abs(a[i] - ave_a)
        flamenum = i

print(i)

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

ave_a = sum(a) / n
dist = 1000007
flamenum = 0

for i in range(n):
    if abs(a[i] - ave_a) < dist:
        dist = abs(a[i] - ave_a)
        flamenum = i
        #print(dist)

print(flamenum)
Buggy code:
n = int(input())
A = list(map(int,input().split()))
ave = sum(A)/n 
diff = []  
for a in A:
	diff.append(abs(a-ave))
tmp = 0   
d = 10**9
for i in range(n):
	if diff[i] < d:
		d = diff[i]
		tmp = i
print(i)

Fixed code:
n = int(input())
A = list(map(int,input().split()))
ave = sum(A)/n 
diff = []  
for a in A:
	diff.append(abs(a-ave))
tmp = 0   
d = 10**9
for i in range(n):
	if diff[i] < d:
		d = diff[i]
		tmp = i
print(tmp)