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:
import itertools

input_moji = input()

count = 0

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

for i, _ in enumerate(lis, 1):     
    for j in itertools.permutations(lis, r=i):  # rには1、2、3と渡される
        total = "".join([str(_) for _ in j])
        if input_moji == total:
            count += 1
            print('Yes')

if count == 0:
    print('No')

Submission status: Wrong Answer

Solution code:
import itertools

input_moji = input()

count = 0

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

for i, _ in enumerate(lis, 1):     
    for j in itertools.permutations(lis, r=i):  # rには1、2、3と渡される
        total = "".join([str(_) for _ in j])
        print(total)
        if input_moji == total:
            count += 1
            print('Yes')

if count == 0:
    print('No')

Submission status: Wrong Answer

Solution code:
import itertools

input_moji = input()

count = 0

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

origin_list = ['dream','dreamer', 'erase','eraser']
for i in itertools.product(origin_list, repeat=2):
    total = "".join([str(_) for _ in i])
    if input_moji == total:
        count += 1
        print('YES')

if count == 0:
    print('NO')

Submission status: Wrong Answer

Solution code:
import itertools

input_moji = input()

count = 0

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

origin_list = ['dream','dreamer', 'erase','eraser']
for i in itertools.product(origin_list, repeat=2):
    total = "".join([str(_) for _ in i])
    if input_moji == total:
        count += 1
        print('Yes')

if count == 0:
    print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
q = ['dream','dreamer','erase','eraser']
s = input()

while True:
  if len(s) <= 7:
    break
  if s[-5:] in q:
    s = s[0:-5]
  elif s[-7:] in q:
    s = s[0:-7]
  elif s[-6:] in q:
    s = s[0:-6]
  else:
    print('N0')
    exit()
    
if s in q:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
q = ['dream','dreamer','erase','eraser']
s = input()

while True:
  if len(s) == 5 or len(s) == 7 or len(s) == 6:
    break
  if s[-5:] in q:
    s = s[0:-5]
  elif s[-7:] in q:
    s = s[0:-7]
  elif s[-6:] in q:
    s = s[0:-6]
  else:
    print('N0')
    exit()
    
if s in q:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
S = input()

def solve(T) :
    while 1:
        for i in ("dream", "dreamer", "erase", "eraser"):
            if T.endswith(i):
                T = T[: -len(i)]
                break
        
        else:
            print("NO")
            break
        
        if not T:
            print("Yes")
            break

solve(S)

Submission status: Wrong Answer

Solution code:
S = input()

def solve(T) :
    while 1:
        for i in ("dream", "dreamer", "erase", "eraser"):
            if T.endswith(i):
                T = T[: -len(i)]
                break
        
        else:
            print("NO")
            break
        
        if len(T) == 0:
            print("Yes")
            break

solve(S)

Submission status: Wrong Answer

Solution code:
S = input()

def solve(T) :
    while 1:
        flag = True
        for i in ("dream", "dreamer", "erase", "eraser"):
            if T.endswith(i):
                T = T[: -len(i)]
                flag = False
                break
        
        if flag:
            print("NO")
            break
        
        if len(T) == 0:
            print("Yes")
            break

solve(S)

Submission status: Wrong Answer

Solution code:
s=str(input())
x=len(s)
a=s.count("dream")
b=s.count("dreamer")
c=s.count("erase")
d=s.count("eraser")
e=s.count("dreameraser")
a-=b
c-=d
if 5*(a+c)+6*(b+d)-e==x:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
S = input()

while len(S) != 0:
    if S[-2:] == 'er':
        S = S[:-2]
        if S[-5:] == 'dream':
            S = S[:-5]
        elif S[-4:] == 'eras':
            S = S[:-4]
        else:
            print('No')
            exit()
    else:
        if S[-5:] == 'dream' or S[-5:] == 'erase':
            S = S[:-5]
        else:
            print('No')
            exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
S = input()

