Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def solver(T):
    if T == "":
        print("YES")
        quit()
    if len(T) >= 5:
        if T[:5] == "dream" or T[:5] == "erase":
            solver(T[5:])
    if len(T) >= 6:
        if T[:6] == "eraser":
            solver(T[6:])
    if len(T) >= 7:
        if T[:7] == "dreamer":
            solver(T[7:])
    return


def main():
    S = input()
    # 再帰的に解いて解く

    solver(S)
    print("NO")
    return


if __name__ == "__main__":
    main()


Fixed submission:
import sys
sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 後ろから貪欲に評価すればよい
    while True:
        if S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue
        elif S[-6:] == "eraser":
            S = S[:-6]
            continue
        elif S[-7:] == "dreamer":
            S = S[:-7]
            continue
        else:
            break
    if S == "":
        print("YES")
    else:
        print("NO")
    return


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 再帰的に解いて解く

    def solver(T):
        if T == "":
            print("YES")
            quit()
        if len(T) >= 5:
            if T[:5] == "dream" or T[:5] == "erase":
                solver(T[5:])
        if len(T) >= 6:
            if T[:6] == "eraser":
                solver(T[6:])
        if len(T) >= 7:
            if T[:7] == "dreamer":
                solver(T[7:])
        return

    solver(S)
    print("NO")
    return


if __name__ == "__main__":
    main()


Fixed submission:
import sys
sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 後ろから貪欲に評価すればよい
    while True:
        if S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue
        elif S[-6:] == "eraser":
            S = S[:-6]
            continue
        elif S[-7:] == "dreamer":
            S = S[:-7]
            continue
        else:
            break
    if S == "":
        print("YES")
    else:
        print("NO")
    return


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys
sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 再帰的に解いて解く

    @lru_cache(None)
    def solver(T):
        if T == "":
            print("YES")
            quit()
        if len(T) >= 5:
            if T[:5] == "dream" or T[:5] == "erase":
                solver(T[5:])
        if len(T) >= 6:
            if T[:6] == "eraser":
                solver(T[6:])
        if len(T) >= 7:
            if T[:7] == "dreamer":
                solver(T[7:])
        return

    solver(S)
    print("NO")
    return


if __name__ == "__main__":
    main()


Fixed submission:
import sys
sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 後ろから貪欲に評価すればよい
    while True:
        if S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue
        elif S[-6:] == "eraser":
            S = S[:-6]
            continue
        elif S[-7:] == "dreamer":
            S = S[:-7]
            continue
        else:
            break
    if S == "":
        print("YES")
    else:
        print("NO")
    return


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 再帰的に解いて解く

    def solver(T):
        if T == "":
            print("YES")
            quit()
        if len(T) >= 5:
            if T[:5] == "dream" or T[:5] == "erase":
                solver(T[5:])
        if len(T) >= 6:
            if T[:6] == "eraser":
                solver(T[6:])
        if len(T) >= 7:
            if T[:7] == "dreamer":
                solver(T[7:])
        return

    solver(S)
    print("NO")
    return


if __name__ == "__main__":
    main()


Fixed submission:
import sys
sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 後ろから貪欲に評価すればよい
    while True:
        if S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue
        elif S[-6:] == "eraser":
            S = S[:-6]
            continue
        elif S[-7:] == "dreamer":
            S = S[:-7]
            continue
        else:
            break
    if S == "":
        print("YES")
    else:
        print("NO")
    return


if __name__ == "__main__":
    main()