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: Runtime Error

Solution code:
s = input()
s_origin = s
t = ""
word_list = ["dream", "dreamer", "erase", "eraser"]
while 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

    s_child_2 = s[-6:]
    if s_child_2 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")

Submission status: Runtime Error

Solution code:
s = input()
s = s[::-1]
t_list = ['dream', 'dreamer', 'erase', 'eraser']
t_list = [i[::-1] for i in t_list]
i = 0

while i < len(s):
    can = False
    for j in range(4):
        if s[i:i+len(t_list[j])] == t_list[j]:
            i+=len(t_list[j])
            can = True
    if can == False: # うまくいっても最後には`can=False`になる
        break

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

Submission status: Runtime Error

Solution 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')

Submission status: Runtime Error

Solution 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)

Submission status: Runtime Error

Solution code:
import sys
li = ["dream","dreamer","erase","eraser"]
li = [s[::-1] for s in li]
sen = input()[::-1]
while 1:
  if sen[:5] == "maerd":
    if len(sen) == 5:
      print("YES")
      sys.exit()
    else sen = sen[5:]
  elif sen[:6] == "remaerd":
    if len(sen) == 6:
      print("YES")
      sys.exit()
    else sen = sen[6:]
  elif sen[:5] == "esare":
    if len(sen) == 5:
      print("YES")
      sys.exit()
    else sen = sen[5:]
  elif sen[:6] == "resare":
    if len(sen) == 6:
      print("YES")
      sys.exit()
    else sen = sen[6:]
  else:
    print("NO")
    sys.exit()

Submission status: Runtime Error

Solution code:
S = input()[::-1]
T = ['maerd' ,'remaerd' ,'esare' ,'resare']
i, j = 0, 0
while True:
    if i == 4:
        break
    if T[i] == S[j:j+len(T[i])]:
        p += len(T[i])
        i = 0
    else:
        i += 1
print("YES" if len(S)==j else "NO")

Submission status: Runtime Error

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

S_reverse = ''.join(list(reversed(S)))
for i in list:
    i_reverse = ''.join(list(reversed(i)))
    S_reverse = S_reverse.replace(i_reverse, "")

if S_reverse == "":
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

S_reverse = ''.join(list(reversed(S)))
for i in list:
    i_reverse = ''.join(list(reversed(i)))
  S_reverse = S_reverse.replace(i_reverse, "")

if S_reverse == "":
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
import random
S = input()
T = ""
list = ["dream", "dreamer", "erase", "eraser"]

while len(T) <= 100000:
	T += random.choice(list)
    if T == S:
      print("YES")
      break
print("NO")

Submission status: Runtime Error

Solution code:
import random
S = input()
T = ""
list = ["dream", "dreamer", "erase", "eraser"]

while len(T) <= 100000:
	T += random.choice(list)
    if T == S:
      break

Submission status: Runtime Error

Solution code:
import random
S = input()
T = ""
list = ["dream", "dreamer", "erase", "eraser"]

while T <= 100000:
	T += random.choice(list)
    if T == S:
      break

Submission status: Runtime Error

Solution code:
import random
S = input()
T = ""
list = ["dream", "dreamer", "erase", "eraser"]

While T =< 100000:
	T += random.choice(list)
    if T == S:
      break

Submission status: Runtime Error

Solution code:
S = input()

flag = []

def dfs(s):
    if not S.startswith(s):
        return
    if S == s:
        flag.append(1)
        return

    dfs(s + 'dream')
    dfs(s + 'dreamer')
    dfs(s + 'erase')
    dfs(s + 'eraser')

re1 = dfs('dream')
re2 = dfs('dreamer')
re3 = dfs('erase')
re4 = dfs('eraser')

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

Submission status: Runtime Error

Solution code:
S = input()

def dfs(s):
    if S == s:
        print("YES")
        exit()
        return
    if not S.startswith(s):
        return

    dfs(s + 'dream')
    dfs(s + 'dreamer')
    dfs(s + 'erase')
    dfs(s + 'eraser')

re1 = dfs('dream')
re2 = dfs('dreamer')
re3 = dfs('erase')
re4 = dfs('eraser')

print('NO')

Submission status: Runtime Error

