qyliang/CodeNanoFix huggingface dataset:
Buggy code:
s = input()
i = 0
while True:
	if i == len(s):
		print('YES')
		break
	if len(s) - i < 5:
		print('NO')
		break
	if s[i] == 'd':
		if s[i:i+5] != 'dream':
			print('NO')
			break
		if len(s) - i < 7:
			i += 5
			continue
		if s[i:i+7] != 'dreamer':
			i += 5
			continue
		if len(s) - i == 7 or s[i+7] == 'a':
			i += 7
			continue
		i += 5
		continue
	if s[i] == 'e':
		if s[i:i+5] != 'erase':
			print('NO')
			break
		if len(s) - i < 6:
			i += 5
			continue
		if s[i:i+6] != 'eraser':
			i += 5
			continue
		if len(s) - i == 6 or s[i+6] != 'a':
			i += 6
			continue
		i += 5
		continue
	print('NO')
	break


Fixed code:
s = input()
i = 0
while True:
	if i == len(s):
		print('YES')
		break
	if len(s) - i < 5:
		print('NO')
		break
	if s[i] == 'd':
		if s[i:i+5] != 'dream':
			print('NO')
			break
		if len(s) - i < 7:
			i += 5
			continue
		if s[i:i+7] != 'dreamer':
			i += 5
			continue
		if len(s) - i == 7 or s[i+7] != 'a':
			i += 7
			continue
		i += 5
		continue
	if s[i] == 'e':
		if s[i:i+5] != 'erase':
			print('NO')
			break
		if len(s) - i < 6:
			i += 5
			continue
		if s[i:i+6] != 'eraser':
			i += 5
			continue
		if len(s) - i == 6 or s[i+6] != 'a':
			i += 6
			continue
		i += 5
		continue
	print('NO')
	break
Buggy code:
S = input()
strs = ["erase", "eraser", "dreamer","dream"]
rtss = [s[::-1] for s in strs]
S = S[::-1]

ind = 0
while True:
    print(ind,S[ind])
    if S[ind:ind+5] in rtss:
        ind += 5
    elif S[ind:ind+6] in rtss:
        ind += 6
    elif S[ind:ind+7] in rtss:
        ind +=7
    else:
        print("NO")
        exit()
    if ind == len(S):
        print("YES")
        exit()

Fixed code:
S = input()
strs = ["erase", "eraser", "dreamer","dream"]
rtss = [s[::-1] for s in strs]
S = S[::-1]

ind = 0
while True:
    # print(ind,S[ind])
    if S[ind:ind+5] in rtss:
        ind += 5
    elif S[ind:ind+6] in rtss:
        ind += 6
    elif S[ind:ind+7] in rtss:
        ind +=7
    else:
        print("NO")
        exit()
    if ind == len(S):
        print("YES")
        exit()
Buggy code:
def main():
  s=input()
  q=[0]
  m=len(s)
  l=["dream","dreamer","erase","eraser"]
  while q:
    i=q.pop()
    if i==n:
      print("YES")
      return
    for j in l:
      nj=len(j)
      if i+nj<=m and s[i:i+nj]==j:
        q.append(i+nj)
  print("NO")

main()

Fixed code:
def main():
  s=input()
  q=[0]
  m=len(s)
  l=["dream","dreamer","erase","eraser"]
  while q:
    i=q.pop()
    if i==m:
      print("YES")
      return
    for j in l:
      nj=len(j)
      if i+nj<=m and s[i:i+nj]==j:
        q.append(i+nj)
  print("NO")

main()
Buggy code:
s=input()[::-1]
p=["maerd","remaerd","resare","esare"]
while True:
  if s[:5]==p[0]:s.replace(p[0],"",1)
  elif s[:5]==p[3]:s.replace(p[3],"",1)
  elif s[:7]==p[1]:s.replace(p[1],"",1)
  elif s[:6]==p[2]:s.replace(p[2],"",1)
  else:
    if s=="":print("YES");break
    else:print("NO");break

Fixed code:
s=input()[::-1]
p=["maerd","remaerd","resare","esare"]
while True:
  if s[:5]==p[0]:s=s[5:]
  elif s[:5]==p[3]:s=s[5:]
  elif s[:7]==p[1]:s=s[7:]
  elif s[:6]==p[2]:s=s[6:]
  else:
    if s=="":print("YES");break
    else:print("NO");break
Buggy code:
word=input()

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



