qyliang/CodeNanoFix huggingface dataset:
Buggy code:
S = list(input())
S.reverse()
S = "".join(S)
ans = "YES"
while len(S) > 0:
        print(S)
        if S[:5] == "maerd" or S[:5] == "esare":
                S = S[5:]
        elif S[:6] == "resare":
                S = S[6:]
        elif S[:7] == "remaerd":
                S = S[7:]
        else:
                ans = "NO"
                break
print(ans)

Fixed code:
S = list(input())
S.reverse()
S = "".join(S)
ans = "YES"
while len(S) > 0:
        if S[:5] == "maerd" or S[:5] == "esare":
                S = S[5:]
        elif S[:6] == "resare":
                S = S[6:]
        elif S[:7] == "remaerd":
                S = S[7:]
        else:
                ans = "NO"
                break
print(ans)
Buggy code:
s = input()
s_reverse = ''.join(list(reversed(s)))
t = ''

while True:
    n = len(t)
    if s_reverse == t:
        print('YES')
        break
    if len(s) > n:
        print('NO')
        break
    if s_reverse[n] == 'm':
        t += ''.join(list(reversed('dream')))
    elif s_reverse[n] == 'e':
        t += ''.join(list(reversed('erase')))
    elif s_reverse[n:n+3] == 'rem':
        t += ''.join(list(reversed('dreamer')))
    elif s_reverse[n:n+3] == 'res':
        t += ''.join(list(reversed('eraser')))
    else:
        print('NO')
        break

Fixed code:
s = input()
s_reverse = ''.join(list(reversed(s)))
t = ''

while True:
    n = len(t)
    if s_reverse == t:
        print('YES')
        break
    if len(s) <= n:
        print('NO')
        break
    if s_reverse[n] == 'm':
        t += ''.join(list(reversed('dream')))
    elif s_reverse[n] == 'e':
        t += ''.join(list(reversed('erase')))
    elif s_reverse[n:n+3] == 'rem':
        t += ''.join(list(reversed('dreamer')))
    elif s_reverse[n:n+3] == 'res':
        t += ''.join(list(reversed('eraser')))
    else:
        print('NO')
        break
Buggy code:
S = input()
T = ''

S = S[::-1]
words = ["dream","dreamer","erase","eraser"]
rev_words = [w[::-1] for w in words]

i=0
while(1):
	for w in rev_words:
		s = S[i:i+len(w)]
		if s == w:
			flag = True
			T += w
			i += len(w)
			break
	if T == S:
		ans = "YES"
		break
	if flag == False:
		ans = 'NO'
		break
	flag = False

print(ans)

Fixed code:
#ABC 049 C
S = input()
T = ''
S = S[::-1]
words = ["dream","dreamer","erase","eraser"]
rev_words = [w[::-1] for w in words]

flag = False
i=0
while(1):
	for w in rev_words:
		s = S[i:i+len(w)]
		if s == w:
			flag = True
			T += w
			i += len(w)
			break
	if T == S:
		ans = "YES"
		break
	if flag == False:
		ans = 'NO'
		break
	flag = False

print(ans)
Buggy code:
s = input()
sr = s[::-1]
words = [w[::-1] for w in ('dream','dreamer','erase','eraser')]

f = 0
while f == 0:  
  f = 1
  for w in words_r:
    if sr[0:len(w)] == w:
      sr = sr[len(w):]
      f = 0
  
if sr =='':
  print('YES')
else:
  print('NO')
  

Fixed code:
s = input()
sr = s[::-1]
words = [w[::-1] for w in ('dream','dreamer','erase','eraser')]

f = 0
while f == 0:  
  f = 1
  for w in words:
    if sr[0:len(w)] == w:
      sr = sr[len(w):]
      f = 0
  
if sr =='':
  print('YES')
else:
  print('NO')
Buggy code:
S = input()
S.replace("dreamer", "").replace("eraser","").replace("dream","").replace("erase", "")
if len(S) == 0:
  print("YES")
else:
  print("NO")


Fixed code:
S = input()

result = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if len(result) == 0:
    print("YES")
else:
    print("NO")
