Problem p02954 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 18:06:22 2019

@author: reira
"""

S = input()
r = 0
l = 0
flag = 0
Ans = [0] * len(S)
for i in range(0, len(S)):
    if  flag == 0:
        if S[i] == "R":
            r += 1
        elif S[i] == "L":
            l += 1
            flag = 1
            r_place = i-1
            if i == len(S)-1:
                if (r+l)%2 == 0:
                    Ans[r_place] = int((r+l)/2)
                    Ans[r_place+1] = int((r+l)/2)
                elif l%2 == 0:
                    Ans[r_place] = int(((r+l)+1)/2)
                    Ans[r_place+1] = int(((r+l)-1)/2)
                else:
                    Ans[r_place] = int(((r+l)-1)/2)
                    Ans[r_place+1] = int(((r+l)+1)/2)
    elif flag == 1:
        if S[i] == "R":
            flag = 0
            if (r+l)%2 == 0:
                Ans[r_place] = int((r+l)/2)
                Ans[r_place+1] = int((r+l)/2)
            elif l%2 == 0:
                Ans[r_place] = int(((r+l)+1)/2)
                Ans[r_place+1] = int(((r+l)-1)/2)
            else:
                Ans[r_place] = int(((r+l)-1)/2)
                Ans[r_place+1] = int(((r+l)+1)/2)
            r = 1
            l = 0
        elif S[i] == "L":
            l += 1
            if i == len(S)-1:
                if (r+l)%2 == 0:
                    Ans[r_place] = int((r+l)/2)
                    Ans[r_place+1] = int((r+l)/2)
                elif l%2 == 0:
                    Ans[r_place] = int(((r+l)+1)/2)
                    Ans[r_place+1] = int(((r+l)-1)/2)
                else:
                    Ans[r_place] = int(((r+l)-1)/2)
                    Ans[r_place+1] = int(((r+l)+1)/2)

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

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 18:06:22 2019

@author: reira
"""

S = input()
r = 0
l = 0
flag = 0
Ans = [0] * len(S)
for i in range(0, len(S)):
    if  flag == 0:
        if S[i] == "R":
            r += 1
        elif S[i] == "L":
            l += 1
            flag = 1
            r_place = i-1
            if i == len(S)-1:
                if (r+l)%2 == 0:
                    Ans[r_place] = int(count/2)
                    Ans[r_place+1] = int(count/2)
                elif l%2 == 0:
                    Ans[r_place] = int((count+1)/2)
                    Ans[r_place+1] = int((count-1)/2)
                else:
                    Ans[r_place] = int((count-1)/2)
                    Ans[r_place+1] = int((count+1)/2)
    elif flag == 1:
        if S[i] == "R":
            flag = 0
            if (r+l)%2 == 0:
                Ans[r_place] = int(count/2)
                Ans[r_place+1] = int(count/2)
            elif l%2 == 0:
                Ans[r_place] = int((count+1)/2)
                Ans[r_place+1] = int((count-1)/2)
            else:
                Ans[r_place] = int((count-1)/2)
                Ans[r_place+1] = int((count+1)/2)
            r = 1
        elif S[i] == "L":
            l += 1
            if i == len(S)-1:
                if (r+l)%2 == 0:
                    Ans[r_place] = int(count/2)
                    Ans[r_place+1] = int(count/2)
                elif l%2 == 0:
                    Ans[r_place] = int((count+1)/2)
                    Ans[r_place+1] = int((count-1)/2)
                else:
                    Ans[r_place] = int((count-1)/2)
                    Ans[r_place+1] = int((count+1)/2)

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