while 1:
  if word[len(word)-5:]==wordList[0]:
    word=word[:len(word)-5]
  elif word[len(word)-7:]==wordList[1]:
    word=word[:len(word)-7]
  elif word[len(word)-5:]==wordList[2]:
    word=word[:len(word)-5]
  elif word[len(word)-7:]==wordList[3]:
    word=word[:len(word)-7]
  else:
    print("NO")
    break
  if word=="":
    print("YES")
    break

Fixed code:
word=input()

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



while 1:
  if word[len(word)-5:]==wordList[0]:
    word=word[:len(word)-5]
  elif word[len(word)-7:]==wordList[1]:
    word=word[:len(word)-7]
  elif word[len(word)-5:]==wordList[2]:
    word=word[:len(word)-5]
  elif word[len(word)-6:]==wordList[3]:
    word=word[:len(word)-6]
  else:
    print("NO")
    break
  if word=="":
    print("YES")
    break
Buggy code:
s = input()
s = s[::-1]

w = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]

current_position = 0


while current_position < len(s):
    if s[current_position:current_position+5] == w[0]:
        current_position += 5
    
    elif s[current_position:current_position+7] == w[1]:
        current_position += 7
    
    elif s[current_position:current_position+6] == w[3]:
        current_position += 6
    
    elif s[current_position:current_position+5] == w[2]:
        current_position += 5
    
    else:
        break
    
if current_position == len(s):
    print('YES')


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

w = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]

current_position = 0


while current_position <= len(s):
    if s[current_position:current_position+5] == w[0]:
        current_position += 5
    
    elif s[current_position:current_position+7] == w[1]:
        current_position += 7
    
    elif s[current_position:current_position+6] == w[3]:
        current_position += 6
    
    elif s[current_position:current_position+5] == w[2]:
        current_position += 5
    
    else:
        break
    
if current_position == len(s):
    print('YES')
else:
	print('NO')
Buggy code:
s = input()
while 1:
    if len(S) == 0:
        print("YES")
        break
    if s[len(s)-5:] == "dream":
        s = s[:len(s)-5]
        continue
    elif s[len(s)-7:] == "dreamer":
        s = s[:len(s)-7]
        continue
    elif s[len(s)-5:] == "erase":
        s = s[:len(s)-5]
        continue
    elif s[len(s)-6:] == "eraser":
        s = s[:len(s)-6]
        continue
    else:
        print("NO")
        break
    

Fixed code:
s = input()
while 1:
    if len(s) == 0:
        print("YES")
        break
    if s[len(s)-5:] == "dream":
        s = s[:len(s)-5]
        continue
    elif s[len(s)-7:] == "dreamer":
        s = s[:len(s)-7]
        continue
    elif s[len(s)-5:] == "erase":
        s = s[:len(s)-5]
        continue
    elif s[len(s)-6:] == "eraser":
        s = s[:len(s)-6]
        continue
    else:
        print("NO")
        break
Buggy code:
import numpy as np
import math
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

s = list(input())
s.reverse()
v = []
v.append(list("dream"))
v.append(list("erase"))
v.append(list("eraser"))
v.append(list("dreamer"))
for i in range(4):
    v[i].reverse()

now = 0
while(1):
    check = False
    for i in range(4):
        if now+len(v[i]) > len(s): continue
        tmp = ''.join(s[now:now+len(v[i])])
        x = ''.join(v[i])
        if tmp == x:
            print(tmp, x)
            check = True
            now += len(v[i])
        if check: break
    if not check: break
    if now == len(s): break

if check: print("YES")
else: print("NO")

Fixed code:
import numpy as np
import math
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

s = list(input())
s.reverse()
v = []
v.append(list("dream"))
v.append(list("erase"))
v.append(list("eraser"))
v.append(list("dreamer"))
for i in range(4):
    v[i].reverse()

now = 0
while(1):
    check = False
    for i in range(4):
        if now+len(v[i]) > len(s): continue
        tmp = ''.join(s[now:now+len(v[i])])
        x = ''.join(v[i])
        if tmp == x:
            check = True
            now += len(v[i])
        if check: break
    if not check: break
    if now == len(s): break

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

if len(s.replace('1','')) == 0:
    print("YES")
else :
    print("NO")

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

if s == '':
    print('YES')
else:
    print('NO')


Fixed code:
s = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')

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

Fixed code:
s = input()
t = s.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
print("YES" if len(t) == 0 else "NO")
Buggy code:
S = input()
S = S[::-1]

words = ['dreamer', 'eraser', 'dream', 'erase']
for i in range(4):
    K = words[i]
    words[i] = K[::-1]

