Problem p02954 (python)

Fixed submission:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import OrderedDict, defaultdict
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
#import numba

def run():
    S = input()
    N = len(S)
    group = [[]]
    g = []
    l = []
    init = 0
    indice = 0
    group_num = 0
    ind = [-1] * N
    for k in range(N):
        if S[k] == 'R':
            group[group_num].append(k)
            ind[k] = indice
            indice +=1
            g.append(group_num)
            continue
        else:
            if not init:
                l.append(indice-1)
                init = 1
            if k < N-1 and S[k+1] == 'R':
                group[group_num].append(k)
                g.append(group_num)
                group_num += 1
                group.append([])
                init = 0
                ind[k] = indice
                indice=0
            else:
                group[group_num].append(k)
                g.append(group_num)
                ind[k] = indice
                indice+=1

    #print(group)
    #print(ind)
    #print(l)
    #print(g)
    #print('')
    ret = [0] * N
    for i in range(N):
        _l = l[g[i]]
        indice = ind[i]
        if indice <= _l:
            tmp = group[g[i]][_l + (_l - indice) % 2]
            ret[tmp]+=1
        if indice >= _l+1:
            tmp = group[g[i]][_l + (_l - indice) % 2]
            ret[tmp] += 1
        #print(ret)

    print(' '.join([str(s) for s in ret]))

if __name__ == "__main__":
    run()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import OrderedDict, defaultdict
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
#import numba

def run():
    S = input()
    N = len(S)
    seen = [0] * N
    group = [-1] * N
    dic = {}
    ind = [-1] * N
    for i in range(N):
        if not seen[i]:
            dic[i]=[[], -1]
        else:continue
        x = i
        indice = 0
        while True:
            if seen[x]:break
            group[x] = i
            seen[x] = 1
            ind[x] = indice
            dic[i][0].append(x)
            indice+=1
            if S[x] == 'L':x-=1
            else :x+=1

        dic[i][1] = dic[i][0].index(x)
    #print(dic)
    #print(group)
    #print(ind)

    ret = [0] * N
    for i in range(N):
        indice = ind[i]
        g = group[i]
        L = len(dic[g][0])
        s = dic[g][1]
        if L-s == 1:
            ret[dic[g][0][s]]+=1
        else:
            if indice < s:
                if (s-indice)%2:
                    ret[dic[g][0][s+1]] += 1
                else:
                    ret[dic[g][0][s]] += 1
            else:
                ret[dic[g][0][indice]] += 1

    ret = [str(s) for s in ret]
    print(' '.join(ret))


if __name__ == "__main__":
    run()