while len(S) != 0:
    if S[-2:] == 'er':
        S = S[:-2]
        if S[-5:] == 'dream':
            S = S[:-5]
        elif S[-4:] == 'eras':
            S = S[:-4]
        else:
            print('No')
            exit()
    else:
        if S[-5:] == 'dream' or S[-5:] == 'erase':
            S = S[:-5]
        else:
            print('No')
            exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
s = input()

while True:
  if len(s) == 0:
    print("YES")
    break
  elif len(s) < 5:
    print("NO")
    break
  else:
    if s[:5] == "dream":
      s = s.replace("dream", "", 1)
    elif s[:5] == "erase":
      s = s.replace("erase", "", 1)
    elif s[:7] == "dreamer" :
      s = s.replace("dreamer", "", 1)
    elif s[:6] == "eraser":
      s = s.replace("eraser", "", 1)
    else:
      print("NO")
      break

Submission status: Wrong Answer

Solution code:
s = input()

while True:
  if len(s) == 0:
    print("YES")
    break
  elif len(s) < 5:
    print("NO")
    break
  else:
    if s[:5] == "dream":
      s = s.replace("dream", "", 1)
    elif s[:6] == "eraser":
      s = s.replace("eraser", "", 1)
    elif s[:7] == "dreamer" :
      s = s.replace("dreamer", "", 1)
    elif s[:5] == "erase":
      s = s.replace("erase", "", 1)
    else:
      print("NO")
      break

Submission status: Wrong Answer

Solution code:
s = input()

while True:
  if len(s) == 0:
    print("YES")
    break
  elif len(s) < 5:
    print("NO")
    break
  else:
    if s[:5] == "dream":
      s = s.replace("dream", "", 1)
    elif s[:6] == "eraser":
      s = s.replace("eraser", "", 1)
    elif s[:6] == "dreamer" :
      s = s.replace("dreamer", "", 1)
    elif s[:5] == "erase":
      s = s.replace("erase", "", 1)
    else:
      print("NO")
      break

Submission status: Wrong Answer

Solution code:
s=input()[::-1]
a="dream"[::-1]
b="dreamer"[::-1]
c="erase"[::-1]
d="eraser"[::-1]
i=0
ans="Yes"
while i<len(s):
    if a in s[i:i+5]:
        i+=5
    elif b in s[i:i+7]:
        i+=7
    elif c in s[i:i+5]:
        i+=5
    elif d in s[i:i+6]:
        i+=6
    else :
        ans="No"
        break

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    num = 0

    while num < len(s) - 7:
        if s[num:num+6] == "dreamd" or s[num:num+8] == "dreamera":   #"dream"確定
            num += 5
        elif s[num:num+8] == "dreamerd" or s[num:num+8] == "dreamere":  #"dreamer"確定
            num += 7
        elif s[num:num+6] == "erased" or s[num:num+6] == "erasee":    #"erase"確定
            num += 5
            print('erase')
        elif s[num:num+7] == "eraserd" or s[num:num+7] == "erasere":    #"eraser"確定
            num += 6
        else:
            print("NO")
            exit()
    if s[num:num+5] == "dream" or s[num:num+7] == "dreamer" or s[num:num+5] == "erase" or s[num:num+6] == "eraser":
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
t=n-1
for i in range(n):
    if t>=4 and s[t-4:t+1]=="dream":
        t-=5
    elif t>=6 and s[t-6:t+1]=="dream":
        t-=7
    elif t>=4 and s[t-4:t+1]=="erase":
        t-=5
    elif t>=5 and s[t-5:t+1]=="eraser":
        t-=6
    if t<0:
        break