T = ''
T_next = ''

while len(T) < len(S):
    if len(T) + 5 > len(S):
        break
    for i in range(4):
        S_next = S[len(T):len(T + words[i])]
        T_next = words[i]
        #print(S_next)
        #print(T_next)
        #print()
        if S_next == T_next:
            T += T_next
            if T == S:
                print('YES')
                exit()
            break

print('NO')



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

words = ['dreamer', 'eraser', 'dream', 'erase']
for i in range(4):
    K = words[i]
    words[i] = K[::-1]

T = ''
T_next = ''

while True:
    if len(T) + 5 > len(S):
        break
    for i in range(4):
        S_next = S[len(T):len(T + words[i])]
        T_next = words[i]
        flag = False
        #print(S_next)
        #print(T_next)
        #print()
        if S_next == T_next:
            flag = True
            T += T_next
            #print(T)
            #print()
            #input()
            if T == S:
                print('YES')
                exit()
            break
    if flag == False:
        break
    #input()

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

Fixed code:
S=input()
while(len(S)>=5):
    if(len(S)>=7 and S[len(S)-7:len(S)]=='dreamer'):
        S=S[:len(S)-7]
    elif(len(S)>=6 and S[len(S)-6:len(S)]=='eraser'):
        S=S[:len(S)-6]
    elif(S[len(S)-5:len(S)]=='dream' or S[len(S)-5:len(S)]=='erase'):
        S=S[:len(S)-5]
    else:
        print("NO")
        exit()
if(len(S)!=0):
    print("NO")
else:
    print("YES")
Buggy code:
s = str(input())
r = ''.join(list(reversed(s)))
flag = [0,0,0,0]
t = ['maerd', 'remaerd', 'esare', 'resare']
while len(r) >= 0:
    if r[0:5] == t[0]:
        r = r[5:]
        flag[0] +=1
    elif r[0:6] == t[1]:
        r = r[6:]
        flag[1] +=1
    elif r[0:5] == t[2]:
        r = r[5:]
        flag[2] +=1
    elif r[0:6] == t[3]:
        r = r[6:]
        flag[3] +=1
    elif len(r) == 0:
        print('YES')
        break
    else:
        print('NO')
        break
print(flag)

Fixed code:
s = str(input())
r = ''.join(list(reversed(s)))
flag = [0,0,0,0]
t = ['maerd', 'remaerd', 'esare', 'resare']
while len(r) >= 0:
    if r[0:5] == t[0]:
        r = r[5:]
        flag[0] +=1
    elif r[0:7] == t[1]:
        r = r[7:]
        flag[1] +=1
    elif r[0:5] == t[2]:
        r = r[5:]
        flag[2] +=1
    elif r[0:6] == t[3]:
        r = r[6:]
        flag[3] +=1
    elif len(r) == 0:
        print('YES')
        break
    else:
        print('NO')
        break
# print(flag)
Buggy code:
x,y,l=0,5,len(s)
for _ in range(10**5):
  if x>=l-7:
    if x==l-7 and s[x:l]=='dreamer':
      print('YES')
    elif x==l-6 and s[x:l]=='eraser':
      print('YES')
    elif x==l-5 and (s[x:l]=='dream' or s[x:l]=='erase'):
      print('YES')
    else:
      print('NO')
    exit()
    
  if s[x:y]=='erase':
    x=y+1 if s[y]=='r' else y
    y=x+5
  elif s[x:y]=='dream':
    x=y+2 if s[x:y+2]=='er' else y
    y=x+5
  else:
    print('NO')
    exit()

Fixed code:
s=input()
x,y,l=0,5,len(s)
for _ in range(10**5):
  if x>=l-7:
    if x==l-7 and s[x:l]=='dreamer':
      print('YES')
    elif x==l-6 and s[x:l]=='eraser':
      print('YES')
    elif x==l-5 and (s[x:l]=='dream' or s[x:l]=='erase'):
      print('YES')
    else:
      print('NO')
    exit()
    
  if s[x:y]=='erase':
    x=y+1 if s[y]=='r' else y
    y=x+5
  elif s[x:y]=='dream':
    x=y if s[y:y+3]=='era' else (y+2 if s[y:y+2]=='er' else y) 
    y=x+5
  else:
    print('NO')
    exit()
Buggy code:
# coding: utf-8

import sys

S = input()

