Problem p02954 (python)

Fixed submission:
#from collections import deque
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7

S = str(input())
N = len(S)
ans = [0]*N
k = int(1)
R = []
L = []
rcount = int(1)
lcount = int(0)
lLocate = []
for i in range(1,N):
    if S[i]==S[i-1]:
        if k == 1:
            rcount +=1
        else:
            lcount +=1
    else:
        if k==1:
            R.append(rcount)
            lLocate.append(i-1)
            lcount = int(1)
        else:
            L.append(lcount)
            rcount = int(1)

        k *= (-1)


L.append(lcount)

#print(R)
#print(L)
#print(lLocate)
j = int(0)
#for i in range(N):
#    if i in lLocate:
for i in lLocate:
    r = R[j]
    l = L[j]
    ans[i] = (r+1)//2 + l//2
    ans[i+1] = r//2 + (l+1)//2
    j +=1

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

Buggy submission (verdict: Runtime Error):
S = str(input())
l = len(S)
a = int(0)
b= int(0)
ans = [0]*l
ansc=int(0)
ansv=int(0)
ansi=int(0)

newS = S.split('LR')

k = len(newS)

for i in range(k):
    if i ==0:
        a = newS[i].count('R')
        b = len(newS[i])-a
        ansc = (a+1)//2 + (b+1)//2
        ansv = a//2 + (b)//2 +1
        if 'RL' in newS[i]:
            ansi += newS[i].index('RL')
        else:
            ansi =0
        ans[ansi]=ansc
        ans[ansi+1]=ansv
        ansi += len(newS[i])

    elif i < k-1:
        a = newS[i].count('R')
        b = len(newS[i])-a
        ansc = (a)//2 + (b+1)//2 + 1
        ansv = (a+1)//2 + (b)//2 + 1
        if 'RL' in newS[i]:
            ansi += newS[i].index('RL')+1
        else:
            ansi +=1
        ans[ansi]=ansc
        ans[ansi+1]=ansv
        ansi += (len(newS[i])+1)
    else:
        a = newS[i].count('R')
        b = len(newS[i]) - a
        ansc = (a+1) // 2 + (b+1) // 2
        ansv = (a) // 2 + (b) // 2 + 1
        if 'RL' in newS[i]:
            ansi += newS[i].index('RL')+1
        else:
            ansi += 1
        ans[ansi] = ansc
        ans[ansi + 1] = ansv


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

Buggy submission (verdict: Runtime Error):
S = str(input())
l = len(S)
a = int(0)
b= int(0)
ans = [0]*l
ansc=int(0)
ansv=int(0)
ansi=int(0)

newS = S.split('LR')

k = len(newS)

for i in range(k):
    if i ==0:
        a = newS[i].count('R')
        b = len(newS[i])-a
        ansc = (a+1)//2 + b//2 +1
        ansv = a//2 + (b+1)//2
        ansi += newS[i].index('RL')
        ans[ansi]=ansc
        ans[ansi+1]=ansv
        ansi = len(newS[i])

    elif i < k-1:
        a = newS[i].count('R')
        b = len(newS[i])-a
        ansc = (a)//2 + (b+1)//2 + 1
        ansv = (a+1)//2 + (b)//2 + 1
        if 'RL' in newS[i]:
            ansi += newS[i].index('RL')+1
        else:
            ansi +=1
        ans[ansi]=ansc
        ans[ansi+1]=ansv
        ansi += (len(newS[i])+1)
    else:
        a = newS[i].count('R')
        b = len(newS[i]) - a
        ansc = (a) // 2 + (b+1) // 2
        ansv = (a+1) // 2 + (b) // 2 + 1
        if 'RL' in newS[i]:
            ansi += newS[i].index('RL')+2
        else:
            ansi += 2
        ans[ansi] = ansc
        ans[ansi + 1] = ansv


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

Buggy submission (verdict: Runtime Error):
S = str(input())
l = len(S)
a = int(0)
b= int(0)
ans = [0]*l
ansc=int(0)
ansv=int(0)
ansi=int(0)