Buggy code:
# Me
def check(s):
    words = [
            'dream',
            'dreamer',
            'erase',
            'eraser',
            ]

    while len(s) == 0:
        flag = False
        for w in words:
            if s[-len(w):] == w:
                s = s[:-len(w)]
                flag = True
                break
        if not flag:
            return 'NO'
    return 'YES'


print(check(input()))


Fixed code:
# Me
def check(s):
    words = [
            'dream',
            'dreamer',
            'erase',
            'eraser',
            ]

    while len(s) != 0:
        flag = False
        for w in words:
            if s[-len(w):] == w:
                s = s[:-len(w)]
                flag = True
                break
        if not flag:
            return 'NO'
    return 'YES'


print(check(input()))
Buggy code:
def check(s):
    s = s.replace('dream', '')
    s = s.replace('dreamer', '')
    s = s.replace('erase', '')
    s = s.replace('eraser', '')
    if s != '':
        return 'NO'
    return 'YES'


s = input()
print(check(s))


Fixed code:
def check(s):
    s = s.replace('eraser', '')
    s = s.replace('erase', '')
    s = s.replace('dreamer', '')
    s = s.replace('dream', '')
    if len(s) != 0:
        return 'NO'
    return 'YES'


print(check(input()))
Buggy code:
S = input()

partstrs = ["eraser", "erase", "dreamer", "dream"]

for s in partstrs:
    S = S.replace(s , "") 
if S=="":
    print("YES")
else:
    print("N")

Fixed code:
S = input()

partstrs = ["eraser", "erase", "dreamer", "dream"]

for s in partstrs:
    S = S.replace(s , "") 
if S=="":
    print("YES")
else:
    print("NO")
Buggy code:
import sys

S = input()

while S:
    prefix = S[0:5]
    if prefix == 'dream':
        if S[5:7] == 'er':
            if len(S) > 8 and S[7] == 'a':
                S = S[5:]
            else:
                S = S[7:]
        else:
            S = S[5:]
    elif prefix == 'erase':
        if len(S) > 6 and S[5] == 'r':
            S = S[6:]
        else:
            S = S[5:]
    else:
        print('NO')
        sys.exit(0)
    # print(S)
print('YES')


Fixed code:
import sys

S = input()

while S:
    prefix = S[0:5]
    if prefix == 'dream':
        if S[5:7] == 'er':
            if len(S) >= 8 and S[7] == 'a':
                S = S[5:]
            else:
                S = S[7:]
        else:
            S = S[5:]
    elif prefix == 'erase':
        if len(S) >= 6 and S[5] == 'r':
            S = S[6:]
        else:
            S = S[5:]
    else:
        print('NO')
        sys.exit(0)
    # print(S)
print('YES')
Buggy code:
S = input()
S = S[::-1]
divide = list(map(lambda phrase:phrase[::-1], ['dream', 'dreamer', 'erase', 'eraser']))
print(divide)

flag = False
i = 0
while i != len(S):
    for d in divide:
        if S[i:i+len(d)] == d:
            flag = True
            i += len(d)
            break

print('YES' if flag else 'NO')


Fixed code:
S = input()
S = S[::-1]
divide = list(map(lambda phrase:phrase[::-1], ['dream', 'dreamer', 'erase', 'eraser']))

flag = False
i = 0
while i != len(S):
    flag = False
    for d in divide:
        if S[i:i+len(d)] == d:
            flag = True
            i += len(d)
            break

    if flag == False:
        break

print('YES' if flag else 'NO')
Buggy code:
s=input()
ind =0
len_s=len(s)
s = s+ "zzzzzzzzzz"

A = "dreamer"
B= "dream"
C= "erase"
D="eraser"

flag =True
while(1):
    if(s[ind] =="d"):
        if(s[ind + 7] !="a"):
            if(s[ind:ind+7]!=A):
                flag = False
                break
            else:
                ind+=7
        else:
            if(s[ind:ind+5] !=B):
                flag = False
                break
            else:
                ind+=5
    elif(s[ind]=="e"):
        if(s[ind+5]=="r"):
            if(s[ind:ind+6]!=D):
                flag = False
                break
            else:
                ind+=6

        else:
            if(s[ind:ind +5] !=C):
                flag =False
                break
            else:
                ind+=5
    else:
        flag=False
        break
    if(ind == len_s):
        break
    if(ind > len(s)):
        flag=False
        break
if(flag):
    print("YES")
