Problem p02954 (python)

Fixed submission:
S = str(input())
s_len = len(S)
ans = [0 for _ in range(s_len)]
r_count = 0
l_count = 0
before = 0
switch = 'R'


for i in range(s_len):
    if S[i]==switch:
        if switch == 'R':
            r_count += 1
        else:
            l_count += 1
    else:
        if switch == 'L':
            switch = 'R'
            if (r_count+l_count)%2 == 0:
                ans[before] = (r_count+l_count)//2
                ans[before-1] = (r_count+l_count)//2
            elif r_count%2 == 0:
                ans[before] = (r_count+l_count)//2+1
                ans[before-1] = (r_count+l_count)//2
            else:
                ans[before] = (r_count+l_count)//2
                ans[before-1] = (r_count+l_count)//2+1
            r_count = 1
            l_count = 0
        else:
            switch = 'L'
            before = i
            l_count = 1


if (r_count+l_count)%2 == 0:
    ans[before] = (r_count+l_count)//2
    ans[before-1] = (r_count+l_count)//2
elif r_count%2 == 0:
    ans[before] = (r_count+l_count)//2+1
    ans[before-1] = (r_count+l_count)//2
else:
    ans[before] = (r_count+l_count)//2
    ans[before-1] = (r_count+l_count)//2+1

print(*ans)

Buggy submission (verdict: Runtime Error):
S = str(input())
s_len = len(S)
ans = [0 for _ in range(s_len)]

def L_checker(n):
    if n+1 == s_len:
        return s_len
    for i in range(n+1,s_len):
        if S[i]=='R':
            return i
    return s_len


def check1(n, r_count):
    if S[n]=='R':
        check1(n+1, r_count+1)
    else:
        next_r = L_checker(n)
        total = r_count+next_r-n
        if total%2==0:
            ans[n-1]=int(total/2)
            ans[n]=int(total/2)
        elif r_count%2==1:
            ans[n-1]=int(total//2)+1
            ans[n]=int(total//2)
        else:
            ans[n-1]=int(total//2)
            ans[n]=int(total//2)+1
        if next_r == s_len:
            print(*ans)
        else:
            check1(next_r,0)

check1(0,0)

Buggy submission (verdict: Runtime Error):
S = str(input())
s_len = len(S)
ans = [0 for _ in range(s_len)]

def L_checker(n):
    if n+1 == s_len:
        return s_len
    for i in range(n+1,s_len):
        if S[i]=='R':
            return i
    return s_len


def check1(n, r_count):
    if S[n]=='R':
        check1(n+1, r_count+1)
    else:
        next_r = L_checker(n)
        total = r_count+next_r-n
        if (total)%2==0:
            ans[n-1]=int((total)/2)
            ans[n]=int((total)/2)
        elif r_count%2==1:
            ans[n-1]=int((total)//2)+1
            ans[n]=int((total)//2)
        else:
            ans[n-1]=int((total)//2)
            ans[n]=int((total)//2)+1
        if next_r == s_len:
            print(*ans)
        else:
            check1(next_r,0)

check1(0,0)

Buggy submission (verdict: Runtime Error):
S = str(input())
s_len = len(S)
ans = [0 for _ in range(s_len)]

def L_checker(n):
    if n+1 == s_len:
        return s_len
    for i in range(n+1,s_len):
        if S[i]=='R':
            return i
    return s_len


def check(n, r_count):
    if S[n]=='R':
        check(n+1, r_count+1)
    else:
        next_r = L_checker(n)
        total = r_count+next_r-n
        if (total)%2==0:
            ans[n-1]=int((total)/2)
            ans[n]=int((total)/2)
        elif r_count%2==1:
            ans[n-1]=int((total)//2)+1
            ans[n]=int((total)//2)
        else:
            ans[n-1]=int((total)//2)
            ans[n]=int((total)//2)+1
        if next_r == s_len:
            print(*ans)
        else:
            check(next_r,0)

check(0,0)

Buggy submission (verdict: Runtime Error):
S = input()
s_len = len(S)
ans = [0 for _ in range(s_len)]

def L_checker(n):
    if n+1 == s_len:
        return s_len

    for i in range(n+1,s_len):
        if S[i]=='R':
            return i
    return s_len


def check(n, r_count):
    if S[n]=='R':
        check(n+1, r_count+1)
    else:
        next_r = L_checker(n)
        total = r_count+next_r-n
        if (total)%2==0:
            ans[n-1]=int((total)/2)
            ans[n]=int((total)/2)
        elif r_count%2==1:
            ans[n-1]=int((total)//2)+1
            ans[n]=int((total)//2)
        else:
            ans[n-1]=int((total)//2)
            ans[n]=int((total)//2)+1
        if next_r == s_len:
            print(*ans)
        else:
            check(next_r,0)

check(0,0)

Buggy submission (verdict: Runtime Error):
S = input()
s_len = len(S)
ans = [0 for _ in range(s_len)]

def L_checker(n):
    for i in range(n+1,s_len):
        if S[i]=='R':
            return i
    return s_len

def check(n, r_count):
    if S[n]=='R':
        check(n+1, r_count+1)
    else:
        next_r = L_checker(n)
        total = r_count+next_r-n
        if (total)%2==0:
            ans[n-1]=int((total)/2)
            ans[n]=int((total)/2)
        elif r_count%2==1:
            ans[n-1]=int((total)//2)+1
            ans[n]=int((total)//2)
        else:
            ans[n-1]=int((total)//2)
            ans[n]=int((total)//2)+1
        if next_r == s_len:
            print(*ans)
        else:
            check(next_r,0)

check(0,0)

Buggy submission (verdict: Runtime Error):
S = input()
s_len = len(S)
ans = [0 for _ in range(s_len)]

def L_checker(n):
    for i in range(n+1,s_len):
        if S[i]=='R':
            return i
    return s_len

def check(n, r_count):
    if S[n]=='R':
        check(n+1, r_count+1)
    else:
        next_r = L_checker(n)
        total = r_count+next_r-n
        if (total)%2==0:
            ans[n-1]=int((total)/2)
            ans[n]=int((total)/2)
        elif r_count%2==1:
            ans[n-1]=int((total)//2)+1
            ans[n]=int((total)//2)
        else:
            ans[n-1]=int((total)//2)
            ans[n]=int((total)//2)+1
        if next_r == s_len:
            print(*ans)
            exit(0)
        check(next_r,0)

check(0,0)