Problem p03854 (python)

Fixed submission:
S = input()
S = S[::-1]
l = ['dream','dreamer','erase','eraser']
L = []
pos = 0
f=True

for i in l:
    L.append(i[::-1])

while pos < len(S):
    no_match = True
    for candidate in L:
        if S[pos:pos+len(candidate)]==candidate:
            pos+=len(candidate)
            no_match =False
            break
    if no_match:
        f =False
        break


if f:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
S = input()
S = S[::-1]
l = ['dream','dreamer','erase','eraser']
L = []
for i in l:
    L.append(i[::-1])
def rec(s):
    flag=False
    for ii in L:
        leng = len(ii)
        if len(s)<leng:
            continue
        else:
            if s[num:leng]==ii:
                if len(s)==leng:
                    flag=True
                    break
                else:
                    return rec(s[leng:])
            else:
                continue
    return flag
f = rec(S)
if f:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
S = input()

S = S[::-1]

l = ['dream','dreamer','erase','eraser']
L = []
for i in l:
    L.append(i[::-1])
num=0
def rec(s):
    flag=False
    for ii in L:
        leng = len(ii)
        if len(s)<leng:
            continue
        else:
            if s[num:leng]==ii:
                if len(s)==leng:
                    flag=True
                    break
                else:
                    return rec(s[leng:])
            else:
                continue
    return flag
f = rec(S)
if f:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
S = input()

S = S[::-1]

l = ['dream','dreamer','erase','eraser']
L = []
for i in l:
    L.append(i[::-1])
print(L)
num=0
def rec(s):
    flag=False
    for ii in L:
        leng = len(ii)
        if len(s)<leng:
            continue
        else:
            if s[num:leng]==ii:
                if len(s)==leng:
                    flag=True
                    break
                else:
                    return rec(s[leng:])
            else:
                continue
    return flag
f = rec(S)
if f:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
S = input()

def rec(s):
    leng = len(s)
    if leng==0:
        print('YES')
    else:
        if leng>4:
            if s[0:5]=="dream":
                if leng==5:
                    rec(s[5:])
                else:
                    if s[5:7]=="er":
                        if s[5:10]=="erase":
                            if leng==10:
                                rec(s[10:])
                            elif s[10]=="r":
                                rec(s[11:])
                            else:
                                rec(s[10:])
                        else:
                            rec(s[7:])
                    else:
                        rec(s[5:])
            elif s[0:5]=="erase":
                if leng==5:
                    rec(s[5:])
                else:
                    if s[5]=="r":
                        rec(s[6:])
                    else:
                        rec(s[5:])
            else:
                print('NO')
        else:
            print('NO')
rec(S)

Buggy submission (verdict: Runtime Error):
S = input()

def rec(s):
    leng = len(s)
    if leng==0:
        print('YES')
    else:
        if s[0:5]=="dream":
            if leng==5:
                rec(s[5:])
            else:
                if s[5:7]=="er":
                    if s[5:10]=="erase":
                        if leng==10:
                            rec(s[10:])
                        elif s[10]=="r":
                            rec(s[11:])
                        else:
                            rec(s[10:])
                    else:
                        rec(s[7:])
                else:
                    rec(s[5:])
        elif s[0:5]=="erase":
            if leng==5:
                rec(s[5:])
            else:
                if s[5]=="r":
                    rec(s[6:])
                else:
                    rec(s[5:])
        else:
            print('NO')
rec(S)

Buggy submission (verdict: Runtime Error):
S = input()

def rec(s):
    leng = len(s)
    if leng==0:
        print('YES')
    else:
        if s[0:5]=="dream":
            if leng==5:
                rec(s[5:])
            else:
                if s[5:7]=="er":
                    if s[5:10]=="erase":
                        if s[10]=="r":
                            rec(s[11:])
                        else:
                            rec(s[10:])
                    else:
                        rec(s[7:])
                else:
                    rec(s[5:])
        elif s[0:5]=="erase":
            if leng==5:
                rec(s[5:])
            else:
                if s[5]=="r":
                    rec(s[6:])
                else:
                    rec(s[5:])
        else:
            print('NO')
rec(S)

Buggy submission (verdict: Runtime Error):
S = input()

def rec(s):
    leng = len(s)
    if leng==0:
        print('YES')
    else:
        if s[0:5]=="dream":
            if leng==5:
                rec(s[5:])
            else:
                if s[5:7]=="er":
                    if s[5:10]=="erase":
                        if s[10]=="r":
                            rec(s[11:])
                        else:
                            rec(s[10:])
                    else:
                        rec(s[7:])
                else:
                    rec(s[5:])
        elif s[0:5]=="erase":
            if leng==5:
                rec(s[5:])
            else:
                if s[5]=="r":
                    rec(s[6:])
                else:
                    rec(s[5:])
        else:
            print('NO')
rec(S)

Buggy submission (verdict: Runtime Error):
S = input()

def rec(s):
    print(s)
    leng = len(s)
    if leng==0:
        print('YES')
    else:
        if s[0:5]=="dream":
            if leng==5:
                rec(s[5:])
            else:
                if s[5:7]=="er":
                    if s[5:10]=="erase":
                        if s[10]=="r":
                            rec(s[11:])
                        else:
                            rec(s[10:])
                    else:
                        rec(s[7:])
                else:
                    print("s:")
                    print(s)
                    rec(s[5:])
        elif s[0:5]=="erase":
            if leng==5:
                rec(s[5:])
            else:
                if s[5]=="r":
                    rec(s[6:])
                else:
                    rec(s[5:])
        else:
            print('NO')
rec(S)