else:
    print("NO")



Fixed code:
s=input()
ind =0
len_s=len(s)
s = s+ "AAAAAAAAA"

A = "dreamer"
B= "dream"
C= "erase"
D="eraser"

flag =True
while(1):
    if(s[ind] =="d"):
        if(s[ind + 5] =="d"):
            if(s[ind:ind+5]!=B):
                flag = False
                break
            else:
                ind+=5
        else:
            if(s[ind+5]!='e' and s[ind+5]!='A'):
                flag=False
                break
            if(s[ind+7] == "a" or ind + 7 >len_s):
                if(s[ind:ind+5]!=B):
                    flag = False
                    break
                else:
                    ind+=5

            else:
                if(s[ind:ind+7] !=A):
                    flag = False
                    break
                else:
                    ind+=7
    elif(s[ind]=="e"):
        if(s[ind+5]=="r"):
            if(s[ind:ind+6]!=D):
                flag = False
                break
            else:
                ind+=6

        else:
            if(s[ind:ind +5] !=C):
                flag =False
                break
            else:
                ind+=5
    else:
        flag=False
        break
    if(ind == len_s):
        break
    if(ind > len_s):
        flag=False
        break
if(flag):
    print("YES")
else:
    print("NO")
Buggy code:
S0 = input()
S = S0[::-1]
cands = ["dream"[::-1],"dreamer"[::-1],"erase"[::-1],"eraser"[::-1]]
i = 0
while i < len(S):
  f = False
  for word in cands:
    #print(S[i:],word)
    if S[i:].startswith(word):
        f = True
    	i += len(word)
    	break
  if f = False:
    print("NO")
    exit(0)
#print(i)
if i == len(S):
  print("YES")
else:
  print("NO")


Fixed code:
S0 = input()
S = S0[::-1]
cands = ["dream"[::-1],"dreamer"[::-1],"erase"[::-1],"eraser"[::-1]]
i = 0
while i < len(S):
  f = False
  for word in cands:
    #print(S[i:],word)
    if S[i:].startswith(word):
        f = True
        i += len(word)
        break
  if f == False:
    print("NO")
    exit(0)
#print(i)
if i == len(S):
  print("YES")
else:
  print("NO")
Buggy code:
import sys
input = sys.stdin.readline
S = input().rstrip()

while S:
    if S[-5:] == "dream":
        S = S[:-5]
    elif S[-5] == "erase":
        S = S[:-5]
    elif S[-6:] == "eraser":
        S = S[:-6]
    elif S[-7:] == "dreamer":
        S = S[:-7]
    else:
        print("NO")
        sys.exit()
print("YES") 




Fixed code:
import sys
input = sys.stdin.readline
S = input().rstrip()

while S:
    if S[-5:] == "dream":
        S = S[:-5]
    elif S[-5:] == "erase":
        S = S[:-5]
    elif S[-6:] == "eraser":
        S = S[:-6]
    elif S[-7:] == "dreamer":
        S = S[:-7]
    else:
        print("NO")
        sys.exit()
print("YES")
Buggy code:
S=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
   print("NO")
else:
   print("YES")

Fixed code:
s = input()
x = s.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if x:
    print("NO")
else:
    print("YES")
Buggy code:
S=input()
flag=0
S=S.replace("dreamer", "0")
S=S.replace("eraser", "0")
S=S.replace("dream", "0")
S=S.replace("erase", "0")
S=S.replace("0", "")
if S=="":
    print("YES")
else:
    print("NO")


Fixed code:
S = input()
S = S.replace("eraser","")
S = S.replace("erase", "")
S = S.replace("dreamer","")
S = S.replace("dream","")
if S:
    print("NO")
else:
    print("YES")
Buggy code:
S = input()
i = 0
while S:
    S = S.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
    i += 1
    if i == 10**5+1:
        print("NO")
        exit()

print("Yes")

Fixed code:
S = input()
i = 0
while S:
    S = S.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
    i += 1
    if i == 10**5+1:
        print("NO")
        exit()

print("YES")
Buggy code:
S = input()

cnt = 0
j = len(S) - 1

for i in range(len(S)-1, -1, -1):
    if j-1 > len("dreamer"):
        break
    for dd in ("dream", "dreamer", "erase", "eraser"):
        if S[i:j+1] == dd:
            j = i-1
            cnt += len(dd)