newS = S.split('LR')

k = len(newS)

for i in range(k):
    if i ==0:
        a = newS[i].count('R')
        b = len(newS[i])-a
        ansc = (a+1)//2 + b//2 +1
        ansv = a//2 + (b+1)//2
        ansi += newS[i].index('RL')
        ans[ansi]=ansc
        ans[ansi+1]=ansv
        ansi = len(newS[i])

    elif i < k-1:
        a = newS[i].count('R')
        b = len(newS[i])-a
        ansc = (a)//2 + (b+1)//2 + 1
        ansv = (a+1)//2 + (b)//2 + 1
        if 'RL' in newS[i]:
            ansi += newS[i].index('RL')+1
        else:
            ansi +=1
        ans[ansi]=ansc
        ans[ansi+1]=ansv
        ansi += (len(newS[i])+1)
    else:
        a = newS[i].count('R')
        b = len(newS[i]) - a
        ansc = (a) // 2 + (b+1) // 2
        ansv = (a+1) // 2 + (b) // 2 + 1
        ansi += newS[i].index('RL')+2
        ans[ansi] = ansc
        ans[ansi + 1] = ansv


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

Buggy submission (verdict: Runtime Error):
S = str(input())
l = len(S)
a = int(0)
b= int(0)
ans = [0]*l
ansc=int(0)
ansv=int(0)
ansi=int(0)

newS = S.split('LR')

k = len(newS)

for i in range(k):
    if i ==0:
        a = newS[i].count('R')
        b = len(newS[i])-a
        ansc = (a+1)//2 + b//2 +1
        ansv = a//2 + (b+1)//2
        ansi += newS[i].index('RL')
        ans[ansi]=ansc
        ans[ansi+1]=ansv
        ansi = len(newS[i])

    elif i < k-1:
        a = newS[i].count('R')
        b = len(newS[i])-a
        ansc = (a)//2 + (b+1)//2 + 1
        ansv = (a+1)//2 + (b)//2 + 1
        if 'RL' in newS[i]:
            ansi += newS[i].index('RL')+1
        else:
            ansi +=1
        ans[ansi]=ansc
        ans[ansi+1]=ansv
        ansi += (len(newS[i])+1)
    else:
        a = newS[i].count('R')
        b = len(newS[i]) - a
        ansc = (a) // 2 + (b+1) // 2
        ansv = (a+1) // 2 + (b) // 2 + 1
        ansi += newS[i].index('RL')+2
        ans[ansi] = ansc
        ans[ansi + 1] = ansv




print(ans)

Buggy submission (verdict: Runtime Error):
S = str(input())
l = len(S)
a = int(0)
b= int(0)
ans = [0]*l
ansc=int(0)
ansv=int(0)
ansi=int(0)

newS = S.split('LR')

print(newS,len(newS))
k = len(newS)

for i in range(k):
    if i ==0:
        a = newS[i].count('R')
        b = len(newS[i])-a
        print(a,b)
        ansc = (a+1)//2 + b//2 +1
        ansv = a//2 + (b+1)//2
        ansi += newS[i].index('RL')
        ans[ansi]=ansc
        ans[ansi+1]=ansv
        ansi = len(newS[i])

    elif i < k-1:
        a = newS[i].count('R')
        b = len(newS[i])-a
        print(a,b)
        ansc = (a+1)//2 + b//2 + 1
        ansv = a//2 + (b+1)//2 + 1
        if 'RL' in newS[i]:
            ansi += newS[i].index('RL')+1
        else:
            ansi +=1
        ans[ansi]=ansc
        ans[ansi+1]=ansv
        ansi += (len(newS[i])+1)
    else:
        a = newS[i].count('R')
        b = len(newS[i]) - a
        print(a, b)
        ansc = (a + 1) // 2 + b // 2
        ansv = a // 2 + (b + 1) // 2 + 1
        ansi += newS[i].index('RL')+2
        print(newS[i].index('RL'))
        ans[ansi] = ansc
        ans[ansi + 1] = ansv




print(ans)