qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n = int(input())
sum=0
dig = len(list(str(n)))
# print(dig)
for i in range(1,dig+1):
    if i%2==1:
        if i==dig:
            print(n-10**(i-1))
            sum+=(n-10**(i-1)+1)
        else:
            sum+=10**(i-1)*9

print(sum)

Fixed code:
n = int(input())
sum=0
dig = len(list(str(n)))
# print(dig)
for i in range(1,dig+1):
    if i%2==1:
        if i==dig:
            sum+=(n-10**(i-1)+1)
        else:
            sum+=10**(i-1)*9

print(sum)
Buggy code:
N = int(input())
a = 0
i = 1
while N//i != 0:
    if N//(i*10) != 0:
        a += i*10 - i
        i = i*100
    else:
        a = N - i +1
print(a)

Fixed code:
N = int(input())
a = 0
i = 1
while N//i != 0:
    if N//(i*10) != 0:
        a += i*10 - i
        i = i*100
    else:
        a += N - i +1
        i = i*100
print(a)
Buggy code:
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
s = list(rs()+"R")
cnt=0
ans=[0]*(len(s)-1)
for i in range(len(s)-1):
    cnt+=1
    if s[i]=="R" and s[i+1]=="L":
        ans[i]+=cnt-(cnt//2)
        ans[i+1]+=cnt//2
        cnt=0
        hook=i
        continue
    if s[i]=="L" and s[i+1]=="R":
        print(hook)
        ans[hook]+=cnt//2
        ans[hook+1]+=cnt-(cnt//2)
        cnt=0
        continue
print(*ans)


Fixed code:
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
s = list(rs()+"R")
cnt=0
ans=[0]*(len(s)-1)
for i in range(len(s)-1):
    cnt+=1
    if s[i]=="R" and s[i+1]=="L":
        ans[i]+=cnt-(cnt//2)
        ans[i+1]+=cnt//2
        cnt=0
        hook=i
        continue
    if s[i]=="L" and s[i+1]=="R":
        ans[hook]+=cnt//2
        ans[hook+1]+=cnt-(cnt//2)
        cnt=0
        continue
print(*ans)
Buggy code:


s=str(input())
res=[0]*len(s)

nr=0
nl=0

for i in range(len(s)):
  if s[i]=="L":
    nl+=1
    if i==len(s)-1:
      res[i-nl+1]+=(nl+1)//2
      res[i-nl]+=nl//2
    if nr!=0:
      res[i]+=nr//2
      res[i-1]+=(nr+1)//2
    nr=0
  elif s[i]=="R":
    nr+=1    
    if nl!=0:
      res[i-nl]+=(nl+1)//2
      res[i-nl-1]+=nl//2
    nl=0
res=[str(x) for x in res]
print(res)

Fixed code:


s=str(input())
res=[0]*len(s)

nr=0
nl=0

for i in range(len(s)):
  if s[i]=="L":
    nl+=1
    if i==len(s)-1:
      res[i-nl+1]+=(nl+1)//2
      res[i-nl]+=nl//2
    if nr!=0:
      res[i]+=nr//2
      res[i-1]+=(nr+1)//2
    nr=0
  elif s[i]=="R":
    nr+=1    
    if nl!=0:
      res[i-nl]+=(nl+1)//2
      res[i-nl-1]+=nl//2
    nl=0
res=[str(x) for x in res]
print(" ".join(res))
Buggy code:
ll = list(input())

leng = len(ll)
x = [0] * leng

for k in range(leng - 1):
    print(k)
    if ll[k] == 'R' and ll[k + 1] == 'L':
        count_r = 1
        j = k - 1
        while ll[j] == 'R':
            count_r += 1
            j -= 1

        count_l = 0
        j = k + 1
        while ll[j] == 'L':
            count_l += 1
            j += 1
            if j == leng:
                break
        
        x[k] = (count_r + 1) // 2 + count_l // 2
        x[k + 1] = count_r // 2 + (count_l + 1) // 2

x_string = map(str, x)
print(' '.join(x_string))

Fixed code:
ll = list(input())

leng = len(ll)
x = [0] * leng

for k in range(leng - 1):
    if ll[k] == 'R' and ll[k + 1] == 'L':
        count_r = 1
        j = k - 1
        while ll[j] == 'R':
            count_r += 1
            j -= 1

        count_l = 0
        j = k + 1
        while ll[j] == 'L':
            count_l += 1
            j += 1
            if j == leng:
                break
        
        x[k] = (count_r + 1) // 2 + count_l // 2
        x[k + 1] = count_r // 2 + (count_l + 1) // 2

x_string = map(str, x)
print(' '.join(x_string))
Buggy code:
import numpy as np
S = list(input())
cnts = [0]*len(S)
c = 0
for idx in range(len(S)):
    if S[idx] == 'R':
        c += 1
    else:
        cnts[idx] += np.floor(c / 2)
        cnts[idx-1] += np.ceil(c / 2)

c = 0
for i in range(len(S)):
    idx = len(S)-i-1
    if S[idx] == 'L':
        c += 1
    else:
        cnts[idx] += np.floor(c / 2)
        cnts[idx+1] += np.ceil(c / 2)

print(' '.join([str(x) for x in cnts]))


Fixed code:
import numpy as np
S = list(input())
cnts = [0]*len(S)

c = 0
for idx in range(len(S)):
    if S[idx] == 'R':
        c += 1
    else:
        cnts[idx] += np.floor(c / 2)
        cnts[idx-1] += np.ceil(c / 2)
        c = 0

c = 0
for i in range(len(S)):
    idx = len(S)-i-1
    if S[idx] == 'L':
        c += 1
    else:
        cnts[idx] += np.floor(c / 2)
        cnts[idx+1] += np.ceil(c / 2)
        c = 0
        
print(' '.join([str(int(x)) for x in cnts]))
Buggy code:
import sys
def input():
    return sys.stdin.readline()[:-1]

S = list(input())
S.append('R')

ans = []

R_count = 0
L_count = 0
before = 'R'

for R_L in S:
    if before == 'L' and R_L == 'R':
        ans.extend([0]*(R_count-1))
        total = R_count + L_count
        if total % 2 == 0:
            ans.extend([int(total/2), int(total/2)])
        elif total % 2 == 1:
            if R_count % 2 == 1:
                ans.extend([int(total/2) + 1, int(total/2)])
            else:
                ans.extend([int(total/2), int(total/2) + 1])
        ans.extend([0]*(L_count-1))
        R_count = 0
        L_count = 0
    if R_L == 'R':
        R_count += 1
        before = 'R'
    elif R_L == 'L':
        L_count += 1
        before = 'L'

print(ans)

Fixed code:
import sys
def input():
    return sys.stdin.readline()[:-1]

S = list(input())
S.append('R')

ans = []

R_count = 0
L_count = 0
before = 'R'

for R_L in S:
    if before == 'L' and R_L == 'R':
        ans.extend([0]*(R_count-1))
        total = R_count + L_count
        if total % 2 == 0:
            ans.extend([int(total/2), int(total/2)])
        elif total % 2 == 1:
            if R_count % 2 == 1:
                ans.extend([int(total/2) + 1, int(total/2)])
            else:
                ans.extend([int(total/2), int(total/2) + 1])
        ans.extend([0]*(L_count-1))
        R_count = 0
        L_count = 0
    if R_L == 'R':
        R_count += 1
        before = 'R'
    elif R_L == 'L':
        L_count += 1
        before = 'L'

print(*ans)
Buggy code:
S = input()

length = [0] * len(S)
child = [0] * len(S)

index = 0
count = 0
while index < len(S):
  while index < len(S) and S[index] == "R":
    index += 1
  count = 1
  while index < len(S) and S[index] == "L":
    length[index] = -count
    index += 1
    count += 1

index = 0
count = 0
while index < len(S):
  while index < len(S) and S[len(S) - index - 1] == "L":
    index += 1
  count = 1
  while index < len(S) and S[len(S) - index - 1] == "R":
    length[len(S) - index - 1] = count
    index += 1
    count += 1

for i in range(len(S)):
  if length[i] > 0:
    l = length[i] - 1
    child[i + l + l % 2] += 1
  else:
    l = abs(length[i]) - 1
    child[i - l - l % 2] += 1

for i in range(len(S)):
  print(child[i], end="")
print()


Fixed code:
S = input()

length = [0] * len(S)
child = [0] * len(S)

index = 0
count = 0
while index < len(S):
  while index < len(S) and S[index] == "R":
    index += 1
  count = 1
  while index < len(S) and S[index] == "L":
    length[index] = -count
    index += 1
    count += 1

index = 0
count = 0
while index < len(S):
  while index < len(S) and S[len(S) - index - 1] == "L":
    index += 1
  count = 1
  while index < len(S) and S[len(S) - index - 1] == "R":
    length[len(S) - index - 1] = count
    index += 1
    count += 1

for i in range(len(S)):
  if length[i] > 0:
    l = length[i] - 1
    child[i + l + l % 2] += 1
  else:
    l = abs(length[i]) - 1
    child[i - l - l % 2] += 1

for i in range(len(S)):
  print(child[i], end="")
  if i != len(S) - 1:
    print(" ", end="")
print()
Buggy code:
S = list(input())
print(S)

N = len(S)

ans = [0]*N

for _ in range(2):
    cnt = 0
    for i in  range(len(S)):
        if S[i] =='R':cnt +=1
        else:
            ans[i] += int(cnt/2)
            ans[i-1] += int((cnt+1)/2)
            cnt = 0

    S.reverse()
    ans.reverse()
    for i in range(len(S)):
        if S[i] == 'L':
            S[i] ='R'
        else:
            S[i] = 'L'

print(*ans)

Fixed code:
S = list(input())

N = len(S)

ans = [0]*N

for _ in range(2):
    cnt = 0
    for i in  range(len(S)):
        if S[i] =='R':cnt +=1
        else:
            ans[i] += int(cnt/2)
            ans[i-1] += int((cnt+1)/2)
            cnt = 0

    S.reverse()
    ans.reverse()
    for i in range(len(S)):
        if S[i] == 'L':
            S[i] ='R'
        else:
            S[i] = 'L'

print(*ans)
Buggy code:
s = input()
r_cnt = 0
l_cnt = 0
lst = [0 for _ in range(len(s))]
for i in range(len(s)):
  if s[i] == 'R' and l_cnt == 0:
    r_cnt += 1
  elif s[i] == 'L':
    l_cnt += 1
    if r_cnt % 2 == 0:
      lst[i] += r_cnt // 2
      lst[i-1] += r_cnt // 2
    else:
      lst[i] += r_cnt // 2
      lst[i-1] += r_cnt // 2 + 1
    r_cnt = 0
  elif s[i] == 'R' and l_cnt > 0:
    r_cnt += 1
    if l_cnt % 2 == 0:
      lst[i-1] += l_cnt // 2
      lst[i-2] += l_cnt // 2
    else:
      lst[i-1] += l_cnt // 2 + 1
      lst[i-2] += l_cnt // 2
    l_cnt = 0
print(*lst)
      
    

Fixed code:
s = input()
r_cnt = 0
l_cnt = 0
lst = [0 for _ in range(len(s))]
s += 'R'
for i in range(len(s)):
  if s[i] == 'R' and l_cnt == 0:
    r_cnt += 1
  elif s[i] == 'L' and r_cnt > 0:
    l_cnt += 1
    if r_cnt % 2 == 0:
      lst[i] += r_cnt // 2
      lst[i-1] += r_cnt // 2
    else:
      lst[i] += r_cnt // 2
      lst[i-1] += r_cnt // 2 + 1
    r_cnt = 0
    ind = i
  elif s[i] == 'L' and r_cnt == 0:
    l_cnt += 1
  elif s[i] == 'R' and l_cnt > 0:
    r_cnt += 1
    if l_cnt % 2 == 0:
      lst[ind] += l_cnt // 2
      lst[ind-1] += l_cnt // 2
    else:
      lst[ind] += l_cnt // 2 + 1
      lst[ind-1] += l_cnt // 2
    l_cnt = 0
print(*lst)
Buggy code:
import math
S = input()
N = len(S)

count = 0
flug = 0
kiten={}
chukan={}
syuten={}

kiten[count] = 0
for i in range(N-1):
  if S[i] != S[i+1]:
    if flug == 0:
      chukan[count] = i
      flug = 1
    elif flug == 1:
      syuten[count] = i
      flug = 0
      count = count + 1
      kiten[count] = i+1

syuten[count] = N-1

H={}
for j in range(N-1):
  H[j]=0
for j in range(count+1):
  H[chukan[j]]=int(((syuten[j]-kiten[j]+1)+2-1)/2)
  H[chukan[j]+1]=math.floor(((syuten[j]-kiten[j]+1)/2))

for k in range(N-1):
  print(H[k],"",end="")

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

count = 0
flug = 0
kiten={}
chukan={}
syuten={}

kiten[count] = 0
for i in range(N-1):
  if S[i] != S[i+1]:
    if flug == 0:
      chukan[count] = i
      flug = 1
    elif flug == 1:
      syuten[count] = i
      flug = 0
      count = count + 1
      kiten[count] = i+1

syuten[count] = N-1

H={}
for j in range(N):
  H[j]=0
for j in range(count+1):
  if (chukan[j]-kiten[j])%2==0:
    H[chukan[j]]=int(((syuten[j]-kiten[j]+1)+2-1)/2)
    H[chukan[j]+1]=math.floor(((syuten[j]-kiten[j]+1)/2))
  if (chukan[j]-kiten[j])%2==1:
    H[chukan[j]]=math.floor(((syuten[j]-kiten[j]+1)/2))
    H[chukan[j]+1]=int(((syuten[j]-kiten[j]+1)+2-1)/2)
for k in range(N):
  print(H[k],"",end="")
Buggy code:
import math
S = list(input())

N = len(S)
flag = 0
x = 0
y = 0
X = []
Y = [-2]
for n in range(N):
    if flag==0 and S[n]=='R':
        pass
    elif flag==0 and S[n]=='L':
        flag = 1
        Y.append(n-1)
    elif flag==1 and S[n]=='L':
        pass
    else:
        flag = 0
        X.append([x,n-1])
        x = n
X.append([x,N-1])

ans = []
K = len(Y)-1
for k in range(K):
    ans = ans + [0]*(Y[k+1]-Y[k]-2)
    ans = ans + [math.ceil((Y[k+1]-X[k][0]+1)/2) + math.floor((X[k][1]-Y[k+1])/2)]
    ans = ans + [math.floor((Y[k+1]-X[k][0]+1)/2) + math.ceil((X[k][1]-Y[k+1])/2)]
ans = ans + [0]*(N-Y[K]-2)

print(ans)

Fixed code:
from collections import deque 
import math
S = list(input())

N = len(S)
flag = 0
x = 0
y = 0
X = []
Y = [-2]
for n in range(N):
    if flag==0 and S[n]=='R':
        pass
    elif flag==0 and S[n]=='L':
        flag = 1
        Y.append(n-1)
    elif flag==1 and S[n]=='L':
        pass
    else:
        flag = 0
        X.append([x,n-1])
        x = n
X.append([x,N-1])

ans = []
ans = deque(ans)
K = len(Y)-1
for k in range(K):
    ans += [0]*(Y[k+1]-Y[k]-2)
    ans.append(math.ceil((Y[k+1]-X[k][0]+1)/2) + math.floor((X[k][1]-Y[k+1])/2))
    ans.append(math.floor((Y[k+1]-X[k][0]+1)/2) + math.ceil((X[k][1]-Y[k+1])/2))
ans += [0]*(N-Y[K]-2)

print(*ans)
Buggy code:
import sys

input = sys.stdin.readline

S = input().strip()
N = len(S)

crs = list(map(len, S.split('R')))
cls = list(map(len, S.split('L')))
converges=[0] * N

current_index = 0
for cr in crs:
    if cr == 0:
        current_index += 1
    else:
        odd = cr // 2
        even = cr - odd
        converges[current_index - 1] += odd
        converges[current_index] += even
        current_index += cr+1

current_index = N - 1
for cl in cls[::-1]:
    if cl == 0:
        current_index -= 1
    else:
        odd = cl // 2
        even = cl - odd
        converges[current_index + 1] += odd
        converges[current_index] += even
        current_index -= cl + 1

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

Fixed code:
import sys

input = sys.stdin.readline

S = input().strip()
N = len(S)

crs = list(map(len, S.split('R')))
cls = list(map(len, S.split('L')))
converges=[0] * N

current_index = 0
for cr in crs:
    if cr == 0:
        current_index += 1
    else:
        odd = cr // 2
        even = cr - odd
        converges[current_index - 1] += odd
        converges[current_index] += even
        current_index += cr+1

current_index = N - 1
for cl in cls[::-1]:
    if cl == 0:
        current_index -= 1
    else:
        odd = cl // 2
        even = cl - odd
        converges[current_index + 1] += odd
        converges[current_index] += even
        current_index -= cl + 1

print(' '.join(map(str, converges)))
Buggy code:
S = input()
N = len(S)

Rcnt = 0
SR = [0]*N
for i in range(N):
    if S[i] == 'R':
        Rcnt += 1
    elif Rcnt== 0:
        continue
    else:
        SR[i] = Rcnt//2
        SR[i-1] = Rcnt - Rcnt//2
        Rcnt = 0
        
SL = [0]*N
SS = S[-1::-1]
Lcnt = 0
for i in range(N):
    if SS[i] == 'L':
        Lcnt += 1
    elif Lcnt ==0:
        continue
    else:
        SL[i] = Lcnt//2
        SL[i-1] = Lcnt - Lcnt//2
        Lcnt = 0

for i in range(N):
    print(SR[i]+SL[N-i-1], end = "")


Fixed code:
S = input()
N = len(S)

Rcnt = 0
SR = [0]*N
for i in range(N):
    if S[i] == 'R':
        Rcnt += 1
    elif Rcnt== 0:
        continue
    else:
        SR[i] = Rcnt//2
        SR[i-1] = Rcnt - Rcnt//2
        Rcnt = 0
        
SL = [0]*N
SS = S[-1::-1]
Lcnt = 0
for i in range(N):
    if SS[i] == 'L':
        Lcnt += 1
    elif Lcnt ==0:
        continue
    else:
        SL[i] = Lcnt//2
        SL[i-1] = Lcnt - Lcnt//2
        Lcnt = 0

for i in range(N):
    print(SR[i]+SL[N-i-1], end = " ")
Buggy code:
# ABC136D - Gathering Children
def main():
    # children gather on the border of "RL"
    S = input()
    # decompose into partial strings (RR...LL)
    P = S.replace("LR", "L R").split
    ans = []
    for p in P:
        # children on even numbers -> even, odds -> odd
        e, o = len(p) // 2, len(p) // 2 + len(p) % 2
        l, r = (e, o) if p.index("L") % 2 == 0 else (o, e)
        ans += [0] * (p.count("R") - 1) + [l] + [r] + [0] * (p.count("L") - 1)
    print(*ans)


if __name__ == "__main__":
    main()

Fixed code:
# ABC136D - Gathering Children
def main():
    # children gather on the border of "RL"
    S = input()
    # decompose into partial strings (RR...LL)
    P = S.replace("LR", "L R").split()
    ans = []
    for p in P:
        # children on even numbers -> even, odds -> odd
        e, o = len(p) // 2, len(p) // 2 + len(p) % 2
        l, r = (e, o) if p.index("L") % 2 == 0 else (o, e)
        ans += [0] * (p.count("R") - 1) + [l] + [r] + [0] * (p.count("L") - 1)
    print(*ans)


if __name__ == "__main__":
    main()
Buggy code:
s = input()
n = len(s)
r, l = 0, 0
odd, even = 0, 0
ans = [0] * n
for i in range(n):
    if i % 2 == 0:
        even += 1
    else:
        odd += 1
    if i == n - 1 or s[i] != s[i + 1]:
        if s[i] == 'R':
            r, l = i, i + 1
        if (r % 2 == 0 and s[i] == 'R') or (r % 2 == 1 and s[i] == 'L'):
            ans[r] += even
            ans[l] += odd
        else:
            ans[r] += even
            ans[l] += odd
        odd, even = 0, 0
print(*ans, sep=' ')

Fixed code:
s = input()
n = len(s)
r, l = 0, 0
odd, even = 0, 0
ans = [0] * n
for i in range(n):
    if i % 2 == 0:
        even += 1
    else:
        odd += 1
    if i == n - 1 or s[i] != s[i + 1]:
        if s[i] == 'R':
            r, l = i, i + 1
        if r % 2 == 0:
            ans[r] += even
            ans[l] += odd
        else:
            ans[r] += odd
            ans[l] += even
        odd, even = 0, 0
print(*ans, sep=' ')
Buggy code:
def solve():
    S = input()

    s = [0 for _ in range(len(S))]
    for i, si in enumerate(S):
        if si == 'R':
            t = S[i:].index('L')
            if t % 2 == 0:
                s[i+t] += 1
            else:
                s[i+t-1] += 1
        else:
            t = S[:i].rfind('R')
            if (i - t) % 2 == 0:
                s[t] += 1
            else:
                s[t+1] += 1
                
    return s

print(solve())

Fixed code:
def solve():
    S = input()

    s = [0 for _ in range(len(S))]
    for i, si in enumerate(S):
        if si == 'R':
            t = S[i:].index('L')
            if t % 2 == 0:
                s[i+t] += 1
            else:
                s[i+t-1] += 1
        else:
            t = S[:i].rfind('R')
            if (i - t) % 2 == 0:
                s[t] += 1
            else:
                s[t+1] += 1
                
    return s

print(*solve())
Buggy code:

import sys
import math

def main():
    cells = sys.stdin.readline().strip()
    results = [0 for i in range(len(cells))]
    current = 0
    for index in range(len(cells)):
        if cells[index] == 'R':
            current += 1
        elif cells[index] == 'L':
            results[index - 1] += int(math.ceil(current / 2.0))
            results[index] += int(current / 2)
            current = 0
    for index in reversed(range(len(cells))):
        if cells[index] == 'L':
            current += 1
        elif cells[index] == 'R':
            results[index + 1] += int(math.ceil(current / 2.0))
            results[index] += int(current / 2)
            current = 0
    print(results)

if __name__ == "__main__":
    main()

Fixed code:

import sys
import math

def main():
    cells = sys.stdin.readline().strip()
    results = [0 for i in range(len(cells))]
    current = 0
    for index in range(len(cells)):
        if cells[index] == 'R':
            current += 1
        elif cells[index] == 'L':
            results[index - 1] += int(math.ceil(current / 2.0))
            results[index] += int(current / 2)
            current = 0
    for index in reversed(range(len(cells))):
        if cells[index] == 'L':
            current += 1
        elif cells[index] == 'R':
            results[index + 1] += int(math.ceil(current / 2.0))
            results[index] += int(current / 2)
            current = 0
    print(" ".join( [str(i) for i in results]))

if __name__ == "__main__":
    main()
Buggy code:
s=input()
n=len(s)
b=[]
b2=[]
ans=[0 for i in range(n)]

for i in range(n-1):
    if s[i]=='R' and s[i+1]=='L':
        b.append(i)
    if s[i]=='L' and s[i+1]=='R':
        b2.append(i)
       
b2.append(n-1)

cnt=0
for i in range(len(b2)):
    if i==0:
        for j in range(b2[i]+1):
            if((b[i]//2+b[i]-j)%2==0 and s[j]=='R') or ((b[i]//2+b[i]-j)%2==0 and s[j]=='L'):
                ans[b[i]+1]+=1
            else:
                ans[b[i]]+=1
        cnt=b2[i]
    else:
        for j in range(b2[i]-b2[i-1]):
            if((b[i]//2+b[i]-cnt-j-1)%2==0 and s[j+cnt+1]=='R') or ((b[i]//2+b[i]-j-cnt-1)%2==0 and s[j+cnt+1]=='L'):
                ans[b[i]+1]+=1
            else:
                ans[b[i]]+=1
        cnt=b2[i]

for i in range(len(ans)):
    ans[i]=str(ans[i])
print(' '.join(ans))

           

Fixed code:
s=input()
n=len(s)
b=[]
b2=[]
ans=[0 for i in range(n)]

for i in range(n-1):
    if s[i]=='R' and s[i+1]=='L':
        b.append(i)
    if s[i]=='L' and s[i+1]=='R':
        b2.append(i)
       
b2.append(n-1)

cnt=0
for i in range(len(b2)):
    if i==0:
        for j in range(b2[i]+1):
            if (b[i]-j)%2==0:
                ans[b[i]]+=1
            else:
                ans[b[i]+1]+=1
        cnt=b2[i]
    else:
        for j in range(b2[i]-b2[i-1]):
            if (b[i]-cnt-j-1)%2==0:
                ans[b[i]]+=1
            else:
                ans[b[i]+1]+=1
        cnt=b2[i]

for i in range(len(ans)):
    ans[i]=str(ans[i])
print(' '.join(ans))
Buggy code:
s=input()
n=len(s)
ans=[0 for _ in range(n)]
r=ans[:]
p=''
c=0
for i in range(n):
  x=s[i]
  if x=='R':
    if p=='R':
      c+=1
    else:
      c=1
  else:
    if p=='R':
      r[i-1]=c
      c=0
  p=x
r=r[::-1]
s=s[::-1]
for i in range(n):
  x=s[i]
  if x=='L':
    if p=='L':
      c+=1
    else:
      c=1
  else:
    if p=='L':
      r[i-1]=c
      c=0
  p=x
r=r[::-1]
s=s[::-1]
o=ans[:]
e=ans[:]
for i in range(n):
  y=r[i]
  if y!=0:
    x=s[i]
    if x=='R':
      ans[i]+=(y+1)//2
      ans[i+1]+=y//2
    else:
      ans[i-1]+=y//2
      ans[i]+=(y+1)//2
print(ans)

Fixed code:
s=input()
n=len(s)
ans=[0 for _ in range(n)]
r=ans[:]
p=''
c=0
for i in range(n):
  x=s[i]
  if x=='R':
    if p=='R':
      c+=1
    else:
      c=1
  else:
    if p=='R':
      r[i-1]=c
      c=0
  p=x
r=r[::-1]
s=s[::-1]
for i in range(n):
  x=s[i]
  if x=='L':
    if p=='L':
      c+=1
    else:
      c=1
  else:
    if p=='L':
      r[i-1]=c
      c=0
  p=x
r=r[::-1]
s=s[::-1]
o=ans[:]
e=ans[:]
for i in range(n):
  y=r[i]
  if y!=0:
    x=s[i]
    if x=='R':
      ans[i]+=(y+1)//2
      ans[i+1]+=y//2
    else:
      ans[i-1]+=y//2
      ans[i]+=(y+1)//2
print(*ans)
Buggy code:
S = input()
RtoL = []
LtoR = []
for i in range(len(S)-1):
    if S[i] == 'R' and S[i+1] == 'L':
        RtoL.append(i+1)
    elif S[i] == 'L' and S[i+1] == 'R':
        LtoR.append(i+1)
LtoR.append(len(S))
LR_RL = [0]*(len(LtoR))
ans = [0]*len(S)
for i in range(len(LtoR)-1,-1,-1):
    LR_RL[i] = LtoR[i]-RtoL[i]
    if i-1 > -1:
        LtoR[i] = LtoR[i]-LtoR[i-1]
    k = LtoR[len(LtoR)-i-1]
    p = LtoR[len(LtoR)-i-1]//2
    z = RtoL[len(LtoR)-i-1]
    if k%2 ==0:
        ans[z] = p
        ans[z-1] = p
    else:
        if LR_RL[i]%2 == 0:
            ans[z] = p
            ans[z-1] = k-p
        else:
            ans[z] = k-p
            ans[z-1] = p


ans_str = ""
for i in range(len(ans)):
    ans_str += str(ans[i])
    ans_str += " "
    
print(ans_str[0:-1])

Fixed code:
S = input()
RtoL = []
LtoR = []
for i in range(len(S)-1):
    if S[i] == 'R' and S[i+1] == 'L':
        RtoL.append(i+1)
    elif S[i] == 'L' and S[i+1] == 'R':
        LtoR.append(i+1)
LtoR.append(len(S))
LR_RL = [0]*(len(LtoR))
ans = [0]*len(S)
for i in range(len(LtoR)-1,-1,-1):
    LR_RL[i] = LtoR[i]-RtoL[i]
    if i-1 > -1:
        LtoR[i] = LtoR[i]-LtoR[i-1]
    k = LtoR[i]
    p = LtoR[i]//2
    z = RtoL[i]
    if k%2 ==0:
        ans[z] = p
        ans[z-1] = p
    else:
        if LR_RL[i]%2 == 0:
            ans[z] = p
            ans[z-1] = k-p
        else:
            ans[z] = k-p
            ans[z-1] = p


ans_str = ""
for i in range(len(ans)):
    ans_str += str(ans[i])
    ans_str += " "
    
print(ans_str[0:-1])