i = 0
while i < len(S):
	if S[i : i + 5] == "dream":
		print("dream")
		if S[i + 5 : i + 7] == "er":
			print("er")
			if S[i + 7 : i + 10] == "ase":
				print("ase")
				if S[i + 10] == "r":
					print("r")
					i += 11
				else:
					i += 10
			else:
				i += 7
		else:
			i += 5
	else:
		if S[i : i + 5] == "erase":
			print("erase")
			if S[i + 5] == "r":
				print("r")
				i += 6
			else:
				i += 5
		else:
			print("NO")
			sys.exit()

print("YES")

Fixed code:
# coding: utf-8

import sys

S = input()

i = 0
while i < len(S):
	if i + 4 < len(S) and S[i : i + 5] == "dream":
		if i + 6 < len(S) and S[i + 5 : i + 7] == "er":
			if i + 9 < len(S) and S[i + 7 : i + 10] == "ase":
				if i + 10 < len(S) and S[i + 10] == "r":
					i += 11
				else:
					i += 10
			else:
				i += 7
		else:
			i += 5
	else:
		if i + 4 < len(S) and S[i : i + 5] == "erase":
			if i + 5 < len(S) and S[i + 5] == "r":
				i += 6
			else:
				i += 5
		else:
			print("NO")
			sys.exit()

print("YES")
Buggy code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
i = 0
while i < n:
    if s[i:i+7] == 'dreamer':
        i += 7
    elif s[i:i+6] == 'eraser':
        i += 6
    elif s[i:i+5] == 'dream':
        i += 5
    elif s[i:i+5] == 'erase':
        i += 5
    else:
        print('NO')
        break
else:
    print('YES')

Fixed code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
i = n
while i > 0:
    if s[i-7:i] == 'dreamer' and i-7 >= 0:
        i -= 7
    elif s[i-6:i] == 'eraser' and i-6 >= 0:
        i -= 6
    elif s[i-5:i] == 'dream' and i-5 >= 0:
        i -= 5
    elif s[i-5:i] == 'erase' and i-5 >= 0:
        i -= 5
    else:
        print('NO')
        break
else:
    print('YES')
Buggy code:
S = input()
targets = ['eraser', 'erase', 'dreamer', 'dream']

for tg in targets:
    print(S)
    S = S.replace(tg, '')

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


Fixed code:
S = input()
targets = ['eraser', 'erase', 'dreamer', 'dream']

for tg in targets:
    S = S.replace(tg, '')

if len(S) == 0:
    print('YES')
else:
    print('NO')
Buggy code:
import sys
from collections import defaultdict, deque, Counter
import math
 
# import copy
from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
 
def main():
    S = list(getS())
    tgt5 = [list(s) for s in ["dream", "erase", ]]
    tgt7 = [list(s) for s in ["dreamer", "eraser"]]
    dp = [0 for i in range(len(S)+1)]
    dp[0] = 1
    for i, c in enumerate(S):
        if dp[i] == 1:
            for tg in tgt5:
                if S[i: i+5] == tg and i+5 <= len(S):
                    dp[i+5] = 1
            for tg in tgt7:
                if S[i: i+7] == tg and i+7 <= len(S):
                    dp[i+7] = 1

    # print(dp)
    if dp[-1] == 1:
        print("YES")
    else: 
        print("NO")

    return


 
if __name__ == "__main__":
    main()
   

Fixed code:
import sys
from collections import defaultdict, deque, Counter
import math
 
# import copy
from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
 
def main():
    S = list(getS())
    tgt5 = [list(s) for s in ["dream", "erase"]]
    tgt6 = [list(s) for s in ["eraser"]]
    tgt7 = [list(s) for s in ["dreamer"]]
    dp = [0 for i in range(len(S)+1)]
    dp[0] = 1
    for i, c in enumerate(S):
        if dp[i] == 1:
            for tg in tgt5:
                if S[i: i+5] == tg and i+5 <= len(S):
                    dp[i+5] = 1
            for tg in tgt6:
                if S[i: i+6] == tg and i+6 <= len(S):
                    dp[i+6] = 1
            for tg in tgt7:
                if S[i: i+7] == tg and i+7 <= len(S):
                    dp[i+7] = 1

    # print(dp)
    if dp[-1] == 1:
        print("YES")
    else: 
        print("NO")

    return


 
if __name__ == "__main__":
    main()
Buggy code:
#
# abc049 c
#
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']

while len(s) > 0:
    flag = 0
    for w in words:
        if s[-1 * len(w):] == w:
            s = s.replace(w, "").rstrip()
            flag = 1
            break
    if flag == 0:
        print("NO")
        exit()

