Problem:


Score : 300 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Another string T is initially empty.
Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:

Append one of the following at the end of T: dream, dreamer, erase and eraser.

Constraints

1≦|S|≦10^5

S consists of lowercase English letters.

Input

The input is given from Standard Input in the following format:

S

Output

If it is possible to obtain S = T, print YES. Otherwise, print NO.

Sample Input 1

erasedream

Sample Output 1

YES

Append erase and dream at the end of T in this order, to obtain S = T.

Sample Input 2

dreameraser

Sample Output 2

YES

Append dream and eraser at the end of T in this order, to obtain S = T.

Sample Input 3

dreamerer

Sample Output 3

NO



Sample input:
erasedream


Sample output:
YES

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

S = input()

## Logic

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

S = input()

## Logic

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

Submission status: Wrong Answer

Solution code:
s = list(input())
while s:
    for c in ("dream", "dreamer", "erase", "eraser"):
        if "".join(s[-7:]).endswith(c):
            for _ in range(len(c)):
                s.pop()
            break
    else:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:

s = input()

words = ['dream', 'dreamer', 'erase', 'eraser']

while len(s) > 0:
    for word in words:
        s = s[::-1]
        word = word[::-1]
        flg = False

        if s.startswith(word):
            print(word)
            s = s.replace(word, '', 1)
            s = s[::-1]
            flg = True
            break

        s = s[::-1]

    if not flg:
        break

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

Submission status: Wrong Answer

Solution code:
S=input()
str_list=["dreamer","eraser","dream","erase"]
     
S_tmp=""
while True:
  S_tmp=S
  for str in str_list:
    if S[-len(str):]==str:
      S=S.rstrip(str)
        
  if S_tmp==S:
    break    
        
if S=="":
  print("YES")
if S!="":
  print("NO")

Submission status: Wrong Answer

Solution code:
S=input()
str_list=["dreamer","eraser"]
str_list_2=["dream","erase"]

S_tmp=""
while True:
  S_tmp=S
  for str in str_list:
    if S[:7]=="dreamer":
      S=S.rstrip("dreamer")
    if S[:6]=="eraser":
      S=S.rstrip("eraser")
        
  if S_tmp==S:
    break

while True:
  S_tmp=S
  for str in str_list_2:
    if S[:5]==str:
    	S=S.rstrip(str)
    
  if S_tmp==S:
    break    
    
if S=="":
  print("YES")
if S!="":
  print("NO")

Submission status: Wrong Answer

Solution code:
s = input()