if t==-1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
mycode = r'''
# distutils: language=c++
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: infer_types=True
# cython: cdivision=True
# False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。

from libcpp.string cimport string as Str
# define 
ctypedef long long LL

# 読み込みはpython側で行う
import sys
readline = sys.stdin.buffer.readline().rstrip

cdef LL i,j,k,_


cdef Str S = readline()
cdef Str dream = b'dream'
cdef Str dreamer = b'dreamer'
cdef Str erase = b'erase'
cdef Str eraser = b'eraser'

# 文字列処理は流石にpypy提出のほうが楽そう
# 致命的な点としては、libcpp.stringがeraseなどの文字列削除操作に対応していない点だ

cdef LL idx=S.size()
while idx>7:
    if S.substr(idx-5,idx)==dream: #idxから後ろ5文字以降を表示
        idx-=5 
    elif S.substr(idx-5,idx)==erase:
        idx-=5 
    elif S.substr(idx-6,idx)==eraser:
        idx-=6
    elif S.substr(idx-7,idx)==dreamer:
        idx-=7 
    else:
        print('NO')
        exit()

if S.substr(0, idx) in [dream, dreamer, erase, eraser]:
    print('YES')
else:
    print('NO')




'''

import sys
if sys.argv[-1] == 'ONLINE_JUDGE':  # コンパイル時
    import os
    with open('mycode.pyx', 'w') as f:
        f.write(mycode)
    os.system('cythonize -i -3 -b mycode.pyx')

import mycode

Submission status: Wrong Answer

Solution code:
mycode = r'''
# distutils: language=c++
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: infer_types=True
# cython: cdivision=True
# False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。

from libcpp.string cimport string as Str
# define 
ctypedef long long LL

# 読み込みはpython側で行う
import sys
readline = sys.stdin.buffer.readline().rstrip

cdef LL i,j,k,_


cdef Str S = readline()
cdef Str dream = b'dream'
cdef Str dreamer = b'dreamer'
cdef Str erase = b'erase'
cdef Str eraser = b'eraser'

# 文字列処理は流石にpypy提出のほうが楽そう
# 致命的な点としては、libcpp.stringがeraseなどの文字列削除操作に対応していない点だ

cdef LL idx=S.size()
while idx>7:
    if S.substr(idx-5,idx)==dream: #idxから後ろ5文字以降を表示
        idx-=5 
    elif S.substr(idx-5,idx)==erase:
        idx-=5 
    elif S.substr(idx-6,idx)==eraser:
        idx-=6
    elif S.substr(idx-7,idx)==dreamer:
        idx-=7 
    else: break

if S.substr(0, idx) in [dream, dreamer, erase, eraser]:
    print('YES')
else:
    print('NO')


'''

import sys
if sys.argv[-1] == 'ONLINE_JUDGE':  # コンパイル時
    import os
    with open('mycode.pyx', 'w') as f:
        f.write(mycode)
    os.system('cythonize -i -3 -b mycode.pyx')

import mycode

Submission status: Wrong Answer

Solution code:
S = input()

idx = 0
while True:
    if idx >= len(S) - 1:
        break
    if S[idx:idx +
         7] == 'dreamer' and (S[idx +
                                5:idx +
                                10] != 'erase' or S[idx +
                                                    5:idx +
                                                    11] != 'eraser'):
        idx += 7
    elif S[idx:idx + 6] == 'eraser' and (S[idx +
                                           4:idx +
                                           9] != 'erase' or S[idx +
                                                              4:idx +
                                                              10] != 'eraser'):
        idx += 6
    elif S[idx:idx + 5] == 'dream' or S[idx:idx + 5] == 'erase':
        idx += 5
    else:
        print('NO')
        exit()

print('YES')

Submission status: Wrong Answer

Solution code:
S = input()

idx = 0
while True:
    if idx >= len(S) - 1:
        break
    if S[idx:idx +
         7] == 'dreamer' and (S[idx +
                                5:idx +
                                10] != 'erase' or S[idx +
                                                    5:idx +
                                                    11] != 'eraser'):
        idx += 7
    elif S[idx:idx + 6] == 'eraser' and (S[idx +
                                           4:idx +
                                           9] != 'erase' or S[idx +
                                                              4:idx +
                                                              10] != 'eraser'):
        idx += 6
    elif S[idx:idx + 5] == 'dream' or S[idx:idx + 5] == 'erase':
        idx += 5
    else:
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
S = str(input())
i = 0
error = 0