print(("NO", "YES")[len(S) == cnt])


Fixed code:
S = input()

cnt = 0
j = len(S) - 1

for i in range(len(S) - 1, -1, -1):
    if j - i > len("dreamer"):
        break
    for dd in ("dream", "dreamer", "erase", "eraser"):
        if S[i:j + 1] == dd:
            j = i - 1
            cnt += len(dd)

print(("NO", "YES")[len(S) == cnt])
Buggy code:
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']
T = set([s[::-1] for s in T])

A = ''
for s in S[::-1]:
    A += s
print('YES' if A == '' else 'NO')

Fixed code:
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']
T = set([s[::-1] for s in T])

A = ''
for s in S[::-1]:
    A += s
    if A in T:
        A = ''
print('YES' if A == '' else 'NO')
Buggy code:
s = input()
s_origin = s
t = ""
word_list = ["dream", "dreamer", "erase", "eraser"]
while True:
    if len(s) <= 4:
        break

    flag = True
    s_child_1 = s[:5]
    
    if s_child_1 in word_list:
        t += s[:5]
        s = s[5:]
        flag = False

    if len(s) <= 5:
        break
    
    s_child_2 = s[:6]
    if s_child_2 in word_list:
        t += s[:6]
        s = s[6:]
        flag = False
    if flag:
        break

if s_origin == t:
    print("YES")
else:
    print("NO")
    

Fixed code:
s = input()
s_origin = s
t = ""
word_list = ["dream", "dreamer", "erase", "eraser"]
while True:
    flag = True
    if len(s) <= 4:
        break

    if len(s) == 5:
        s_child_1 = s[-5:]
        if s_child_1 in word_list:
            t = s[-5:] + t
            s = s[:-5]
        break
    
    if len(s) == 6:
        s_child_1 = s[-6:]
        if s_child_1 in word_list:
            t = s[-6:] + t
            s = s[:-6]
        break

    s_child_2 = s[-7:]
    if s_child_2 in word_list:
        t = s[-7:] + t
        s = s[:-7]
        flag = False

    s_child_1 = s[-6:]
    if s_child_1 in word_list:
        t = s[-6:] + t
        s = s[:-6]
        flag = False

    s_child_1 = s[-5:]
    if s_child_1 in word_list:
        t = s[-5:] + t
        s = s[:-5]
        flag = False
    
    if flag:
        break

if s_origin == t:
    print("YES")
else:
    print("NO")
Buggy code:
words = {"dream": "A", "dreamer": "A", "erase": "A", "eraser": "A"}
 
ans = []
 
inputs = str(input())
 
inputs = inputs.replace("eraser", "").replace("erase", "")
inputs = inputs.replace("dreamer", "").replace("dream", "")

print(inputs)

if len(list(inputs)) > 0:
  print("NO")
else:
  print("YES")

Fixed code:
words = {"dream": "A", "dreamer": "A", "erase": "A", "eraser": "A"}
 
ans = []
 
inputs = str(input())
 
inputs = inputs.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")

if len(list(inputs)) > 0:
  print("NO")
else:
  print("YES")
Buggy code:
S = input()[::-1]

words = list(map(lambda s: s[::-1], ['dreamer', 'eraser', 'erase', 'dream']))

while any([w in S for w in words]):
    for w in words:
        if S[:len(w)] == w:
            S = S[len(w):]
            break

print('YES' if len(S) == 0 else 'NO')

Fixed code:
S = input()[::-1]

words = list(map(lambda s: s[::-1], ['dreamer', 'eraser', 'erase', 'dream']))

while True:
    for w in words:
        if S[:len(w)] == w:
            S = S[len(w):]
            break
    else:
        break

print('YES' if len(S) == 0 else 'NO')
Buggy code:
s = input()
now = len(s)
while 1:
    if 7 <= now:
        if s[now-7:now] == "dreamer":
            now -= 7
    if 6 <= now:
        if s[now-6:now] == "eraser":
            now -= 6
    if 5 <= now:    
        if s[now-5:now] == "erase":
            now -= 5
        if s[now-5:now] == "dream":
            now -= 5
    if now == 0:
        print("YES")
        exit()
    elif now < 5:
        print("NO")
        exit()