Solution code:
S = input()

success = 0
def dfs(s, success):
    if S == s:
        print("YES")
        exit()
        return 1
    if not S.startswith(s):
        return 0

    dfs(s + 'dream', success)
    dfs(s + 'dreamer', success)
    dfs(s + 'erase', success)
    dfs(s + 'eraser', success)

re1 = dfs('dream', success)
re2 = dfs('dreamer', success)
re3 = dfs('erase', success)
re4 = dfs('eraser', success)

print('NO')

Submission status: Runtime Error

Solution code:
S=input()
lenS=len(S)
L=[0]*10000
j=0
i=0
s=0
S+="######################"
while(True):
    if(lenS==i):
        print("YES")
        exit()
    if(S[i:i+7]=="dreamer" and s<1):
        L[j]=1
        j+=1
        i+=7
        s=0
        continue
    if(S[i:i+5]=="dream" and s<2):
        L[j]=2
        j+=1
        i+=5
        s=0
        continue
    if(S[i:i+6]=="eraser" and s<3):
        L[j]=3
        j+=1
        i+=6
        s=0
        continue
    if(S[i:i+5]=="erase" and s<4):
        L[j]=4
        j+=1
        i+=5
        s=0
        continue
    j-=1
    if(j<0):
        print("NO")
        exit()
    if(L[j]==1):
        i-=7
        s=1
    elif(L[j]==2):
        i-=5
        s=2
    elif(L[j]==3):
        i-=6
        s=3    
    elif(L[j]==4):
        i-=5
        s=4

Submission status: Runtime Error

Solution code:
S=input()
lenS=len(S)
L=[0]*10000
j=0
i=0
s=0
while(True):
    if(lenS==i):
        print("YES")
        exit()
    if(S[i:i+7]=="dreamer" and s<1):
        L[j]=1
        j+=1
        i+=7
        s=0
        continue
    if(S[i:i+5]=="dream" and s<2):
        L[j]=2
        j+=1
        i+=5
        s=0
        continue
    if(S[i:i+6]=="eraser" and s<3):
        L[j]=3
        j+=1
        i+=6
        s=0
        continue
    if(S[i:i+5]=="erase" and s<4):
        L[j]=4
        j+=1
        i+=5
        s=0
        continue
    j-=1
    if(j<0):
        print("NO")
        exit()
    if(L[j]==1):
        i-=7
        s=1
    elif(L[j]==2):
        i-=5
        s=2
    elif(L[j]==3):
        i-=6
        s=3    
    elif(L[j]==4):
        i-=5
        s=4

Submission status: Runtime Error

Solution code:
S=input()
lenS=len(S)

def state(i):
    if(lenS==i):
        return True

    if(S[i:i+7]=="dreamer"):
        j=state(i+7)
        if(j==True):
            return True
    if(S[i:i+5]=="dream"):
        j=state(i+5)
        if(j==True):
            return True
    if(S[i:i+6]=="eraser"):
        j=state(i+6)
        if(j==True):
            return True      
    if(S[i:i+5]=="erase"):
        j=state(i+5)  
        if(j==True):
            return True
    return False
i=0
if(state(i)):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s = input()[::-1]
while True:
    end_flg = False
    if s[:5] == "maerd":
        s = s.replace("maerd", "", 1)
        end_flg = True
        print(s)
    elif s[:5] == "esare":
        s = s.replace("esare", "", 1)
        end_flg = True
    elif s[:7] == "remaerd":
        s = s.replace("remaerd", "", 1)
        end_flg = True
    elif s[:6] == "resare":
        s = s.replace("resare", "", 1)
        end_flg = True    

    if end_flg == False:
        break
        
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s = input()[::-1]
s = s.replace("maerd", "", 1)

while True:
    end_flg = False
    if s[:5] == "maerd":
        s = s.replace("maerd", "", 1)
        end_flg = True
        print(s)
    elif s[:5] == "esare":
        s = s.replace("esare", "", 1)
        end_flg = True
    elif s[:7] == "remaerd":
        s = s.replace("remaerd", "", 1)
        end_flg = True
    elif s[:6] == "resare":
        s = s.replace("resare", "", 1)
        end_flg = True    

    if end_flg == False:
        break
        
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