while i < len(S) and error == 0:

    if i + 5 > len(S):
        error = -1
        break

    if S[i: i + 5] == 'dream':
        i += 5
        if i + 2 >= len(S):
            if S[i: i + 2] == 'er':
                if (i + 2) == len(S):
                    i += 2
                elif S[i + 2] != 'a':
                    i += 2
    elif S[i: i + 5] == 'erase':
        i += 5
        if i + 1 >= len(S):
            if S[i] == 'r':
                if (i + 1) == len(S):
                    i += 1
                elif S[i + 1] != 'a':
                    i += 1
    else:
        error = -1
        break

if error == 0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    s = list(input())
    s.reverse()
    len_s = len(s)
    t = 0
    while True:
        if t == len_s:
            print("YES")
            exit()
        elif t > len_s:
            break
        else:
            if s[t] == "m":
                t += 5
            elif s[t] == "r" and s[t+2] == "m":
                t += 7
            elif s[t] == "e":
                t += 5
            elif s[t] == "r":
                t += 6
            else:
                break
    print("NO")


if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    s = list(input())
    s.reverse()
    len_s = len(s)
    t = 0
    while True:
        if t == len_s:
            print("YES")
            exit()
        if t > len_s:
            break
        if s[t] == "m":
            t += 5
        elif s[t] == "r" and s[t+2] == "m":
            t += 7
        elif s[t] == "e":
            t += 5
        elif s[t] == "r":
            t += 6
        else:
            break
    print("NO")


if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

S=input()
N=len(S)
ans=True
i=0
while ans:
    if i==N:
        break
    if S[i]=='e':
        if S[i:i+6]=='eraser':
            i+=6
        elif S[i:i+5]=='erase':
            i+=5
        else:
            ans=False
    if S[i]=='d':
        if S[i:i+11]=='dreameraser':
            i+=11
        elif S[i:i+10]=='dreamerase':
            i+=10
        elif S[i:i+7]=='dreamer':
            i+=7
        elif S[i:i+5]=='dream':
            i+=5
        else:
            ans=False
    else:
        ans=False
judge(ans,['YES','NO'])

Submission status: Wrong Answer

Solution code:
S = str("dreamerase")

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

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

Submission status: Wrong Answer

Solution code:
S = input()

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

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

Submission status: Wrong Answer

Solution code:
S = input()
S = S.replace('eraser', '#', S.count('eraser'))
S = S.replace('dreamer', '#', S.count('dreamer'))
S = S.replace('erase', '#', S.count('erase'))
S = S.replace('dream', '#', S.count('dream'))
# print(S)
if len(S) == S.count('#'):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from sys import stdin
s = stdin.readline().rstrip()
d = ['dream','dreamer','erase','eraser']

#print(s[0])
#print(s[0:len(d[0])],d[0])
#if s[0:len(d[0])] == d[0]:
#   print('true')

for t in range(len(s)):
#   print(s,2)
   if s == '':
      print('YES')
      break
   elif s[0] == 'd' or s[0] == 'e':
     for x in range(4):
         if s == '':
            print('YES')
            break
         elif s[0:len(d[x])] == d[x]:
            s = s.replace(d[x],'')
#            print(s,1)
            break
   else:
      print('NO')
      break

Submission status: Wrong Answer

Solution code:
S = input()
while(len(S) >= 5):
  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(len(S) == 0):
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
input_str = input()
process_flag = 'process'
ans_flag = 'NO'
d_e = ''
ans_list = []

def pre_str_process(now_str):
  ans_list.append(now_str[:5])
  now_str = now_str[5:]
  return now_str

