qyliang/CodeNanoFix huggingface dataset:
Buggy code:
s = input()
a = [0]*len(s)
r, l = 0, 0

for i in range(len(s)):
    r += 1
    if s[i] == 'L':
        a[i-1] += r//2
        a[i] += (r+1)//2
        r = 0
print(a)
for j in range(len(s)-1, -1, -1):
    l += 1
    if s[j] == 'R':
        a[j+1] += l//2
        a[j] += (l+1)//2
        l = 0
    a[j] -= 1

print(*a)



Fixed code:
s = input()
a = [0]*len(s)
r, l = 0, 0

for i in range(len(s)):
    r += 1
    if s[i] == 'L':
        a[i-1] += r//2
        a[i] += (r+1)//2
        r = 0
        
for j in range(len(s)-1, -1, -1):
    l += 1
    if s[j] == 'R':
        a[j+1] += l//2
        a[j] += (l+1)//2
        l = 0
    a[j] -= 1

print(*a)
Buggy code:
from itertools import groupby
S = input()
A = [len(list(it)) for s, it in groupby(S)]
B = [[0]*(n1-1)+[(n1+1)//2+n2//2]+[n1//2+(n2+1)//2]+[0]*(n2-1)
     for n1, n2 in zip(A[::2], A[1::2])]
print(*sum(B, []))from itertools import groupby
S = input()
A = [len(list(it)) for s, it in groupby(S)]
for n1, n2 in zip(A[::2], A[1::2]):
    print(*([0]*(n1-1)+[(n1+1)//2+n2//2]+[n1//2+(n2+1)//2]+[0]*(n2-1)), end=" ")

Fixed code:
from itertools import groupby
S = input()
A = [len(list(it)) for s, it in groupby(S)]
for n1, n2 in zip(A[::2], A[1::2]):
    print(*([0]*(n1-1)+[(n1+1)//2+n2//2]+[n1//2+(n2+1)//2]+[0]*(n2-1)), end=" ")
Buggy code:
S = input()

even = 0
odd = 0
l = S.index('L')
r = S.index('R')
ans = [0] * len(S)

for i in range(len(S) - 1):
    if i % 2 == 0:
        even += 1
    else:
        odd += 1
    if S[i] == 'R' and S[i + 1] == 'L':
        l = i
        r = i + 1
        if i % 2 == 0:
            ans[i] += even
            ans[i + 1] += odd
        else:
            ans[i] += odd
            ans[i + 1] += even
        even = 0
        odd = 0
    elif S[i] == 'L' and S[i + 1] == 'R':
        if l % 2 == 0:
            ans[l] += even
            ans[l + 1] += odd
        else:
            ans[l] += odd
            ans[l + 1] += even
        even = 0
        odd = 0


if (len(S) - 1 - l) % 2 == 0:
    ans[l] += 1
else:
    ans[r] += 1

if l % 2 == 0:
    ans[l] += even
    ans[l + 1] += odd
else:
    ans[l] += odd
    ans[l + 1] += even

print(''.join(map(str, ans)))

Fixed code:
S = input()

even = 0
odd = 0
l = S.index('L')
r = S.index('R')
ans = [0] * len(S)

for i in range(len(S) - 1):
    if i % 2 == 0:
        even += 1
    else:
        odd += 1
    if S[i] == 'R' and S[i + 1] == 'L':
        l = i
        r = i + 1
        if i % 2 == 0:
            ans[i] += even
            ans[i + 1] += odd
        else:
            ans[i] += odd
            ans[i + 1] += even
        even = 0
        odd = 0
    elif S[i] == 'L' and S[i + 1] == 'R':
        if l % 2 == 0:
            ans[l] += even
            ans[l + 1] += odd
        else:
            ans[l] += odd
            ans[l + 1] += even
        even = 0
        odd = 0


if (len(S) - 1 - l) % 2 == 0:
    ans[l] += 1
else:
    ans[r] += 1

if l % 2 == 0:
    ans[l] += even
    ans[l + 1] += odd
else:
    ans[l] += odd
    ans[l + 1] += even

print(' '.join(map(str, ans)))
Buggy code:
from math import ceil
import re
S = input()
N = len(S)

X = re.findall('R+L+', S)
ans = [0] * N

print(X)
i = 0
for x in X:
    x_len = len(x)
    start = x.find('RL')

    ans[i + start] += (x_len - start - 1) // 2 + ceil((start + 1) / 2)
    ans[i + start + 1] += (start + 1) // 2 + ceil((x_len - start - 1) / 2)

    i += x_len

print(*ans, sep=' ')


Fixed code:
from math import ceil
import re
S = input()
N = len(S)

X = re.findall('R+L+', S)
ans = [0] * N

i = 0
for x in X:
    x_len = len(x)
    start = x.find('RL')

    ans[i + start] += (x_len - start - 1) // 2 + ceil((start + 1) / 2)
    ans[i + start + 1] += (start + 1) // 2 + ceil((x_len - start - 1) / 2)

    i += x_len

print(*ans, sep=' ')
Buggy code:
s = input()
n = len(s)
rl = 0
lr = 0
count = [0, 0]
ans = [0] * n
prev = s[0]
for i in range(n):
    if s[i] != prev:
        if s[i] == 'L':
            rl = i
            ans[rl - 1] += count[0]
            ans[rl] += count[1]
            count = [0, 0]
            print(ans)
        if s[i] == 'R':
            lr = i
            ans[rl] += count[0]
            ans[rl - 1] += count[1]
            count = [0, 0]
            print(ans)
    if s[i] == 'L':
        count[(i - rl) % 2] += 1
    if s[i] == 'R':
        count[(i - lr) % 2] += 1
    prev = s[i]
    print(count)
ans[rl] += count[0]
ans[rl - 1] += count[1]

print(ans)
print(' '.join(map(lambda x: str(x), ans)))








Fixed code:
s = input()
n = len(s)
rl = 0
lr = 0
count = [0, 0]
ans = [0] * n
prev = s[0]
for i in range(n):
    if s[i] != prev:
        if s[i] == 'L':
            rl = i
            ans[rl - 1] += count[0]
            ans[rl] += count[1]
            count = [0, 0]
            #print(ans)
        if s[i] == 'R':
            lr = i
            ans[rl] += count[0]
            ans[rl - 1] += count[1]
            count = [0, 0]
            #print(ans)
    if s[i] == 'L':
        count[(i - rl) % 2] += 1
    if s[i] == 'R':
        count[(i - lr) % 2] += 1
    prev = s[i]
    #print(count)
ans[rl] += count[0]
ans[rl - 1] += count[1]

print(' '.join(map(lambda x: str(x), ans)))
Buggy code:
s = input()
ans = [0]*len(s)
counter = 1
RLSwitch = 0 # if start from "R", 0 else 1
for i in range(1, len(s)):
    if RLSwitch == 0:
        if s[i] == "L":
            pos = i
            if counter % 2 == 1:
                ans[i-1] += counter // 2 + 1
                ans[i] += counter // 2
            else:
                ans[i-1] += counter // 2
                ans[i] += counter // 2
            counter = 1
            RLSwitch = 1
            
        else:
            counter += 1
    
    else:
        if s[i] == "R":
            if counter % 2 == 1:
                ans[pos-1] += counter // 2 
                ans[pos] += counter // 2 + 1
            else:
                ans[pos-1] += counter // 2
                ans[pos] += counter // 2
            counter = 1
            RLSwitch = 0
        else:
            counter += 1
            
        if i == len(s)-1:
            if counter % 2 == 1:
                ans[pos-1] += counter // 2 
                ans[pos] += counter // 2 + 1
            else:
                ans[pos-1] += counter // 2
                ans[pos] += counter // 2            

print(*ans)

Fixed code:
s = input()
ans = [0]*len(s)
counter = 1
RLSwitch = 0 # if start from "R" 0 else 1
for i in range(1, len(s)):
    if RLSwitch == 0: # start from "R"
        if s[i] == "L":
            pos = i
            if counter % 2 == 1:
                ans[i-1] += counter // 2 + 1
                ans[i] += counter // 2
            else:
                ans[i-1] += counter // 2
                ans[i] += counter // 2
            counter = 1
            RLSwitch = 1
            
            if i == len(s)-1:
                ans[i] += 1
        else:
            counter += 1
    
    else: # start from "L"
        if s[i] == "R":
            if counter % 2 == 1:
                ans[pos-1] += counter // 2 
                ans[pos] += counter // 2 + 1
            else:
                ans[pos-1] += counter // 2
                ans[pos] += counter // 2
            counter = 1
            RLSwitch = 0
        else:
            counter += 1
            
        if i == len(s)-1:
            if counter % 2 == 1:
                ans[pos-1] += counter // 2 
                ans[pos] += counter // 2 + 1
            else:
                ans[pos-1] += counter // 2
                ans[pos] += counter // 2            

print(*ans)
Buggy code:
S = input()
ans = [0 for i in range(len(S))]

_Ls = [0 for i in range(len(S))]
_Rs = [0 for i in range(len(S))]
last_L = -1
last_R = -1
for i,s in enumerate(S):
    _Ls[i] = i - last_L-1
    _Rs[i] = i - last_R-1
    if s == 'L':
        last_L = i
    else:
        last_R = i

Ls_ = [0 for i in range(len(S))]
Rs_ = [0 for i in range(len(S))]
last_L = -1
last_R = -1
for i,s in enumerate(reversed(S)):
    Ls_[i] = i - last_L-1
    Rs_[i] = i - last_R-1
    if s == 'L':
        last_L = i
    else:
        last_R = i
Ls_ = [s for s in reversed(Ls_)]
Rs_ = [s for s in reversed(Rs_)]

for i,s in enumerate(S):
    if S[i] == 'L' and S[i-1] == 'R':
        ans[i] = int(Rs_[i]/2) + int(_Ls[i]/2) + 1
    if S[i] == 'R' and S[i+1] == 'L':
        ans[i] = int(Rs_[i]/2) + int(_Ls[i]/2) + 1

print(ans)


Fixed code:
S = input()
ans = [0 for i in range(len(S))]

_Ls = [0 for i in range(len(S))]
_Rs = [0 for i in range(len(S))]
last_L = -1
last_R = -1
for i,s in enumerate(S):
    _Ls[i] = i - last_L-1
    _Rs[i] = i - last_R-1
    if s == 'L':
        last_L = i
    else:
        last_R = i

Ls_ = [0 for i in range(len(S))]
Rs_ = [0 for i in range(len(S))]
last_L = -1
last_R = -1
for i,s in enumerate(reversed(S)):
    Ls_[i] = i - last_L-1
    Rs_[i] = i - last_R-1
    if s == 'L':
        last_L = i
    else:
        last_R = i
Ls_ = [s for s in reversed(Ls_)]
Rs_ = [s for s in reversed(Rs_)]

for i,s in enumerate(S):
    if S[i] == 'L' and S[i-1] == 'R':
        ans[i] = int(Rs_[i]/2) + int(_Ls[i]/2) + 1
    if S[i] == 'R' and S[i+1] == 'L':
        ans[i] = int(Rs_[i]/2) + int(_Ls[i]/2) + 1

print(' '.join(str(i) for i in ans))
Buggy code:
s = input()
n = len(s)

l = []
length = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        length += 1
    else:
        l.append([i, length])
        length = 1
l.append([i+1, length])

res = [0] * n
for i in range(0, len(l), 2):
    if l[i][1] % 2 == 1:
        res[l[i][0]] = (l[i][1] + l[i+1][1] + 1) // 2
        res[l[i][0]+1] = (l[i][1] + l[i+1][1]) // 2
    else:
        res[l[i][0]] = (l[i][1] + l[i+1][1]) // 2
        res[l[i][0]+1] = (l[i][1] + l[i+1][1] + 1) // 2

print(res)

Fixed code:
s = input()
n = len(s)

l = []
length = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        length += 1
    else:
        l.append([i, length])
        length = 1
l.append([i+1, length])

res = [0] * n
for i in range(0, len(l), 2):
    if l[i][1] % 2 == 1:
        res[l[i][0]] = (l[i][1] + l[i+1][1] + 1) // 2
        res[l[i][0]+1] = (l[i][1] + l[i+1][1]) // 2
    else:
        res[l[i][0]] = (l[i][1] + l[i+1][1]) // 2
        res[l[i][0]+1] = (l[i][1] + l[i+1][1] + 1) // 2

for v in res:
    print(v, end=" ")
Buggy code:
S = input().split('LR')
S[0] = S[0][1:]
S[-1] = S[-1][:-1]

ans = []
for s in S:
    s = 'R'+s+'L'
    print(s)
    l = [0]*len(s)
    c = s.find('RL')
    if len(s) % 2 == 0:
        l[c] = len(s)//2
        l[c+1] = len(s)//2
        ans.extend(l)
    else:
        l[c] = len(s)//2+(1-c % 2)
        l[c+1] = len(s)//2+(c % 2)
        ans.extend(l)

print(*ans)


Fixed code:
S = input().split('LR')
S[0] = S[0][1:]
S[-1] = S[-1][:-1]

ans = []
for s in S:
    s = 'R'+s+'L'
    l = [0]*len(s)
    c = s.find('RL')
    if len(s) % 2 == 0:
        l[c] = len(s)//2
        l[c+1] = len(s)//2
        ans.extend(l)
    else:
        l[c] = len(s)//2+(1-c % 2)
        l[c+1] = len(s)//2+(c % 2)
        ans.extend(l)

print(*ans)
Buggy code:
S = input() + "R"
print(S)
N = len(S)-1

ans = [0]*N

num = 0
for i in range(N):
    num += 1
    if S[i+1]=="L" and S[i]=="R":
        ans[i+1] += num//2
        ans[i] += num - num//2
        num = 0
    elif S[i+1]=="R" and S[i]=="L":
        ans[i-num+1] += num - num//2
        ans[i-num] += num//2
        num = 0

print(" ".join(map(str,ans)))

Fixed code:
S = input() + "R"
#print(S)
N = len(S)-1

ans = [0]*N

num = 0
for i in range(N):
    num += 1
    if S[i+1]=="L" and S[i]=="R":
        ans[i+1] += num//2
        ans[i] += num - num//2
        num = 0
    elif S[i+1]=="R" and S[i]=="L":
        ans[i-num+1] += num - num//2
        ans[i-num] += num//2
        num = 0

print(" ".join(map(str,ans)))
Buggy code:
S = input()
T = ''
Z = [0 for i in range(len(S))]
u = []
v = [-1]

for i in range(len(S)-1):
  if S[i] == 'R' and S[i+1] == 'L':
    Z[i] = 1
    Z[i+1] = 1
    u.append(i)
  elif S[i] == 'L' and S[i+1] == 'R':
    v.append(i)
v.append(len(S)-1)

for i in range(len(u)):
  Z[u[i]] = (u[i] - v[i] + 1) // 2 + (v[i+1] - u[i]) // 2
  Z[u[i]+1] = v[i+1] - v[i] - Z[u[i]]

for i in range(len(Z)):  
  print(Z[i], end = '')

Fixed code:
S = input()
T = ''
Z = [0 for i in range(len(S))]
u = []
v = [-1]

for i in range(len(S)-1):
  if S[i] == 'R' and S[i+1] == 'L':
    Z[i] = 1
    Z[i+1] = 1
    u.append(i)
  elif S[i] == 'L' and S[i+1] == 'R':
    v.append(i)
v.append(len(S)-1)

for i in range(len(u)):
  Z[u[i]] = (u[i] - v[i] + 1) // 2 + (v[i+1] - u[i]) // 2
  Z[u[i]+1] = v[i+1] - v[i] - Z[u[i]]

for i in range(len(Z)):  
  print(Z[i], end = ' ')
Buggy code:
S = input()
N = len(S)
ans = [0] * N

T = []
c = 1
p = "R"
for n in range(1, N):
    if S[n] == p:
        c += 1
    else:
        T.append(c)
        c = 1
        p = S[n]
    if n == N-1:
        T.append(c)

print(T)

M = len(T)
for n in range(0, M, 2):
    for _ in range(T[n] - 1):
        print(0, end=" ")
    if (T[n] + T[n+1]) % 2 == 0:
        print((T[n+1] + T[n]) // 2, end=" ")
        print((T[n+1] + T[n]) // 2, end=" ")
    else:
        if max(T[n], T[n+1]) % 2 == 0:
            print(T[n+1], end=" ")
            print(T[n], end=" ")
        else:
            print(T[n], end=" ")
            print(T[n+1], end=" ")

    for _ in range(T[n+1]-1):
        print(0, end=" ")

Fixed code:
S = input()
N = len(S)
ans = [0] * N

T = []
c = 1
p = "R"
for n in range(1, N):
    if S[n] == p:
        c += 1
    else:
        T.append(c)
        c = 1
        p = S[n]
    if n == N-1:
        T.append(c)

M = len(T)
for n in range(0, M, 2):
    for _ in range(T[n] - 1):
        print(0, end=" ")
    
    print((T[n] - 1) // 2 + T[n+1] // 2 + 1 , end=" ")
    print(T[n] // 2 + (T[n+1] - 1) // 2 + 1, end=" ")

    for _ in range(T[n+1]-1):
        print(0, end=" ")
Buggy code:
S=input()

count=0     #R
now="R"
idx=[[],[]]

def goukei(left,right):
    l=0
    r=0
    if left%2==0:
        l+=int(left/2)
        r+=int(left/2)
    else:
        l+=int(left/2)+1
        r+=int(left/2)
    if right%2==0:
        l+=int(right/2)
        r+=int(right/2)
    else:
        l+=int(right/2)
        r+=int(right/2)+1
    return l,r

for i in range(len(S)-1):
    s_left=S[i]
    s_right=S[i+1]
    if s_left=="R" and s_right=="L":
        print("a")
        idx[0].extend([i,i+1])
        left=i-count+1
        count=i+1   #L

        if i==len(S)-2:
            right=i+1-count+1
            l,r=goukei(left, right)
            idx[1].extend([l,r])


    elif s_left=="L" and s_right=="R":
        right=i-count+1
        count=i+1   #R

        l,r=goukei(left, right)
        idx[1].extend([l,r])

    elif i==len(S)-2:
        right=i+1-count+1
        l,r=goukei(left, right)
        idx[1].extend([l,r])

ans=["0" for i in range(len(S))]
for i,j in zip(idx[0],idx[1]):
    ans[i]=str(j)
print(" ".join(ans))

Fixed code:
S=input()

count=0     #R
now="R"
idx=[[],[]]

def goukei(left,right):
    l=0
    r=0
    if left%2==0:
        l+=int(left/2)
        r+=int(left/2)
    else:
        l+=int(left/2)+1
        r+=int(left/2)
    if right%2==0:
        l+=int(right/2)
        r+=int(right/2)
    else:
        l+=int(right/2)
        r+=int(right/2)+1
    return l,r

for i in range(len(S)-1):
    s_left=S[i]
    s_right=S[i+1]
    if s_left=="R" and s_right=="L":
        idx[0].extend([i,i+1])
        left=i-count+1
        count=i+1   #L

        if i==len(S)-2:
            right=i+1-count+1
            l,r=goukei(left, right)
            idx[1].extend([l,r])


    elif s_left=="L" and s_right=="R":
        right=i-count+1
        count=i+1   #R

        l,r=goukei(left, right)
        idx[1].extend([l,r])

    elif i==len(S)-2:
        right=i+1-count+1
        l,r=goukei(left, right)
        idx[1].extend([l,r])

ans=["0" for i in range(len(S))]
for i,j in zip(idx[0],idx[1]):
    ans[i]=str(j)
print(" ".join(ans))
Buggy code:
def play(S, i):
    if S[i] == "L": return i - 1
    else: return i + 1

def solve():
    S = input()
    N = len(S)
    move = 10 ** 100
    
    leftL, rightR = [N-1] * N, [0] * N
    for i in range(1, N):
        if S[i] == "R": rightR[i] = i
        else: rightR[i] = rightR[i-1]
        if S[N-i-1] == "L": leftL[N-i-1] = N-i-1
        else: leftL[N-i-1] = leftL[N-i]

    print(leftL)
    print(rightR)
    count =[0] * N

    for i in range(N):
        if S[i] == "R":
            moved = leftL[i] - i
            #print(moved)
            if moved % 2 == 0: count[leftL[i]] += 1
            else: count[leftL[i] - 1] += 1
        else:
            moved = i - rightR[i]
            #print(moved)
            if moved % 2 == 0: count[rightR[i]] += 1
            else: count[rightR[i] + 1] += 1

    print(" ".join(map(str, count)))
    
    return 0

if __name__ == "__main__":
    solve()

Fixed code:
def play(S, i):
    if S[i] == "L": return i - 1
    else: return i + 1

def solve():
    S = input()
    N = len(S)
    move = 10 ** 100
    
    leftL, rightR = [N-1] * N, [0] * N
    for i in range(1, N):
        if S[i] == "R": rightR[i] = i
        else: rightR[i] = rightR[i-1]
        if S[N-i-1] == "L": leftL[N-i-1] = N-i-1
        else: leftL[N-i-1] = leftL[N-i]

    #print(leftL)
    #print(rightR)
    count =[0] * N

    for i in range(N):
        if S[i] == "R":
            moved = leftL[i] - i
            #print(moved)
            if moved % 2 == 0: count[leftL[i]] += 1
            else: count[leftL[i] - 1] += 1
        else:
            moved = i - rightR[i]
            #print(moved)
            if moved % 2 == 0: count[rightR[i]] += 1
            else: count[rightR[i] + 1] += 1

    print(" ".join(map(str, count)))
    
    return 0

if __name__ == "__main__":
    solve()
Buggy code:
import itertools
n,k=map(int, input().split())
A=[int(i) for i in input().split()]
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse = True)
    return divisors
divlis = make_divisors(sum(A))

for res in divlis:
    tmp_add,tmp_sub = 0,0
    tmp = [i%res for i in A]
    tmp += [0]
    tmp.sort()
    tmp = list(itertools.accumulate(tmp))
    for i in range(1,n+1):
        su = tmp[n-i]-tmp[i]
        if(su==0 and tmp[i]<=k):
            print(res)
            exit()


Fixed code:
import itertools
n,k=map(int, input().split())
A=[int(i) for i in input().split()]
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse = True)
    return divisors
divlis = make_divisors(sum(A))

for res in divlis:
    tmp = [i%res for i in A]
    tmp.sort()
    tmp_l = [0]+list(itertools.accumulate(tmp))
    tmp_r = [0]*(n+1)
    
    for i in range(n-1,-1,-1):
        tmp_r[i] = tmp_r[i+1] + res-tmp[i]

    for i in range(n+1):
        if(tmp_l[i]==tmp_r[i] and tmp_l[i]<=k):
            print(res)
            exit()
Buggy code:
import numpy as np

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

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

asum = sum(a)
adiv = make_divisors(asum)
adiv.reverse()

a = np.array(a)
ans = 1
flg = False
for i in adiv:
    a_ = np.sort(a % i)
    # print(i, a_)
    msum = a_.sum()
    msum_ = 0
    for j in range(-1, -n-1, -1):
        msum -= a_[j]
        msum_ += i - a_[j]

        if msum == msum_ :
            ans = i
            flg = True
            break
    if flg:
        break

print(ans)

Fixed code:
import numpy as np

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

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

asum = sum(a)
adiv = make_divisors(asum)
adiv.reverse()

a = np.array(a)
ans = 1
flg = False
for i in adiv:
    a_ = np.sort(a % i)
    # print(i, a_)
    msum = a_.sum()
    msum_ = 0
    for j in range(-1, -n-1, -1):
        msum -= a_[j]
        msum_ += i - a_[j]
        if msum_ > k:
            break
        if msum < msum_:
            break
        if msum == msum_ :
            ans = i
            flg = True
            break
    if flg:
        break

print(ans)
Buggy code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
m=sum(A)
ans=0
for i in range(1,int(m**0.5)+1):
  if m % i != 0:
    continue 
  for j in [i,m//i]:
    stg = []
    for a in A:
      stg.append(a%j)
    stg.sort()
    sm,idx=0,0
    flag=False
    while sm+stg[idx]<=K:
      sm+=stg[idx]
      idx+=1
      if idx>=N:
        flag=True
        break
  #if idx==N-1:
  #  ans=max(ans,i*(i-stg[idx]<=K))
  if flag or sum([j-x for x in stg[idx:]]) <= K:
    ans=max(ans,j)
  
print(ans)
  
  

Fixed code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
m=sum(A)
ans=0
for i in range(1,int(m**0.5)+1):
  if m % i != 0:
    continue 
  for j in [i,m//i]:
    stg = []
    for a in A:
      stg.append(a%j)
    stg.sort()
    sm,idx=0,0
    flag=False
    while sm+stg[idx]<=K:
      sm+=stg[idx]
      idx+=1
      if idx>=N:
        flag=True
        break
    if flag or sum([j-x for x in stg[idx:]]) <= K:
      ans=max(ans,j)
  
print(ans)
Buggy code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=1
A=sum(a)
l=[]
for i in range(2,int(A**(1/2))+1):
    if A%i!=0:continue
    l.append(i)
    if  A// i != i:
        l.append(A // i)
    print(l)
for i in l:
    if A%i!=0:continue
    x=[0]*n
    for j in range(n):
        x[j]=a[j]%i
    s=sum(x)
    l=0
    x.sort(reverse=True)
    for j in range(n):
        if s<=k and l<=k:
            if (s-l)%i==0:
                cnt=i
                break
        l+=i-x[j]
        s-=x[j]

print(cnt)


Fixed code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=1
A=sum(a)
l=[]
for i in range(1,int(A**(1/2))+1):
    if A%i!=0:continue
    l.append(i)
    if  A// i != i:
        l.append(A // i)
for i in l:
    x=[0]*n
    for j in range(n):
        x[j]=a[j]%i
    s=sum(x)
    l=0
    x.sort(reverse=True)
    for j in range(n):
        if s<=k and l<=k:
            if (s-l)%i==0:
                if i>cnt:
                    cnt=i
                break
        l+=i-x[j]
        s-=x[j]

print(cnt)