#整数の入力
S = input()

#置換
S2 = S1.replace("eraser", "")
S4 = S3.replace("erase", "")
S1 = S.replace("dreamer", "")
S3 = S2.replace("dream", "")

if len(S4) >= 1:
    print("NO")
else:
    print("YES")

Submission status: Runtime Error

Solution code:
import sys
s=reverse(input())
l=list(["maerd","remaerd","esare","resare"]
for i in range len(s):
  ok=0
  for j in range l:
    if s[i:len(j)] == j:
      ok=1
      i += len(j)
      break
  if ok == 0:
    print("NO")
    sys.exit()
print("YES")

Submission status: Runtime Error

Solution code:
s = str(input())[::-1]

while(len(s) >= 5):
    print(s)
    if s[:5] == 'maerd':
        s = s.replace('maerd', '')
    elif s[:7] == 'remaerd':
        s = s.replace('remerd', '')
    elif s[:5] == 'esare':
        s = s.replace('esare', '')
    elif s[:6] == 'resare':
        s = s.replace('resare', '')
    else:
        print('NO')
        exit()

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

Submission status: Runtime Error

Solution code:
s = str(input())[::-1]
print(s)
while(len(s) >= 5):
    print(s)
    if s[:5] == 'maerd':
        s = s.replace('maerd', '')
    elif s[:7] == 'remaerd':
        s = s.replace('remerd', '')
    elif s[:5] == 'esare':
        s = s.replace('esare', '')
    elif s[:6] == 'resare':
        s = s.replace('resare', '')
    else:
        print('NO')
        exit()

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

Submission status: Runtime Error

Solution code:
S = input()

find_flag = 0
rest_S = S
while True:
    if len(rest_S) == 0:
        find_flag = 1
        break
    elif rest_S[-5:] in candidates:
        rest_S = rest_S[:-5]
    elif rest_S[-6:] in candidates:
        rest_S = rest_S[:-6]
    else:
        break

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

Submission status: Runtime Error

Solution code:
s = input()

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

Submission status: Runtime Error

Solution code:
def solve():
    S = input()
    # print(S, len(S))

    S = S[::-1]
    words = ("dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1])

    def recur(i):
        if i >= len(S):
            return True

        for word in words:
            if S[i:i + len(word)] == word:
                if recur(i + len(word)):
                    return True
        return False

    ans = recur(0)

    return ans


if __name__ == '__main__':
    res = solve()
    if res:
        print("YES")
    else:
        print("NO")

Submission status: Runtime Error

Solution code:
T = input()
S = ''
p,q,r,s = 'maerd','esare','remaerd','resare'
for i in range(len(T)):
    S += T[len(T)-i]
while len(S) >= 7:
    x = S[:5]
    y = S[:6]
    z = S[:7]
    if x == p or x == q:
        if len(S) > 5:
            S = S[5:]
        else:
            S = ''
    elif y == s:
        if len(S) > 6:
            S = S[6:]
        else:
            S = ''
    elif z == r:
        if len(S) > 7:
            S = S[7:]
        else:
            S = ''
    else:
        break
ans = 'NO'
if len(S) == 0:
    ans = 'YES'
print(ans)

Submission status: Runtime Error

Solution code:
T = input()
S = ''
p,q,r,s = 'maerd','esare','remaerd','resare'
for i in range(len(T)):
    S += T[len(T)-i]
while len(S) >= 7:
    x = S[:5]
    y = S[:6]
    z = S[:7]
    if x == p or x == q:
        if len(S) > 5:
            S = S[5:]
        else:
            S = ''
    elif y == s:
        if len(S) > 6:
            S = S[6:]
        else:
            S = ''
    elif z == r:
        if len(S) > 7:
            S = S[7:]
        else:
            S = ''
    else:
        break
ans = 'NO'
if len(S) == 0:
    ans = 'YES'

Submission status: Runtime Error

Solution code:
s = input()
l = len(s)
#後ろから見たら一意
import sys
i = l-1
try:
    while i>0:
        if s[i]=="r":
            if s[i-5:i+1]=="eraser":
                i-=6
            elif s[i-6:i+1]=="dremer":
                i-=7
        else:
            if s[i-4:i+1]=="erase":
                i-=5
            elif s[i-4:i+1]=="dream":
                i -= 5
        	else:
            	print("NO")###
            	sys.exit()
    print("YES")
except:
    print("NO")

Submission status: Runtime Error

Solution code:
s=input()
s=s.replace("dream","D")
s=s.replace("erase","E")
n=len(s)
i=0
while i<n:
    if s[i]=="D":
        if i+2<n:
            if s[i:i+3]=="Der":
                i+=3
            else:
                i+=1
        else:
            i+=1
    elif s[i]=="E":
        if i+1<n:
            if s[i:i+2]=="Er":
                i+=2
            else:
                i+=1
        else:
            i+=1
    else:
        break
else:
    print("YES")
    sys.exit()
print("NO")

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

N, K, L = map(int, input().split())
edge1 = [[] for _ in range(N)]
edge2 = [[] for _ in range(N)]

for _ in range(K):
    p, q = map(int, sys.stdin.readline().split())
    edge1[p-1].append(q-1)
    edge1[q-1].append(p-1)

for _ in range(L):
    p, q = map(int, sys.stdin.readline().split())
    edge2[p-1].append(q-1)
    edge2[q-1].append(p-1)


def dfs(edges):
    groups = [-1]*N

    for i in range(N):
        if groups[i] != -1:
            continue

        groups[i] = i
        stack = [i]
        while stack:
            v = stack.pop()
            for dest in edges[v]:
                if groups[dest] != -1:
                    continue
                groups[dest] = i
                stack.append(dest)

    return groups


g1, g2 = dfs(edge1), dfs(edge2)
d = Counter()
for i in range(N):
    d[(g1[i], g2[i])] += 1

print(*(d[(g1[i], g2[i])] for i in range(N)))

Submission status: Runtime Error

Solution code:
# 文字列反転
def rev (s):
    _re=''.join(list(reversed(s)))
    return _re
 
name = ['dream','dreamer','eraser','erase']
S = input()
S_re = rev(S)
can2 = False
i= 0
while i < len(S_re):
    can = False
    can2 = False
    for div in name:
        if len(S_re[i:]) >= len(div):
            if S_re[i:i+len(div)]==rev(div) :
                i+=len(div)
                can = True
                break
    if can :
        can2 = True
    else:
        can2 = False
        break
if can2:
    print('YES')
else :
    print('No')
 
 coding: utf-8
# 文字列反転
def rev (s):
    _re=''.join(list(reversed(s)))
    return _re

name = ['dream','dreamer','eraser','erase']
S = input()
S_re = rev(S)
can2 = False
i= 0
while i < len(S_re):
    can = False
    can2 = False
    for div in name:
        if len(S_re[i:]) >= len(div):
            if S_re[i:i+len(div)]==rev(div) :
                i+=len(div)
                can = True
                break
    if can :
        can2 = True
    else:
        can2 = False
        break
if can2:
    print('YES')
else :
    print('NO')

Submission status: Runtime Error

Solution code:
# coding: utf-8
# 文字列反転
def rev (s):
    _re=''.join(list(reversed(s)))
    return _re

name = ['dream','dreamer','eraser','erase']
S = input()
S_re = rev(S)
can2 = False
i= 0
while i < len(S_re):
    for div in name:
        if len(S_re[i:]) >= len(div):
            if S_re[i:i+len(div)]==rev(div) :
                i+=len(div)
                can = True
                break
    if can :
        can2 = True
    else:
        can2 = False
        break
if can2:
    print('YES')
else :
    print('NO')

Submission status: Runtime Error

Solution code:
 coding: utf-8
# 文字列反転
def rev (s):
    _re=''.join(list(reversed(s)))
    return _re

name = ['dream','dreamer','eraser','erase']
S = input()
S_re = rev(S)
can2 = False
i= 0
while i < len(S_re):
    can = False
    can2 = False
    for div in name:
        if len(S_re[i:]) >= len(div):
            if S_re[i:i+len(div)]==rev(div) :
                i+=len(div)
                can = True
                break
    if can :
        can2 = True
    else:
        can2 = False
        break
if can2:
    print('YES')
else :
    print('No')

Submission status: Runtime Error

Solution code:
ef rev (s):
    _re=''.join(list(reversed(s)))
    return _re

name = ['dream','dreamer','eraser','erase']
S = input()
S_re = rev(S)
can = False
can2 = False
for i in range(len(S_re)):
    for div in name:
        if S_re[i:i+len(div)]==rev(div) :
            i+=len(div)
            can = True
        if can :
            can2 = True
            break
    if not can2 :
        break
if can2 :
    print('YES')
else :
    print('No')

Submission status: Runtime Error

Solution 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')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
u=s[::-1]

k=[maerd,remaerd,esare,resare]

for i in k:
  if u.find(k):
    s.strip(k)
    
if u==[]:
  print("Yes")
  
else:
  print("No")

Submission status: Runtime Error

Solution code:
S = input()
S = S[::-1]
le = 0
while le != len(S):
  le = len(S)
  if S[0] == 'd' and S[1] == 'r' and S[2] == 'e' and S[3] == 'a' and S[4] == 'm':
    del S[0:4]
  if S[0] == 'e' and S[1] == 's' and S[2] == 'a' and S[3] == 'r' and S[4] == 'e':
    del S[0:4]
  if S[0] == 'r' and S[1] == 'e' and S[2] == 's' and S[3] == 'a' and S[4] == 'r' and S[5] == 'e':
    del S[0:5]
  if S[0] == 'r' and S[1] == 'e' and S[2] == 'm' and S[3] == 'a' and S[4] == 'e' and S[5] == 'r' and S[6] == 'd':
    del S[0:6]
if S == '':
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
erasedream

Submission status: Runtime Error

Solution code:
s = str(input())
n = len(s)
i = 0
d = ["dream", "dreamer"]
e = ["erase", "eraser"]
while i<n:
    if s[i]=="d":
        if s[i:i+5]==d[0]:
            i+=5
        else:
            break

        if s[i:i+3]=="era":
            continue
        elif s[i:i+2]!="er" and s[i+2]=="e":
            i+=2
        else:
            break
    elif s[i]=="e":
        if s[i:i+5]==e[0]:
            i+=5
        else:
            break

        if s[i:i+1]=="r":
            i+=1
        else:
            continue
    else:
        break
if i<n:
    print("NO")
else:
    print("YES")

Submission status: Runtime Error

Solution code:
s = input()
while len(s) >= 4:
  s.replace("eraser", "")
  s.replace("erase", "")
  s.replace("dreamer", "")
  s.replace("dream", "")
  if len(s) == 0:
    print('YES')
    return
print('NO')

Submission status: Runtime Error

Solution code:
s = input()
while len(s) <= 4:
  s.replace("eraser", "")
  s.replace("erase", "")
  s.replace("dreamer", "")
  s.replace("dream", "")
  if len(s) == 0:
    print('YES')
    return
print('NO')

Submission status: Runtime Error

Solution code:
s = list(input())

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

def func(s):
  bool = False
  for kw in kws:
    if s.startswith(kw):
      bool = bool or func(s[len(kw):])
  return bool

result = func(s)

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

Submission status: Runtime Error

Solution code:
def checkcheck(s):
    if s=="":
        return True
    else:
        if len(s)>=7:
            if s[-5:]=="dream" or s[-5:]=="erase":
                    s=s[:-5]
                    return checkcheck(s)
            elif s[-7:]=="dreamer":
                    s=s[:-7]
                    return checkcheck(s)
            
            elif s[-6:]=="eraser":
                    s=s[:-6]
                    return checkcheck(s) 
            else:
                s="WOW"
                return False


                
        elif len(s)==6:
            if s[-6:]=="eraser":
                return True
            else:
                return False
            
        elif len(s)==5:
            if s[-5:]=="dream" or s[-5:]=="erase":
                return True
            else:
                return False
        else:
            return False
  
s=input()
if checkcheck(s)==True:
    print("YES")
elif checkcheck(s)==False:
    print("NO")

Submission status: Runtime Error

Solution code:
def check(s):
    if s=="":
        return True
    else:
        if len(s)>=7:
            if s[-5:]=="dream" or s[-5:]=="erase":
                    s=s[:-5]
                    print(s)
                    return check(s)
                
            elif s[-7:]=="dreamer":
                    s=s[:-7]
                    print(s)
                    return check(s)
            
            elif s[-6:]=="eraser":
                    s=s[:-6]
                    print(s)
                    return check(s) 
            else:
              return False


                
        elif len(s)==6:
            if s[-6:]=="eraser":
                return True
            
            else:
                return False

            
        elif len(s)==5:
            if s[-5:]=="dream" or s[-5:]=="erase":
                return True
            else:
                return False

        else:
            return False
  
s=input()
if check(s):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s=input()
def check(s):
    if s=="":
        return True
    else:
        if len(s)>=7:
            if s[-5:]=="dream" or s[-5:]=="erase":
                    s=s[:-5]
                    return check(s)
                
            elif s[-7:]=="dreamer":
                    s=s[:-7]
                    return check(s)
                
            elif s[-6:]=="eraser":
                    s=s[:-6]
                    return check(s) 
                
                
        elif len(s)==6:
            if s[-6:]=="eraser":
                return True
            
            else:
                return False
            
        elif len(s)==5:
            if s[-5:]=="dream" or s[-5:]=="erase":
                return True
            
            else:
                return False
            
        else:
            return False
        
if check(s):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s=input()
def check(s):
    if s=="":
        return True
    else:
        if len(s)>=7:
            if s[-5:]=="dream" or s[-5:]=="erase":
                    return check(s[:-5])
                
            elif s[-7:]=="dreamer":
                    return check(s[:-7])
                
            elif s[-6:]=="eraser":
                    return check(s[:-6]) 
                
                
        elif len(s)==6:
            if s[-6:]=="eraser":
                return True
            
            else:
                return False
            
        elif len(s)==5:
            if s[-5:]=="dream" or s[-5:]=="erase":
                return True
            
            else:
                return False
            
        else:
            return False
        
if check(s):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s=input()
def check(s):
    if s=="":
        return True
    else:
        if len(s)>=7:
        	if s[-5:]=="dream" or s[-5:]=="erase":
                    return check(s[:-5])
                
            elif s[-7:]=="dreamer":
                    return check(s[:-7])
                
            elif s[-6:]=="eraser":
                    return check(s[:-6]) 
                
                
        elif len(s)==6:
            if s[-6:]=="eraser":
                return True
            
            else:
                return False
            
        elif len(s)==5:
            if s[-5:]=="dream" or s[-5:]=="erase":
                return True
            
            else:
                return False
            
        else:
            return False
        
if check(s):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s=input()
def check(s):
    if s=="":
        return True
    else:
        if len(s)>=7:
             if s[-5:]=="dream" or s[-5:]=="erase":
                    return check(s[:-5])
             elif s[-7:]=="dreamer":
                    return check(s[:-7])
             elif s[-6:]=="eraser":
                    return check(s[:-6]) 
                
        elif len(s)==6:
            if s[-6:]=="eraser":
                return True
        elif len(s)==5:
            if s[-5:]=="dream" or s[-5:]=="erase":
                return True
        else:
            return False

if check(s):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
def dividable(S):
    return ((S[:5]=='dream'   and dividable(S[5:])) or
            (S[:7]=='dreamer' and dividable(S[7:])) or
            (S[:5]=='erase'   and dividable(S[5:])) or
            (S[:6]=='eraser'  and dividable(S[6:])) or
            (S==''))

print('YES' if dividable(input()) else 'NO')

Submission status: Runtime Error

Solution code:
S = list(input())
tmp = ''
L = len(S)
S.append('0')
S.append('0')
ans = 0
for i in range(L):
    tmp += str(S[i])
    if tmp=='dream':
        if tmp+str(S[i+1])+str(S[i+2])+str(S[i+3])=='dreamera':
            ans += len(tmp)
            tmp = ''
        elif tmp+str(S[i+1])+str(S[i+2])=='dreamer':
            ans += len(tmp)+2
            tmp = ''
            i+=2
        else:
            ans += len(tmp)
            tmp = ''
    if tmp == 'erase':
        if tmp+str(S[i+1])=='eraser':
            ans += len(tmp)+1
            tmp  = ''
            i+=1
        else:
            ans += len(tmp)
            tmp = ''
if ans == L:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
a = input().split()
print(a[0][0] + a[1][0] + a[2][0])

Submission status: Runtime Error

Solution code:
def erase_check(i, s):
    if s[i:i + 5] == 'erase':
        i_next = erase_check(i + 5, s)
        if i_next == i + 5 and s[i_next] == 'r':
            return s_check(i_next + 1, s)
        else:
            return s_check(i_next, s)
    else:
        return i


def s_check(i, s):
    if s[i:i + 5] == 'dream':
        i_next = erase_check(i + 5, s)
        if i_next == i + 5 and s[i_next:i_next + 2] == 'er':
            return s_check(i_next + 2, s)
        else:
            return s_check(i_next, s)
    else:
        return erase_check(i, s)


s = input()

if s_check(0, s) == len(s):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s = input()
wordList =[ "eraser", "erase","dreamer", "dream"]
ansList = []
def ansFunc(s1, ansList):
    #ansCount = 0
    for w in wordList:
        #print(s1, w)
        if s1.startswith(w):
            s2 = s1.replace(w, "",1)
            if s2 == '':
                print("YES")
                ansList.append(1)
            else:
                ansFunc(s2, ansList)
ansFunc(s, ansList)
if len(ansList) ==0:
    print("NO")

Submission status: Runtime Error

Solution code:
s = input()
wordList = ['dream', 'dreamer', 'erase', 'eraser']
ansCount = 0
def ansFunc(s1, ansCount):
    for w in wordList:
        #print(s1, w)
        if s1.startswith(w):
            s2 = s1.replace(w, "")
            if s2 == '':
                print("YES")
                ansCount += 1
                return ansCount
            else:
                ansCount = ansFunc(s2, ansCount)
ansCount=ansFunc(s, ansCount)
#print("NO")

Submission status: Runtime Error

Solution code:
s = input()
wordList = ['dream', 'dreamer', 'erase', 'eraser']
ansCount = 0
def ansFunc(s1):
    for w in wordList:
        if s1.startswith(w):
            s1 = s1.replace(w, "")
            print(s1)
            if s1 == '':
                print("seikou")
                ansCount += 1
            else:
                ansFunc(s1)
ansFlg = ansFunc(s)
if ansFlg != 0:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s=input()
d='dream'
dr='dreamer'
e='erase'
er='eraser'
l=len(s)
def solve(s,end):
    if end==-1:
        print('YES')
        exit(0)
    if s[end-6:end+1]==dr:
        end-=7
    elif s[end-5:end+1]==er:
        end-=6
    elif s[end-4:end+1]==e or s[end-4:end+1]==d:
        end-=5
    else:
        print('NO')
        exit(0)
    solve(s,end)
solve(s,l-1)

Submission status: Runtime Error

Solution code:
s=str(input())
words=["dream", "dreamer", "erase", "eraser"]
N=max(len(words[0]),len(words[1]),len(words[2]),len(words[3]))
flag=0
while len(s)>=0:
  pos0=s[-N:].rfind(words[0])
  pos1=s[-N:].rfind(words[1])
  pos2=s[-N:].rfind(words[2])
  pos3=s[-N:].rfind(words[3])
  m=max(pos0,pos1,pos2,pos3)
  if m==-1:
    flag=1
    break
  else:
    pos=N-m
    s=s[:-pos]

if flag=1:
  print("NO")
else:
  print("YES")

Submission status: Runtime Error

Solution code:
S_input = str(input())
add_str_tuple = ("dream", "dreamer", "erase", "eraser")

def recur_add(T):
    if T == S_input:
        print("YES")
        exit()
    else:
        if S_input.startswith(T):
            for word in add_str_tuple:
                recur_add(T+word)
        else:
            return

recur_add("")
print("NO")

Submission status: Runtime Error

Solution code:
S_input = str(input())
add_str_taple = ("dream", "dreamer", "erase", "eraser")

def recur_add(T):
    if T == S_input:
        print("YES")
        exit()
    elif len(T) < len(S_input):
        if S_input.startswith(T):
            for word in add_str_taple:
                recur_add(T+word)
        else:
            return
    else:
        return

recur_add("")
print("NO")