Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np


def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    i = 0
    while 1:
        temp = []

        for t in T:
            if S[i:len(t) + i] == t:
                i += len(t)

        for t in T:
            temp.append(t in S[i:])
        if any(temp) == False:
            break
    if len(S) != i:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    i = 0
    while 1:
        temp = []
        bool = True
        for t in T:
            if S[i:len(t) + i] == t:
                i += len(t)
                bool = False
        if bool:
            break
    if len(S) != i:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np


def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    while 1:
        temp = []
        for t in T:
            if S[:len(t)] == t:
                S = S[len(t):]
        for t in T:
            temp.append(t in S)
        if any(temp) == False:
            break
    if len(S) > 0:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    i = 0
    while 1:
        temp = []
        bool = True
        for t in T:
            if S[i:len(t) + i] == t:
                i += len(t)
                bool = False
        if bool:
            break
    if len(S) != i:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np


def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    while 1:
        temp = []
        for t in T:
            if ''.join(S[:len(t)]) == t:
                S = S[len(t):]
        for t in T:
            temp.append(t in S)
        if any(temp) == False:
            break
    if len(S) > 0:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    i = 0
    while 1:
        temp = []
        bool = True
        for t in T:
            if S[i:len(t) + i] == t:
                i += len(t)
                bool = False
        if bool:
            break
    if len(S) != i:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np


def main():
    S = input()
    S = S[::-1]
    T = 'dreamer', 'dream', 'eraser', 'erase'
    while 1:
        temp = []
        for t in T:
            t = t[::-1]
            temp.append(t in S)
        if any(temp) == False:
            break
        for t in T:
            t = t[::-1]
            if ''.join(S[:len(t)]) == t:
                S = S[len(t):]

    if len(S) > 0:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    i = 0
    while 1:
        temp = []
        bool = True
        for t in T:
            if S[i:len(t) + i] == t:
                i += len(t)
                bool = False
        if bool:
            break
    if len(S) != i:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    S = list(S[::-1])
    T = 'dreamer', 'dream', 'eraser', 'erase'
    for s in S:
        for t in T:
            t = t[::-1]
            if ''.join(S[:len(t)]) == t:
                S = S[len(t):]

    if len(S) > 0:
        print('NO')
    else:
        print('YES')

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    i = 0
    while 1:
        temp = []
        bool = True
        for t in T:
            if S[i:len(t) + i] == t:
                i += len(t)
                bool = False
        if bool:
            break
    if len(S) != i:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()