def dream(now_str):
  now_str = pre_str_process(now_str)
  if (now_str == '') or (now_str == 'er'):
    return now_str, 'OK'
  if now_str[:5] == 'dream':
    return now_str, 'dream'
  if now_str[:2] == 'er':
    if now_str[:6] == 'eraser':
      return now_str, 'erase'
    if now_str[:7] == 'ererase':
      now_str = now_str[2:]
      return now_str, 'erase'
    if now_str[:7] == 'erdream':
      now_str = now_str[2:]
      return now_str, 'dream'
    else:
      return now_str, 'NG'

  else:
    return now_str, 'NG'

def erase(now_str):
  now_str = pre_str_process(now_str)
  if (now_str == '') or (now_str == 'r'):
    return now_str, 'OK'
  if now_str[0] == 'r':
    now_str = now_str[1:]
    if now_str[:5] == 'dream':
      return now_str, 'dream'
    if now_str[:5] == 'erase':
      return now_str, 'erase'
    else:
      return now_str, 'NG'
  if now_str[:5] == 'erase':
    return now_str, 'erase'
  if now_str[:5] == 'dream':
    return now_str, 'dream'
  else:
    return now_str, 'NG'

first_str = input_str[:5]
process_num = 0
while process_flag == 'process':
  process_num += 1
  if process_num == 1:
    if first_str == 'dream':
      now_str = input_str
      d_e = 'dream'
    elif first_str == 'erase':
      now_str = input_str
      d_e = 'erase'
    else:
      break
  elif d_e == 'dream':
    now_str, d_e = dream(now_str)
  elif d_e == 'erase':
    now_str, d_e = erase(now_str)
  elif d_e == 'OK':
    ans_flag = 'YES'
    break
  elif d_e == 'NG':
    break
print(ans_flag)

Submission status: Wrong Answer

Solution code:
input_str = input()
process_flag = 'process'
ans_flag = 'NO'
d_e = ''
ans_list = []

def pre_str_process(now_str):
  ans_list.append(now_str[:5])
  now_str = now_str[5:]
  return now_str

def dream(now_str):
  now_str = pre_str_process(now_str)
  if (now_str == '') or (now_str == 'er'):
    return now_str, 'OK'
  if now_str[:5] == 'dream':
    return now_str, 'dream'
  if now_str[:2] == 'er':
    if now_str[:6] == 'eraser':
      return now_str, 'erase'
    if now_str[:7] == 'ererase':
      now_str = now_str[2:]
      return now_str, 'erase'
    if now_str[:8] == 'erdream':
      now_str = now_str[2:]
      return now_str, 'dream'
    else:
      return now_str, 'NG'

  else:
    return now_str, 'NG'

def erase(now_str):
  now_str = pre_str_process(now_str)
  if (now_str == '') or (now_str == 'r'):
    return now_str, 'OK'
  if now_str[0] == 'r':
    now_str = now_str[1:]
    if now_str[:5] == 'dream':
      return now_str, 'dream'
    if now_str[:5] == 'erase':
      return now_str, 'erase'
    else:
      return now_str, 'NG'
  if now_str[:5] == 'erase':
    return now_str, 'erase'
  if now_str[:5] == 'dream':
    return now_str, 'dream'
  else:
    return now_str, 'NG'

first_str = input_str[:5]
process_num = 0
while process_flag == 'process':
  process_num += 1
  if process_num == 1:
    if first_str == 'dream':
      now_str = input_str
      d_e = 'dream'
    elif first_str == 'erase':
      now_str = input_str
      d_e = 'erase'
    else:
      break
  elif d_e == 'dream':
    now_str, d_e = dream(now_str)
  elif d_e == 'erase':
    now_str, d_e = erase(now_str)
  elif d_e == 'OK':
    ans_flag = 'YES'
    break
  elif d_e == 'NG':
    break
print(ans_flag)

Submission status: Wrong Answer

Solution code:
input_str = input()
process_flag = 'process'
ans_flag = 'NO'
d_e = ''
ans_list = []

