Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

def get_divisors(n):
    from math import ceil
    divisors = []
    for num in range(ceil(n**0.5), n+1):
        if n % num == 0:
            divisors.append(n//num)
            if n//num != n:
                divisors.append(num)
    divisors.sort(reverse=True)
    return divisors

total = sum(A)
divisors = get_divisors(total)
ans = -1
for d in divisors:
    R = [a%d for a in A]
    R.sort(reverse=True)
    pr = 0
    nr = -sum(R)
    for i, r in enumerate(R):
        pr += d-r
        nr += r
        if nr+pr >= 0:
            if pr <= K and nr+pr == 0:
                ans = d
            break
    if ans != -1:
        print(ans)
        break
else:
    print(1)


Fixed submission:
S = input()
N = len(S)
cells = [0]*N

seq = 0
for i, s in enumerate(S):
    if s == 'R':
        seq += 1
        cells[i] = seq
        continue
    seq = 0

rev_S = S[::-1]
seq = 0
for i, s in enumerate(rev_S):
    if s == 'L':
        seq += 1
        cells[N-1-i] = seq
        continue
    seq = 0

ans = [0]*N
pre_cell = 0
pre_s = 'R'
l_flag =False
for i, s in enumerate(S):
    cell = cells[i]
    if pre_s == 'R' and s == 'L':
        ans[i] = cell//2 + cell%2 + pre_cell//2
        ans[i-1] = pre_cell//2 + pre_cell % 2 + cell//2
    pre_s = s
    pre_cell = cell

ans_str = ""
for a in ans:
    ans_str += str(a)+" "
print(ans_str)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

def get_divisors(n):
    from math import sqrt, ceil
    divisors = []
    for num in range(ceil(n**0.5), n+1):
        if n % num == 0:
            divisors.append(n//num)
            if n//num != n:
                divisors.append(num)
    divisors.sort(reverse=True)
    return divisors

total = sum(A)
divisors = get_divisors(total)
ans = -1
for d in divisors:
    R = [a%d for a in A]
    R.sort(reverse=True)
    pr = 0
    nr = -sum(R)
    for i, r in enumerate(R):
        pr += d-r
        nr += r
        if nr+pr >= 0:
            if pr <= K and nr+pr == 0:
                ans = d
            break
    if ans != -1:
        print(ans)
        break
else:
    print(1)


Fixed submission:
S = input()
N = len(S)
cells = [0]*N

seq = 0
for i, s in enumerate(S):
    if s == 'R':
        seq += 1
        cells[i] = seq
        continue
    seq = 0

rev_S = S[::-1]
seq = 0
for i, s in enumerate(rev_S):
    if s == 'L':
        seq += 1
        cells[N-1-i] = seq
        continue
    seq = 0

ans = [0]*N
pre_cell = 0
pre_s = 'R'
l_flag =False
for i, s in enumerate(S):
    cell = cells[i]
    if pre_s == 'R' and s == 'L':
        ans[i] = cell//2 + cell%2 + pre_cell//2
        ans[i-1] = pre_cell//2 + pre_cell % 2 + cell//2
    pre_s = s
    pre_cell = cell

ans_str = ""
for a in ans:
    ans_str += str(a)+" "
print(ans_str)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
cells = [0]*N

seq = 0
for i, s in enumerate(S):
    if s == 'R':
        seq += 1
        cells[i] = seq
        continue
    seq = 0

rev_S = S[::-1]
seq = 0
for i, s in enumerate(rev_S):
    if s == 'L':
        seq += 1
        cells[N-1-i] = seq
        continue
    seq = 0

ans = [0]*N
pre_cell = 0
pre_s = 'R'
l_flag =False
for i, s in enumerate(S):
    cell = cells[i]
    if pre_s == 'R' and s == 'L':
        ans[i] = cell//2 + cell%2 + pre_cell//2
        ans[i-1] = pre_cell//2 + pre_cell % 2 + cell//2
    pre_s = s
    pre_cell = cell

ans_str = ""
for a in ans:
    ans_str += str(a)+" "
print(ans_str)

Fixed submission:
S = input()
N = len(S)
cells = [0]*N

seq = 0
for i, s in enumerate(S):
    if s == 'R':
        seq += 1
        cells[i] = seq
        continue
    seq = 0

rev_S = S[::-1]
seq = 0
for i, s in enumerate(rev_S):
    if s == 'L':
        seq += 1
        cells[N-1-i] = seq
        continue
    seq = 0

ans = [0]*N
pre_cell = 0
pre_s = 'R'
l_flag =False
for i, s in enumerate(S):
    cell = cells[i]
    if pre_s == 'R' and s == 'L':
        ans[i] = cell//2 + cell%2 + pre_cell//2
        ans[i-1] = pre_cell//2 + pre_cell % 2 + cell//2
    pre_s = s
    pre_cell = cell

ans_str = ""
for a in ans:
    ans_str += str(a)+" "
print(ans_str)