import re
output ="NO"
s = re.sub('dreameraser', '', s)
s = re.sub('dreamerase', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('eraser', '', s)
s = re.sub('erase', '', s)
s = re.sub('dream', '', s)
if s == "":
    output = "YES"
print(output)

Submission status: Wrong Answer

Solution code:
S=input()
str_list=["dreamer","dream","eraser","erase"]

S_tmp=""
while True:
  S_tmp=S
  for str in str_list:
    
    S=S.replace(str,"",1)
  
  if S_tmp==S:
    break

if S=="":
  print("YES")
if S!="":
  print("NO")

Submission status: Wrong Answer

Solution code:
s = input()

import re
output ="NO"
s = re.sub('dreameraser', '', s)
s = re.sub('dreamerase', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('eraser', '', s)
s = re.sub('erase', '', s)
if s == "":
    output = "YES"
print(output)

Submission status: Wrong Answer

Solution code:
s = input()

import re
output ="NO"
s = re.sub('dreameraser', '', s)
s = re.sub('dreamerase', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
s = re.sub('eraser', '', s)
s = re.sub('erase', '', s)
if s == "":
    output = "YES"
print(output)

Submission status: Wrong Answer

Solution code:
s = input()

import re
output ="NO"
s = re.sub('dreameraser', '', s)
s = re.sub('dreamerase', '', s)
s = re.sub('eraser', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
s = re.sub('erase', '', s)
if s == "":
    output = "YES"
print(output)

Submission status: Wrong Answer

Solution code:
s = input()

import re
output ="NO"
s = re.sub('dreameraser', '', s)
s = re.sub('eraser', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
s = re.sub('erase', '', s)
if s == "":
    output = "YES"
print(output)

Submission status: Wrong Answer

Solution code:
S=input()
str_list=["dream","dreamer","erase","eraser"]

S_tmp=""
while True:
  S_tmp=S
  for str in str_list:
    S=S.replace(str,"") #rstrip(str)はだめ
  
  if S_tmp==S:
    break

if S=="":
  print("YES")
if S!="":
  print("NO")

Submission status: Wrong Answer

Solution code:
S=input()
str_list=["dream","dreamer","erase","eraser"]

S_tmp=""
while True:
  S_tmp=S
  for str in str_list:
    S=S.replace(str,"") #rstrip(str)はだめ
  
  if S_tmp==S:
    break

if S=="":
  print("Yes")
if S!="":
  print("No")

Submission status: Wrong Answer

Solution code:
s = input()

import re
output ="NO"
s = re.sub('eraser', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
s = re.sub('erase', '', s)
if s == "":
    output = "YES"
print(output)

Submission status: Wrong Answer

Solution code:
s = input()

import re
output ="NO"
s = re.sub('dreamer', '', s)
s = re.sub('eraser', '', s)
s = re.sub('dream', '', s)
s = re.sub('erase', '', s)
if s == "":
    output = "YES"
print(output)

Submission status: Wrong Answer

Solution code:
s = input()

import re
output ="NO"
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
s = re.sub('eraser', '', s)
s = re.sub('erase', '', s)
if s == "":
    output = "YES"
print(output)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = list(input())
SS = [0]
SS.extend(S)

def check(s):
	if s == [0]:
		print("YES")
	elif s[-7:] == list("dreamer"):
		del s[-7:]
		check(S)
	elif s[-6] == list("eraser"):
		del s[-6:]
		check(s)
	elif any(s[-5:] == list(x) for x in ["dream", "erase"]):
		del s[-5:]
		check(s)
	else:
		print("NO")

check(SS)

Submission status: Wrong Answer

Solution code:
import re

def main():
    s = list(input())
    sr = ''.join(list(reversed(s)))
    t = ['dream', 'dreamer', 'erase', 'eraser']
    tr = list()
    for i in t:
        tr.append(''.join(list(reversed(i))))
    while sr:
        flag = False
        for i in tr:
            if sr.startswith(i):
                sr = sr.replace(i ,"")
                flag = True
        if not flag:
            print('NO')
            break
    print('YES')
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import re

def main():
    s = list(input())
    sr = ''.join(list(reversed(s)))
    t = ['dream', 'dreamer', 'erase', 'eraser']
    tr = list()
    for i in t:
        tr.append(''.join(list(reversed(i))))
    while sr:
        flag = False
        for i in tr:
            if sr.startswith(i):
                sr = sr.replace(i ,"")
                flag = True
        if not flag:
            print('NO')
            break
        if sr == '':
            print('YES')
            break
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import re

def main():
    s = list(input())
    sr = ''.join(list(reversed(s)))
#    print(sr)
    t = ['dream', 'dreamer', 'erase', 'eraser']
    tr = list()
    for i in t:
        tr.append(''.join(list(reversed(i))))
    flag = False
    while True:
        for i in tr:
            sr_split = re.split('^' + i, sr ,1)
#            print(sr_split)
            if len(sr_split) == 2:
                flag = True
                sr = sr_split[1]
#                print(sr)
        if not flag:
            print('No')
            break
        if sr == '':
            print('Yes')
            break
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import re

def main():
    s = list(input())
    sr = ''.join(list(reversed(s)))
    print(sr)
    t = ['dream', 'dreamer', 'erase', 'eraser']
    tr = list()
    for i in t:
        tr.append(''.join(list(reversed(i))))
    while True:
        for i in tr:
            sr_split = re.split('^' + i, sr ,1)
            print(sr_split)
            if len(sr_split) == 2:
                sr = sr_split[1]
                print(sr)
        if sr_split == 1 or not sr_split == '':
            print('No')
            break
        if sr == '':
            print('Yes')
            break
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

import copy

s = input()

t = ''

words = ['dream', 'dreamer', 'erase', 'eraser']

flg = False


def func(array):
    for word_1 in array:
        words_replace1 = copy.deepcopy(array)
        words_replace1.remove(word_1)
        temp_s = s.replace(word_1, '')

        for word_2 in words_replace1:
            words_replace2 = copy.deepcopy(words_replace1)
            words_replace2.remove(word_2)
            temp_s = temp_s.replace(word_2, '')

            for word_3 in words_replace2:
                words_replace3 = copy.deepcopy(words_replace2)
                words_replace3.remove(word_3)
                temp_s = temp_s.replace(word_3, '')

                word_4 = words_replace3[0]
                temp_s = temp_s.replace(word_4, '')

                if temp_s == t:
                    return True

    return False


if func(words):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = str(input())
counte = 0
countd = 0
e = 'eraser'
d = 'dreamer'

fin = True

def judgeall(i):
    global counte
    global countd
    global fin
    if S[i] == e[counte]:
        counte += 1
    elif S[i] == d[countd]:
        countd += 1
    else:
        fin = False

def judgee(i):
    global counte
    global fin
    if S[i] == e[counte]:
        counte += 1
        counte %= 6
    else:
        fin = False

def judged(i):
    global counte
    global countd
    global fin
    if S[i] == d[countd]:
        countd += 1
        countd %= 7
        if i+2 < len(S):
            if countd == 6 and S[i+2] == 'a':
                counte = 1
                countd = 0
    else:
        fin = False

if S[0:2] == 'dr':
    countd = 2
elif S[0:2] == 'er':
    counte = 2
else:
    fin = False

for i in range(2,len(S)):
    if counte == 5 and S[i] == 'd':
        counte = 0
    if counte == 0 and countd == 0:
        judgeall(i)
        if fin == False:
            break
    elif counte != 0:
        judgee(i)
        if fin == False:
            break
    else:
        judged(i)
        if fin == False:
            break

if countd != 0 and counte != 0:
    fin = False
if countd == 0 and counte != 6:
    fin = False
if countd != 5 and counte == 0:
    fin = False
if countd == 0 and counte == 0 and S[i] != 'a':
    fin = True
if fin:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = str(input())
counte = 0
countd = 0
e = 'eraser'
d = 'dreamer'

fin = True

def judgeall(i):
    global counte
    global countd
    global fin
    if S[i] == e[counte]:
        counte += 1
    elif S[i] == d[countd]:
        countd += 1
    else:
        fin = False

def judgee(i):
    global counte
    global fin
    if S[i] == e[counte]:
        counte += 1
        counte %= 6
    else:
        fin = False

def judged(i):
    global counte
    global countd
    global fin
    if S[i] == d[countd]:
        countd += 1
        countd %= 7
        if i+2 < len(S):
            if countd == 0 and S[i+2] == 'a':
                counte = 2
    else:
        fin = False

if S[0:2] == 'dr':
    countd = 2
elif S[0:2] == 'er':
    counte = 2
else:
    fin = False

for i in range(2,len(S)):
    if counte == 5 and S[i] == 'd':
        counte = 0
    if counte == 0 and countd == 0:
        judgeall(i)
        if fin == False:
            break
    elif counte != 0:
        judgee(i)
        if fin == False:
            break
    else:
        judged(i)
        if fin == False:
            break

if countd != 0 and counte != 0:
    fin = False
if countd == 0 and counte != 6:
    fin = False
if countd != 5 and counte == 0:
    fin = False
if countd == 0 and counte == 0 and S[i] != 'a':
    fin = True
if fin:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = input()
T = ''

a = S.replace('eraser', '').replace('dreamer', '').replace('erase', '').replace('dream', '')

if len(a) == 0:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']


def reverse(t):
    return t[::-1]


RT = [reverse(t) for t in T]
RS = reverse(S)
can = True
i = 0
while i < len(RS):
    can2 = False
    for j in range(4):
        sizeT = len(RT[j])
        print(RS[i:i + sizeT])
        if RT[j] == RS[i:i + sizeT]:
            i += sizeT
            can2 = True
            break

    if not can2:
        can = False
        break

if can:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']


def reverse(t):
    return t[::-1]


RT = [reverse(t) for t in T]
RS = reverse(S)

can = True
i = 0
while i <= len(RS):
    can2 = False
    for j in range(4):
        sizeT = len(RT[j])
        if RT[j] == RS[i:sizeT]:
            i += sizeT
            can2 = True
            break

    if not can2:
        can = False
        break

if can:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']


def reverse(t):
    return t[::-1]


RT = [reverse(t) for t in T]
RS = reverse(S)

can = True
i = 0
while i <= len(RT):
    can2 = False
    for j in range(4):
        sizeT = len(RT[j])
        if RT[j] == RS[i:sizeT]:
            i += sizeT
            can2 = True
            break

    if not can2:
        can = False
        break

if can:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']


def reverse(t):
    return t[::-1]


RT = [reverse(t) for t in T]
RS = reverse(S)

can = True
i = 0
while i < len(RT):
    can2 = False
    for j in range(4):
        sizeT = len(RT[j])
        if RT[j] == RS[i:sizeT]:
            i += sizeT
            can2 = True
            break

    if not can2:
        can = False
        break

if can:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']


def reverse(t):
    return t[::-1]


RT = [reverse(t) for t in T]
RS = reverse(S)


for i in range(len(RS)):
    can = False
    for j in range(4):
        sizeT = len(RT[j])
        if RT[j] == RS[i:sizeT]:
            i += sizeT
            can = True
            break

    if can:
        break

if can:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']


def reverse(t):
    return t[::-1]


RT = [reverse(t) for t in T]
RS = reverse(S)
print(RT)


for i in range(len(RS)):
    can = False
    for j in range(4):
        sizeT = len(RT[j])
        if RT[j] == RS[i:sizeT]:
            i += sizeT
            can = True
            break

    if can:
        break

if can:
    print('OK')
else:
    print('NG')

Submission status: Wrong Answer

Solution code:

import copy

s = input()

t = ''

words = ['dream', 'dreamer', 'erase', 'eraser']

flg = False


def func(array):
    for word_1 in words:
        words_replace1 = copy.deepcopy(words)
        words_replace1.remove(word_1)
        temp_s = s.replace(word_1, '')

        for word_2 in words_replace1:
            words_replace2 = copy.deepcopy(words_replace1)
            words_replace2.remove(word_2)
            temp_s = temp_s.replace(word_2, '')

            for word_3 in words_replace2:
                words_replace3 = copy.deepcopy(words_replace2)
                words_replace3.remove(word_3)
                temp_s = temp_s.replace(word_3, '')

                word_4 = words_replace3[0]
                temp_s = temp_s.replace(word_4, '')

                if temp_s == t:
                    flg = True
                    return True

    return False


if func(words):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

s = input()

t = ''

words = ['dream', 'dreamer', 'erase', 'eraser']

flg = False

for word_1 in words:
    words_replace1 = words
    words_replace1.remove(word_1)
    temp_s = s.replace(word_1, '')
    
    for word_2 in words_replace1:
        words_replace2 = words_replace1
        words_replace2.remove(word_2)
        temp_s = temp_s.replace(word_2, '')
        
        for word_3 in words_replace2:
            words_replace3 = words_replace2
            words_replace3.remove(word_3)
            temp_s = temp_s.replace(word_3, '')
            
            word_4 = words_replace3[0]
            temp_s = temp_s.replace(word_4, '')

            if temp_s == t:
                flg = True
                break
        else:
            continue
    else:
        continue

if flg:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = input()

while S:
    if S[-5:] == "dream" or S[-5:] == "erase":
        S = S[:-5]
    elif S[-6:] == "dreamer" or S[-6:] == "eraser":
        S = S[:-6]
    else:
        break


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

Submission status: Wrong Answer

Solution code:
import sys
import math
import numpy as np
import copy

def main():
    s = input()

    a, b, c, d = "dream", "dreamer", "erase", "eraser"
    ra, rb, rc, rd = a[::-1], b[::-1], c[::-1], d[::-1]
    rs = s[::-1]

    while rs:
        flag = False
        for ele in [ra, rb, rc, rd]:
            if rs.startswith(ele):
                rs = rs.replace(ele, "", 1)
                flag = True
        if not flag:
            print("No")
            return 0
    
    print("Yes")
    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan
import cmath as cma
import copy as cp
import sys
import re
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

s = sinput()[::-1]
n = len(s)

a = "dream"[::-1]
b = "dreamer"[::-1]
c = "erase"[::-1]
d = "eraser"[::-1]

flag = 1
cnt = 0
while s:
    for ele in [a,b,c,d]: s = s.lstrip(ele)
    cnt += 1
    if cnt > 10**6: flag = 0; break

ans = "YES" if flag else "NO"
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan
import cmath as cma
import copy as cp
import sys
import re
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

s = sinput()[::-1]
n = len(s)

a = "dream"[::-1]
b = "dreamer"[::-1]
c = "erase"[::-1]
d = "eraser"[::-1]

flag = 1
cnt = 0
while s:
    for ele in [a,b,c,d]: s = s.lstrip(ele)
    cnt += 1
    if cnt > n//5 + 2: flag = 0; break

ans = "YES" if flag else "NO"
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan
import cmath as cma
import copy as cp
import sys
import re
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

s = sinput()[::-1]
n = len(s)

a = "dream"[::-1]
b = "dreamer"[::-1]
c = "erase"[::-1]
d = "eraser"[::-1]

flag = 1
cnt = 0
while s:
    for ele in [a,b,c,d]: s = s.lstrip(ele)
    cnt += 1
    if cnt > n//5: flag = 0; break

ans = "YES" if flag else "NO"
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan
import cmath as cma
import copy as cp
import sys
import re
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

s = sinput()[::-1]
n = len(s)

a = "dream"[::-1]
b = "dreamer"[::-1]
c = "erase"[::-1]
d = "eraser"[::-1]

flag = 1
cnt = 0
while s:
    for ele in [a,b,c,d]: s = s.lstrip(ele)
    cnt += 1
    if cnt > n//5: flag = 0; break

print(s)
ans = "YES" if flag else "NO"
print(ans)

Submission status: Wrong Answer

Solution code:
import re
moji=str(input())
temp=""
for i in range(-1,-(len(moji))-1 , -1):
  temp+=moji[i]
if "resare" in temp:
  temp=re.sub("resare", "I", temp)
if "remaerd" in temp:
  temp=re.sub("remaerd", "I", temp)
if "maerd" in temp:
  temp=re.sub("maerd", "I", temp)
if "esare" in temp:
  temp=re.sub("esare", "I", temp)
temp=re.sub("I", "", temp)

print("YES" if temp=="" else "NO")

Submission status: Wrong Answer

Solution code:
import re
moji=str(input())
temp=""
for i in range(-1,-(len(moji))-1 , -1):
  temp+=moji[i]
if "resare" in temp:
  temp=re.sub("resare", "", temp)
if "remaerd" in temp:
  temp=re.sub("remaerd", "", temp)
if "maerd" in temp:
  temp=re.sub("maerd", "", temp)
if "esare" in temp:
  temp=re.sub("esare", "", temp)

print("YES" if temp=="" else "NO")

Submission status: Wrong Answer

Solution code:
import re
moji=str(input())
if "eraser" in moji:
  moji=re.sub("eraser", "", moji)

if "dreamer" in moji:
  moji=re.sub("dreamer", "", moji)

if "dream" in moji:
  moji=re.sub("dream", "", moji)

if "erase" in moji:
  moji=re.sub("erase", "", moji)

print("YES" if moji=="" else "NO")

Submission status: Wrong Answer

Solution code:
import re
moji=str(input())
for i in range(4):
  if "eraser" in moji:
    moji=re.sub("eraser", "", moji)
  elif "dreamer" in moji:
    moji=re.sub("dreamer", "", moji)
  elif "dream" in moji:
    moji=re.sub("dream", "", moji)
  elif "erase" in moji:
    moji=re.sub("erase", "", moji)

print("YES" if moji=="" else "NO")

Submission status: Wrong Answer

Solution code:

s = input()

t = ''

s = s.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
print(s)

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

Submission status: Wrong Answer

Solution code:
import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$",input()) else "No")

Submission status: Wrong Answer

Solution code:
# C - 白昼夢
S = input()
S2 = S
W_L = ["dream","dreamer","erase","eraser"]
while True:
    
    for w in W_L:
        if S2.endswith(w):
            S2 = S2[:-(len(w))]
        else:
            print('NO')
            exit()
            
    if len(S2)<=7:
        break
    
if S2 ==''or S2 in W_L:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
# C - 白昼夢
S = input()
S2 = S
W_L = ["dream","dreamer","erase","eraser"]
while True:
    
    for w in W_L:
        if S2.endswith(w):
            S2 = S2[:-(len(w))]
            
    if len(S2)<=7 or not S2.endswith(w):
        break
    
if S2 ==''or S2 in W_L:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
# C - 白昼夢
S = input()
S2 = S
W_L = ["dream","dreamer","erase","eraser"]
while len(S2)>6:
    
    for w in W_L:
        if S2.endswith(w):
            S2 = S2[:-(len(w))]
    if not S2.endswith(w):
        break
    
if S2 ==''or S2 in W_L:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
S = input()

S = S.replace("dreamer","")
S = S.replace("dream","")
S = S.replace("eraser","")
S = S.replace("erase","")

print("YES" if S == "" else "NO")

Submission status: Wrong Answer

Solution code:
S=input()
T=[]

l=-1
while l-2>=-len(S):
    k=S[l:l-3:-1]
    print(k)
    if k=="mae":
        T+="dream"[::-1]
        l-=5
    elif k=="rem":
        T+="dreamer"[::-1]
        l-=7
    elif k=="esa":
        T+="erase"[::-1]
        l-=5
    elif k=="res":
        T+="eraser"[::-1]
        l-=6
    else:
        break
if S=="".join(T[::-1]):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:

S=input()
T=[]

l=-1
while l>=-len(S):
    if S[l]=="r":
        if l-2>=-len(S):          
            if S[l-2]=="s":
                T+="eraser"[::-1]
                l-=6
            elif S[l-2]=="m":
                T+="dreamer"[::-1]
                l-=7
            else:
                print("NO");break
        else:
            print("NO");break
    elif S[l]=="e":
        T+="erase"[::-1]
        l-=5
    elif S[l]=="m":
        T+="dream"[::-1]
        l-=5
    else:
        print("NO");break
    
if S=="".join(T[::-1]):
    print("YES")

Submission status: Wrong Answer

Solution code:


S=input()
T=[]

l=-1
while l>=-len(S):
    if S[l]=="r":
        if l-2<-len(S):
            print("NO");break
        elif S[l-2]=="s":
            T+="eraser"[::-1]
            l-=6
        else:
            T+="dreamer"[::-1]
            l-=7
    elif S[l]=="e":
        T+="erase"[::-1]
        l-=5
    elif S[l]=="m":
        T+="dream"[::-1]
        l-=5
    else:
        print("NO");break
        
if S=="".join(T[::-1]):
    print("YES")

Submission status: Wrong Answer

Solution code:
words = ['dream','dreamer','erase','eraser']
rev_words = []
for i in range(4):
    a = words[i]
    new_word = a[::-1]
    rev_words.append(new_word)

s = list(input())
new_s = list(reversed(s))
str_s = ''.join(new_s)

for i in range(len(str_s) + 1):
    for v in range(4):
        if rev_words[v] == str_s[0:i]:
            t = rev_words[v]
            i += len(rev_words[v])
            str_s = str_s.replace(t,'')

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

Submission status: Wrong Answer

Solution code:
import re
print('YES' if re.match('^(dream|dremaer|erase|eraser)+$', input()) else 'NO')

Submission status: Wrong Answer

Solution code:
s = list(input())
s.reverse()

while len(s) > 5:
    if s[:5] == list("maerd"):
        del s[:5]
        continue
    if s[:7] == list("remaerd"):
        del s[:7]
        continue
    if s[:5] == list("esare"):
        del s[:5]
        continue
    if s[:6] == list("resare"):
        del s[:6]
        continue
    break

if s == []:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s = list(input())
s.reverse()

while len(s) > 5:
    if s[:5] == list("maerd"):
        del s[:5]
        continue
    elif s[:7] == list("remaerd"):
        del s[:7]
        continue
    elif s[:5] == list("esare"):
        del s[:5]
        continue
    elif s[:6] == list("resare"):
        del s[:6]
        continue
    else:
        break

if s == []:
    print("YES")
else:
    print("NO")