print("YES"

Fixed code:
#
# abc049 c
#
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']

s = s[::-1]
while len(s) > 0:
    flag = 0
    for w in words:
        w = w[::-1]
        if s[0:len(w)] == w:
            s = s[len(w)::]
            # s = s.replace(w, "").lstrip()
            flag = 1
            break
    if flag == 0:
        print("NO")
        exit()

print("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","")
print("YES" if s=="" else "NO")
Buggy code:
S = input().replace("dreamer", "1").replace("dream", "1").replace(
    "eraser", "1").replace("erase", "1").replace("1", "")
if len(S) == 0:
    print("YES")
else:
    print("NO")

Fixed code:
S = input().replace("eraser", "1").replace("erase", "1").replace(
    "dreamer", "1").replace("dream", "1").replace("1", "")
if len(S) == 0:
    print("YES")
else:
    print("NO")
Buggy code:
S=input()
S=S.replace('dreamer','')
S=S.replace('eraser','')
S=S.replace('dream','')
S=S.replace('erase','')
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('YES')
  
else:
  print('NO')
Buggy code:
S = input()
while S:
    print(S)
    for x in ['dreamer', 'eraser', 'dream', 'erase']:
        if S.endswith(x):
            S = S[:-len(x)]
            break
    else:
        print('NO')
        exit()
print('YES')
        

Fixed code:
S = input()
while S:
    for x in ['dreamer', 'eraser', 'dream', 'erase']:
        if S.endswith(x):
            S = S[:-len(x)]
            break
    else:
        print('NO')
        exit()
print('YES')
Buggy code:
import re

s = input()
s = re.sub("dreamer","",s)
s = re.sub("dream","",s)
s = re.sub("eraser","",s)
s = re.sub("erase","",s)

if int(s) == 0:
    print("YES")
else:
    print("NO")

Fixed code:
import re

s = input()
s = re.sub("eraser","",s)
s = re.sub("erase","",s)
s = re.sub("dreamer","",s)
s = re.sub("dream","",s)

if len(s) == 0:
    print("YES")
else:
    print("NO")
Buggy code:
S = input()[::-1]
dividor = ['dream','dreamer','erase','eraser']
j=0
while True:
    flag = 0
    for d in dividor:
        print(S[j:j+len(d)])
        if S[j:j+len(d)]==d[::-1]:
            flag = 1
            j+=len(d)
            if j==len(S):
                print("YES")
                quit()
    if flag==0:
        print("NO")
        quit()

Fixed code:
S = input()[::-1]
dividor = ['dream','dreamer','erase','eraser']
j=0
while True:
    flag = 0
    for d in dividor:
        if S[j:j+len(d)]==d[::-1]:
            flag = 1
            j+=len(d)
            if j==len(S):
                print("YES")
                quit() 
    if flag==0:
        print("NO")
        quit()
Buggy code:
s = input()
 
s = s.replace('dreamer', '')
s = s.replace('dream', '')
s = s.replace('eraser', '')
s = s.replace('erase', '')
 
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('YES')
else:
    print('NO')
Buggy code:
#ABC049

s = input()

while len(s) != 0:
    
    if s[-5:] == "dream":
        s = s[:-5]
    elif s[-7:] == "dreamer":
        s = s[:-7]
    elif s[-5:] == "erase":
        s = s[:-5]
    elif s[-6:] == "eraser":
        s = s[:-6]
    else:
        print("NO")
        break
    print("YES")

Fixed code:
#ABC049

s = input()

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

while True:
  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[-7:] == 'eraser':
    S = S[:-7]
    continue
  break

answer = 'YES' if not S else 'NO
print(answer)

Fixed code:
S = input()

while True:
  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
  break

answer = 'YES' if not S else 'NO'
print(answer)
Buggy code:
S = input().strip()

while True:
  if S.endswith('dream'):
    S = S[:-5]
  elif S.endswith('dreamer'):
    S = S[:-7]
  elif S.endswith('erase'):
    S = S[:-5]
  elif S.endswith('eraser'):
    S = S[:-6]
  else break

if S:
  print("NO")
else:
  print('YES')

Fixed code:
S = input().strip()

while True:
  if S.endswith('dream'):
    S = S[:-5]
  elif S.endswith('dreamer'):
    S = S[:-7]
  elif S.endswith('erase'):
    S = S[:-5]
  elif S.endswith('eraser'):
    S = S[:-6]
  else:
    break

if S:
  print("NO")
else:
  print('YES')