Fixed code:
s = input()
now = len(s)
while 1:
    flag = 1
    if 7 <= now:
        if s[now-7:now] == "dreamer":
            now -= 7
            flag = 0
    if 6 <= now:
        if s[now-6:now] == "eraser":
            now -= 6
            flag = 0
    if 5 <= now:    
        if s[now-5:now] == "erase":
            now -= 5
            flag = 0
        if s[now-5:now] == "dream":
            now -= 5
            flag = 0
    if flag:
        print("NO")
        exit()
    if now == 0:
        print("YES")
        exit()
    elif now < 5:
        print("NO")
        exit()
Buggy code:
s = input()

while len(s) >= 5:
    if len(s) >= 5 and s[-5:] == 'dream':
        s = s[:-5]

    elif len(s) >= 7 and s[-7:] == 'dreamer':
        s = s[:-7]

    elif len(s) >= 5 and s[-5:] == 'erase':
        s = s[:-5]

    elif len(s) >= 6 and s[-6:] == 'eraser':
        s = s[:-6]

    else:
        break

if len(s) == 0:
    print('YES')
else:
    print('No')


Fixed code:
s = input()

while len(s) >= 5:
    if len(s) >= 5 and s[-5:] == 'dream':
        s = s[:-5]

    elif len(s) >= 7 and s[-7:] == 'dreamer':
        s = s[:-7]

    elif len(s) >= 5 and s[-5:] == 'erase':
        s = s[:-5]

    elif len(s) >= 6 and s[-6:] == 'eraser':
        s = s[:-6]

    else:
        break

if len(s) == 0:
    print('YES')
else:
    print('NO')
Buggy code:
import re

regex = r'(dream|dreamer|erase|eraser)+$'

s = raw_input()

if re.match(regex, s):
  print("YES")
else:
  print("NO")

Fixed code:
import re

regex = r'(dream|dreamer|erase|eraser)+$'

s = input()

if re.match(regex, s):
  print("YES")
else:
  print("NO")
Buggy code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def dfs(seq):
    if seq in ['dreamer', 'dream', 'erase', 'eraser']:
        return True

    if seq[:7] == 'dreamer':
        if dfs[5:] or dfs[7:]:
            return True
        else:
            return False

    elif seq[:5] == 'dream':
        return dfs(seq[5:])

    elif seq[:6] == 'eraser':
        return dfs(seq[6:])

    elif seq[:5] == 'erase':
        return dfs(seq[5:])
    else:
        return False


def run():
    S = input()
    if dfs(S):
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    run()

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

INF = 1 << 50

def dfs(n,seq):
    if seq[n:] in ['dreamer', 'dream', 'erase', 'eraser']:
        return True

    if seq[n:n+7] == 'dreamer':
        if dfs(n+5, seq):
            return True
        elif dfs(n+7, seq):
            return True
        else:
            return False

    elif seq[n:n+5] == 'dream':
        return dfs(n+5, seq)

    elif seq[n:n+6] == 'eraser':
        return dfs(n+6, seq)

    elif seq[n:n+5] == 'erase':
        return dfs(n+5, seq)
    else:
        return False


def run():
    S = input()
    if dfs(0,S):
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    run()
Buggy code:
s=input()[::-1]
words = {"dream", "dreamer", "erase", "eraser"}

while len(s)!=0:
    for i in words:
        l = len(i)
        print(s[0:l], i[::-1])
        if s[0:l] == i[::-1]:
            s = s[l::]
            break
    else:
        break

print("NO"if len(s)!=0else "YES")

Fixed code:
s=input()[::-1]
words = {"dream", "dreamer", "erase", "eraser"}

while len(s)!=0:
    for i in words:
        l = len(i)
        if s[0:l] == i[::-1]:
            s = s[l::]
            break
    else:
        break

print("NO"if len(s)!=0else "YES")
Buggy code:
s=input().replace('dreamer','').replace('dream','').replace('eraser','').replace('erase','')
if s:
  print('NO')
else:
  print('YES')

Fixed code:
s = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if s == '':
    print("YES")
else:
    print("NO")
Buggy code:
s=input()[::-1]
sample=['maerd', 'resare', 'remaerd', 'esare', '']

