Problem p03854 (python)

Fixed submission:
S = input()
S_r = S[::-1]
dire = ['dream','dreamer','erase','eraser']
dire_r = [0]*4
for i in range(4):
    tmp = dire[i]
    dire_r[i] = tmp[::-1]
ind = 0

excep = 0

while ind  <len(S_r):
    if excep == 1:
        break
    flag2= 0
    for j in range(4):
        if flag2 ==0:
            case = 0
            for k in range(len(dire_r[j])):
                tmp = dire_r[j]

                if ind + k < len(S_r) and case == 0:
                #    print(j)
            #        print('S:'+S_r[ind+k])
            #        print('dire:'+tmp[k])
                    if S_r[ind+k] != tmp[k]:
                        flag = 0
                        case = 1
                        if j == 3:
                            excep = 1

                    elif k== len(dire_r[j])  -1:
                        ind = ind + len(dire_r[j])
                        flag = 1
                        case = 1
                        flag2 = 1


if flag == 1:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0
num=0
count = [0]*10000
while True:
    tmp = dire[count[num]]
    ind = i

    #if ind + len(dire[j]) <=len(S)+1:
        #print(j)
    for k in range(len(dire[count[num]])):
        if S[ind] != tmp[k]  or  i + len(dire[count[num]]) >=len(S)+1 :
            flag =0
            count[num]  += 1
            break
        else:
            ind = ind + 1
            if k==len(dire[count[num]])-1:
                i = i + len(dire[count[num]])
                num +=1
                flag = 1


    if   count[num] >= 4 and flag == 0:
        count[num] = 0
        num -= 1
        i = i - len(dire[count[num]])
        if count[num] != 3:
            count[num] += 1
        else:
            count[num] = 0
    if i >= len(S):
        print('YES')
        break
    elif count[0]==0 and flag == 0 and i <=0:
        print('NO')
        break

Buggy submission (verdict: Runtime Error):
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0
num=0
count = [0]*10000
while True:
    tmp = dire[count[num]]
    ind = i

    #if ind + len(dire[j]) <=len(S)+1:
        #print(j)
    for k in range(len(dire[count[num]])):
        if S[ind] != tmp[k]  or  i + len(dire[count[num]]) >=len(S)+1 :
            flag =0
            count[num]  += 1
            break
        else:
            ind = ind + 1
            if k==len(dire[count[num]])-1:
                i = i + len(dire[count[num]])
                num +=1
                flag = 1


    if   count[num] >= 4 and flag == 0:
        count[num] = 0
        num -= 1
        i = i - len(dire[count[num]])
        if count[num] != 3:
            count[num] += 1
        else:
            count[num] = 0
    if i >= len(S):
        print('YES')
        break
    elif count[0]==0 and flag == 0 and i <=0:
        print('NO')
        break

Buggy submission (verdict: Runtime Error):
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0
num=0
count = [0]*100
while True:
    tmp = dire[count[num]]
    ind = i

    #if ind + len(dire[j]) <=len(S)+1:
        #print(j)
    for k in range(len(dire[count[num]])):
        if S[ind] != tmp[k]  or  i + len(dire[count[num]]) >=len(S)+1 :
            flag =0
            count[num]  += 1
            break
        else:
            ind = ind + 1
            if k==len(dire[count[num]])-1:
                i = i + len(dire[count[num]])
                num +=1
                flag = 1


    if   count[num] >= 4 and flag == 0:
        count[num] = 0
        num -= 1
        i = i - len(dire[count[num]])
        if count[num] != 3:
            count[num] += 1
        else:
            count[num] = 0
    if i >= len(S):
        print('YES')
        break
    elif count[0]==0 and flag == 0 and i <=0:
        print('NO')
        break

Buggy submission (verdict: Runtime Error):
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0
num=0
count = [0]*100
while True:

    tmp = dire[count[num]]
    ind = i

    #if ind + len(dire[j]) <=len(S)+1:
        #print(j)
    for k in range(len(dire[count[num]])):
        if S[ind] != tmp[k]  or  i + len(dire[count[num]]) >=len(S)+1 :
            flag =0
            count[num]  += 1
            break
        else:
            ind = ind + 1
            if k==len(dire[count[num]])-1:
                i = i + len(dire[count[num]])
                num +=1
                flag = 1


    if   count[num] >= 4 and flag == 0:
        count[num] = 0
        num -= 1
        i = i - len(dire[count[num]])
        count[num] += 1

    if i >= len(S):
        print('YES')
        break
    elif count[0]==0 and flag == 0 and i <=0:
        print('NO')
        break

Buggy submission (verdict: Runtime Error):
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0

while True:

    tmp = dire[j]
    ind = i

    if ind + len(dire[j]) <=len(S)+1:
        #print(j)
        for k in range(len(dire[j])):
            if S[ind] != tmp[k]:
                flag =0
                j += 1
                break
            else:
                ind = ind + 1
                if k==len(dire[j])-1:
                    i = i + len(dire[j])
                    flag = 1
                    old = len(dire[j])
                    old_j  = j
                    j=0
    else:
        j+=1
        if j==4:
            i=i-old
            j=old_j+1
            flag = 0

    if   j >= 4 and flag == 0 and i != 0:
        i = i - old
        j = old_j+1

    if i >= len(S):
        print('YES')
        break
    elif i <= 0 and j >= 3 and flag == 0:
        print('NO')
        break

Buggy submission (verdict: Runtime Error):
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0

while True:

    tmp = dire[j]
    ind = i

    if ind + len(dire[j]) <=len(S)+1:
        #print(j)
        for k in range(len(dire[j])):
            if S[ind] != tmp[k]:
                flag =0
                j += 1
                break
            else:
                ind = ind + 1
                if k==len(dire[j])-1:
                    i = i + len(dire[j])
                    flag = 1
                    old = len(dire[j])
                    old_j  = j
                    j=0
    else:
        j+=1
        if j==4:
            i=i-old
            j=old_j+1

    if   j >= 4 and flag == 0 and i != 0:
        i = i - old
        j = old_j+1

    if i >= len(S)-1:
        print('YES')
        break
    elif i <= 0 and j >= 3 and flag == 0:
        print('NO')
        break

Buggy submission (verdict: Runtime Error):
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0

while True:

    tmp = dire[j]
    ind = i

    if ind + len(dire[j]) <=len(S)+1:
    #    print(j)
        for k in range(len(dire[j])):

            if S[ind] != tmp[k]:
                flag =0
                j += 1
                break
            else:
                ind = ind + 1
                if k==len(dire[j])-1:
                    i = i + len(dire[j])
                    flag = 1
                    old = len(dire[j])
                    old_j  = j
                    j=0

    if   j >= 4 and flag == 0 and i != 0:
        i = i - old
        j = old_j+1

    if i >= len(S)-1:
        print('YES')
        break
    elif i <= 0 and j >= 3 and flag == 0:
        print('NO')
        break