def pre_str_process(now_str):
  ans_list.append(now_str[:5])
  now_str = now_str[5:]
  return now_str

def dream(now_str):
  now_str = pre_str_process(now_str)
  if (now_str == '') or (now_str == 'er'):
    return now_str, 'OK'
  if now_str[:5] == 'dream':
    return now_str, 'dream'
  if now_str[:2] == 'er':
    if now_str[:6] == 'eraser':
      return now_str, 'erase'
    if now_str[:8] == 'ereraser':
      now_str = now_str[2:]
      return now_str, 'erase'
    if now_str[:8] == 'erdream':
      now_str = now_str[2:]
      return now_str, 'dream'
    else:
      return now_str, 'NG'

  else:
    return now_str, 'NG'

def erase(now_str):
  now_str = pre_str_process(now_str)
  if (now_str == '') or (now_str == 'r'):
    return now_str, 'OK'
  if now_str[0] == 'r':
    now_str = now_str[1:]
    if now_str[:5] == 'dream':
      return now_str, 'dream'
    if now_str[:5] == 'erase':
      return now_str, 'erase'
    else:
      return now_str, 'NG'
  if now_str[:2] == 'er':
    now_str = now_str[2:]
    if now_str[:5] == 'dream':
      return now_str, 'dream'
    if now_str[:5] == 'erase':
      return now_str, 'erase'
    else:
      return now_str, 'NG'
  if now_str[:5] == 'dream':
    return now_str, 'dream'
  else:
    return now_str, 'NG'

first_str = input_str[:5]
process_num = 0
while process_flag == 'process':
  process_num += 1
  if process_num == 1:
    if first_str == 'dream':
      now_str = input_str
      d_e = 'dream'
    elif first_str == 'erase':
      now_str = input_str
      d_e = 'erase'
    else:
      break
  elif d_e == 'dream':
    now_str, d_e = dream(now_str)
  elif d_e == 'erase':
    now_str, d_e = erase(now_str)
  elif d_e == 'OK':
    ans_flag = 'YES'
    break
  elif d_e == 'NG':
    break
print(ans_flag)

Submission status: Wrong Answer

Solution code:
s=input()

def judge():
  cnt=0
  while True:
    if s[cnt:cnt+6]=='eraser':
      cnt+=6
    elif s[cnt:cnt+5]=='erase':
      cnt+=5
    elif s[cnt:cnt+7]=='dreamer':
      cnt+=7
    elif s[cnt:cnt+5]=='dream':
      cnt+=5
    else:
      print('NO')
      exit()
    if cnt==len(s):
      print('YES')
      exit()

judge()

Submission status: Wrong Answer

Solution code:
s=input()

def judge():
  cnt=0
  while cnt<=len(s):
    if s[cnt:cnt+6]=='eraser':
      cnt+=6
    elif s[cnt:cnt+5]=='erase':
      cnt+=5
    elif s[cnt:cnt+7]=='dreamer':
      cnt+=7
    elif s[cnt:cnt+5]=='dream':
      cnt+=5
    else:
      print('NO')
      exit()
    if cnt==len(s):
      print('YES')
      exit()

judge()

Submission status: Wrong Answer

Solution code:
s=input()

def judge():
  cnt=0
  while cnt<=len(s):
    if s[cnt:cnt+6]=='eraser':
      cnt+=6
    elif s[cnt:cnt+5]=='erase':
      cnt+=5
    elif s[cnt:cnt+6]=='dreamer':
      cnt+=6
    elif s[cnt:cnt+5]=='dream':
      cnt+=5
    else:
      print('NO')
      exit()
    if cnt==len(s):
      print('YES')
      exit()

judge()

Submission status: Wrong Answer

Solution code:
# vim: fileencoding=utf-8


def main():
    s = list(input())
    c = ["dreamer", "dream", "erase", "eraser"]
    n = [7, 5, 5, 6]
    while True:
        f = True
        for i in range(4):
            if "".join(s[-n[i] :]) == c[i]:
                f = False
                s = s[: -n[i]]
                break
        if f:
            if len(s) == 0:
                print("Yes")
            else:
                print("No")
            return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s=input()