i=0
while True:
    for d in sample:
        if s[:len(d)] == d:
            s = s[len(d):]
            break
    
    if d =='':
        print ("NO")
        break

    if len(s) ==0:
        print("OK")
        break

Fixed code:
s=input()[::-1]
sample=['maerd', 'resare', 'remaerd', 'esare', '']

i=0
while True:
    for d in sample:
        if s[:len(d)] == d:
            s = s[len(d):]
            break
    
    if d =='':
        print ("NO")
        break

    if len(s) ==0:
        print("YES")
        break
Buggy code:
s = input()

while len(s)>4:
    if s[-5:] == 'dream':
        s = s[:-5]
        continue
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    elif s[-5:] == 'erase':
        s = s[:-5]
        continue
    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue
    else:
        beak
if s =='' :
    print('YES')
else:
    print('NO')
    




Fixed code:
s = input()

while len(s)>4:
    if s[-5:] == 'dream':
        s = s[:-5]
        continue
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    elif s[-5:] == 'erase':
        s = s[:-5]
        continue
    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue
    else:
        break
if len(s)>0 :
    print('NO')
else:
    print('YES')
Buggy code:
import sys
input = sys.stdin.readline

s=input().strip()
n=len(s)
s+="###################################"
i=0
while n-i>=1:
    """print(n-i)
    print(s[i:i+5])"""

    if s[i:i+5]=="dream":
        if s[i+5:i+7]=="er":
            #print(s[i+7:i+11])
            if s[i+7:i+10]=="ase":
                i+=10
            elif s[i+10]=="r":
                i+=11
            else:
                i+=7
        else:
            i+=5

    elif s[i:i+5]=="erase":
        #print(8)
        if s[i+5]=="r":
            i+=6
        else:
            i+=5
    else:
        print("NO")
        exit()
print("YES")


Fixed code:
import sys
input = sys.stdin.readline

s=input().strip()
n=len(s)
s+="###################################"
i=0
while n-i>=1:
    """print(n-i)
    print(s[i:i+5])"""

    if s[i:i+5]=="dream":
        if s[i+5:i+7]=="er":
            #print(s[i+7:i+11])
            if s[i+7:i+10]=="ase":
                if s[i+10]=="r":
                    i+=11
                else:
                    i+=10    
            else:
                i+=7
        else:
            i+=5

    elif s[i:i+5]=="erase":
        #print(8)
        if s[i+5]=="r":
            i+=6
        else:
            i+=5
    else:
        print("NO")
        exit()
print("YES")
Buggy code:
import sys

s = input()

while len(s) != 0:
    if s.endswith('dream') or s.endswith('erase'):
        s = s[:-5]
    elif s.endswith('dreamer') or s.endswith('eraser'):
        s = s[:-7]
    else:
        print('NO')
        sys.exit()

print('YES')


Fixed code:
import sys

s = input()

while len(s) != 0:
    if s.endswith('dream') or s.endswith('erase'):
        s = s[:-5]
    elif s.endswith('eraser'):
        s = s[:-6]
    elif s.endswith('dreamer'):
        s = s[:-7]
    else:
        print('NO')
        sys.exit()

print('YES')
Buggy code:
s=input()

t1='maerd'
t2='remaerd'
t3='esare'
t4='resare'
t=[t1,t2,t3,t4]

s=s[::-1]

ans=0

while True:
    if s.startswith(t1):
        s=s[5::]
    
    elif s.startswith(t2):
        s=s[7::]
      
    elif s.startswith(t3):
        s=s[5::]
 
    elif s.startswith(t4):
        s=s[6::]
        
    elif len(s)==0:
        break
        
    else:
        print('NO')
        ans=1
        break
        
    
        
if ans==0:
    print('Yes')

Fixed code:
s=input()

t1='maerd'
t2='remaerd'
t3='esare'
t4='resare'
t=[t1,t2,t3,t4]

s=s[::-1]

ans=0

while True:
    if s.startswith(t1):
        s=s[5::]
    
    elif s.startswith(t2):
        s=s[7::]
      
    elif s.startswith(t3):
        s=s[5::]
 
    elif s.startswith(t4):
        s=s[6::]
        
    elif len(s)==0:
        break
        
    else:
        print('NO')
        ans=1
        break
        
    
        
if ans==0:
    print('YES')