while True:
    if len(s) == 0:
        print("Yes")
        break
    elif s[-5:] == "dream" or s[-5:] == "erase":
        s=s[:-5]
    elif s[-6:] == "eraser":
        s=s[:-6]
    elif s[-7:] == "dreamer":
        s=s[:-7]
    else:
        print("No")
        break

Submission status: Wrong Answer

Solution code:
s = input()

slen = len(s)
now=0

while(1):
    if s[now:now+5] == "erase":
        now += 5
    elif s[now:now+6] == "eraser":
        now += 6
    elif s[now:now+5] == "dream":
        now += 5
    if s[now:now+6] == "dreamer":
        now += 7
    else:
        print('NO')
        break
    if now == slen:
        print('YES')
        break

Submission status: Wrong Answer

Solution code:
s = input()
s=s[::-1]
i=0
ans="YES"
while True:
    if len(s)==i:
        break
    elif s[i:i+5]=="maerd":
        i+=5
    elif s[i:i+7]=="remared":
        i+=7
    elif s[i:i+5]=='esare':
        i+=5
    elif s[i:i+6]=='resare':
        i+=6
    else:
        ans="NO"
        break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
s=s[::-1]
i=0
ans="YES"
while True:
    if len(s)==i:
        break
    elif s[i:i+5]=="maerd":
        i+=5
    elif s[i:i+7]=="remared":
        i+=7
    elif s[i:i+5]=='esare':
        i+=5
    elif s[i:i+6]=='resare':
        i+=6
    else:
        ans="NO"
        break
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
z = 'YES'
while len(s) != 0:
    if s[:11] == 'dreameraser':
        s = s[11:]
    elif s[:10] == 'dreamerase':
        s = s[10:]
    elif s[:13] == 'dreamereraser':
        s = s[13:]
    elif s[:12] == 'dreamererase':
        s = s[12:]
    elif 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:
        z = 'NO'
        break
print(z)

Submission status: Wrong Answer

Solution code:
S = input()
while True :
  if S[-5:] == "dream":
    S = S.replace("dream","")
  elif S[-6:] == "eraser":
    S = S.replace("eraser","")
  elif S[-7:] == "dreamer":
    S = S.replace("dreamer","")
  elif S[-5:] == "erase":
    S = S.replace("erase","")
  elif len(S) == 0:
    print("YES")
    break
  else:
    print("NO")
    break

Submission status: Wrong Answer

Solution code:
S = input()
while True :
  if S[0:5] == "dream":
    S = S.replace("dream","")
  elif S[0:6] == "eraser":
    S = S.replace("eraser","")
  elif S[0:7] == "dreamer":
    S = S.replace("dreamer","")
  elif S[0:5] == "erase":
    S = S.replace("erase","")
  elif len(S) == 0:
    print("YES")
    break
  else:
    print("NO")
    break

Submission status: Wrong Answer

Solution code:
S = input()
while True :
  if S[0:7] == "dreamer":
    S = S.replace("dreamer","")
  elif S[0:6] == "eraser":
    S = S.replace("eraser","")
  elif S[0:5] == "dream":
    S = S.replace("dream","")
  elif S[0:5] == "erase":
    S = S.replace("erase","")
  elif len(S) == 0:
    print("YES")
    break
  else:
    print("NO")
    break

Submission status: Wrong Answer

Solution code:
S = input()
while True :
  if S[0:7] == "dreamer":
    S = S.strip("dreamer")
  elif S[0:6] == "eraser":
    S = S.strip("eraser")
  elif S[0:5] == "dream":
    S = S.strip("dream")
  elif S[0:5] == "erase":
    S = S.strip("erase")
  elif len(S) == 0:
    print("YES")
    break
  else:
    print("NO")
    break