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 = str(input())
add_str_taple = ("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_taple:
                recur_add(T+word)
        else:
            return None

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()
    else:
        if S_input.startswith(T):
            for word in add_str_taple:
                recur_add(T+word)
        else:
            return

recur_add("")
print("NO")

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

s = ns()[::-1]
ans = "YES"

def func(spart):
    if spart[:5] == "maerd":
        if len(spart) == 5:
            return "YES"
        else:
            return func(spart[5:])
    elif spart[:7] == "remaerd":
        if len(spart) == 7:
            return "YES"
        else:
            return func(spart[7:])
    elif spart[:5] == "esare":
        if len(spart) == 5:
            return "YES"
        else:
            return func(spart[5:])
    elif spart[:6] == "resare":
        if len(spart) == 6:
            return "YES"
        else:
            return func(spart[6:])
    else:
        return "No"

print(func(s))

Submission status: Runtime Error

Solution code:
s = input()

words = ['dream', 'dreamer', 'erase', 'eraser']
def dfs(t):
    if t == '':
        return True
    ans = False
    for word in words:
        if t[:len(word)] == word:
            ans = ans or dfs(t[len(word):])

    return ans

if dfs(s):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

while s != '':
    tmp = s
    for word in words:
        s = re.sub(f'{word}$', '', s)
    if s == '':
        print('YES')
    if tmp == s:
        print('NO')
        break

Submission status: Runtime Error

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

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


def dayDream(word):
    if word[:7] in phrase:
        return dayDream(word[7:])
    elif word[:6] in phrase:
        return dayDream(word[6:])
    elif word[:5] in phrase:
        return dayDream(word[5:])
    
    if len(word)==0:
        return True
    else:
        return False

print("YES") if dayDream(s) else print("NO")

Submission status: Runtime Error

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

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


def dayDream(word):
    if word[:7] in phrase:
        return dayDream(word[7:])
    elif word[:6] in phrase:
        return dayDream(word[6:])
    elif word[:5] in phrase:
        return dayDream(word[5:])
    
    if len(word)==0:
        return True
    else:
        return False


print(dayDream(s))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scanln(&s)
	r := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	words := [][]rune{[]rune("maerd"), []rune("remaerd"), []rune("esare"), []rune("resare")}
	for {
		if len(r) == 0 {
			fmt.Println("YES")
			return
		}
		fail := 0
		for _, w := range words {
			if strings.HasPrefix(r, w) {
				r = r[len(w):]
				break
			} else {
				fail++
			}
		}
		if fail == len(words) {
			fmt.Println("NO")
			return
		}
	}
}

Submission status: Runtime Error

Solution code:
x = input()
n = len(x)
ans = "NO"

def f(i):
    if n==i:
        global ans
        ans = "YES"
    else:
        if x[i:i+5] == "dream":
            f(i+5)
        if x[i:i+7] == "dreamer":
            f(i+7)
        if x[i:i+5] == "erase":
            f(i+5)
        if x[i:i+6] == "eraser":
            f(i+6)
f(0)
print(ans)

Submission status: Runtime Error

Solution code:
s = input()

words = {'dream', 'dreamer', 'erase', 'eraser'}

def is_prefix_daydream(s, prefix):
    if s == prefix:
        return True
    elif s.startswith(prefix):
        return is_daydream(s[len(prefix):])
    else:
        return False

def is_daydream(s):
    if s == '':
        return True
    else:
        return any(is_prefix_daydream(s, w) for w in words)

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

Submission status: Runtime Error

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


def fn(i):
    if i == 0:
        print('YES')
        exit()
    for tg in targets:
        if S[i - len(tg):i][::-1] == tg[::-1]:
            fn(i - len(tg))
    print('No')
    exit()


fn(len(S))

Submission status: Runtime Error

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


def fn(i):
    if len(S) == i:
        print('YES')
        exit()
    for tg in targets:
        if S[i: i + len(tg)] == tg:
            fn(i + len(tg))


fn(0)
print('No')

Submission status: Runtime Error

Solution code:
s = input()
S = [s[i] for i in range(len(s))]
a = input()

def flag(list_s):
    flag_yes = True
    if len(list_s)<=4:
        flag_yes=False
    else:
        flag_dreamer = False
        while len(list_s)>0 and flag_yes: #listが空でなく、まだ条件を満たしている時
            if flag_dreamer and len(list_s)>=4 and list_s[:4]==['a','s','e','r']: #dreameraser
                list_s = list_s[4:]
                flag_dreamer=False
            elif flag_dreamer and len(list_s)>=3 and list_s[:3]==['a','s','e']: #dreamerase
                list_s = list_s[3:]
                flag_dreamer=False
            elif len(list_s)>=5 and list_s[0:5]==['e','r','a','s','e']: #eraseまたはeraserなら消去して初期化
                flag_dreamer=False
                list_s = list_s[5:]
                if len(list_s)>0 and list_s[0]=='r':
                    list_s = list_s[1:]
            elif list_s == ['d', 'r', 'e', 'a', 'm']: #[dream]なら全消去
                flag_dreamer=False
                list_s = list_s[5:]
            elif len(list_s)>=6 and list_s[:6]==['d', 'r', 'e', 'a', 'm', 'd']: #dreamdream or dreamdreamerなら前半消去
                flag_dreamer=False
                list_s = list_s[5:]
            elif len(list_s)>=7 and list_s[:7]==['d', 'r', 'e', 'a', 'm', 'e', 'r']: #dreamerが面倒
                flag_dreamer=True
                list_s = list_s[7:]
            else:
                flag_yes = False
    return flag_yes
        
if flag(S):
    print('YES')
else:
    print('No')

Submission status: Runtime Error

Solution code:
WORDS = (
  "dreamer",
  "eraser",
  "dream",
  "erase"
)

s = input()

result = "NO"

targets = [s]

def f(input_targets):
  global result
  output_targets = []
  if len(input_targets) == 0:
    return
  for t in input_targets:
    if t == "":
      result = "YES"
      return
    for word in WORDS:
      if t.startswith(word):
        new_target = t[len(word):]
        output_targets.append(new_target)
  del input_targets
  return f(output_targets)


_ = f(targets)

print(result)

Submission status: Runtime Error

Solution code:
WORDS = (
  "dreamer",
  "eraser",
  "dream",
  "erase"
)

s = input()

result = "NO"

targets = [s]

def f(input_targets):
  global result
  output_targets = []
  if len(input_targets) == 0:
    return
  for t in input_targets:
    if t == "":
      result = "YES"
      return
    for word in WORDS:
      if t.startswith(word):
        new_target = t[len(word):]
        output_targets.append(new_target)
  return f(output_targets)


_ = f(targets)

print(result)

Submission status: Runtime Error

Solution code:
WORDS = (
  "dreamer",
  "eraser",
  "dream",
  "erase"
)

s = input()

result = "NO"

targets = [s]

def f(input_targets):
  global result
  output_targets = []
  if len(input_targets) == 0:
    return
  for t in input_targets:
    if t == "":
      result = "YES"
      return
    for word in WORDS:
      if t.startswith(word):
        new_target = t[len(word):]
        output_targets.append(new_target)
  return f(output_targets)

f(targets)

print(result)

Submission status: Runtime Error

Solution code:
WORDS = (
  "dreamer",
  "eraser",
  "dream",
  "erase"
)

s = input()

result = "NO"

targets = set([s])

def f(input_targets):
  global result
  output_targets = set()
  if len(input_targets) == 0:
    return
  for t in input_targets:
    if t == "":
      result = "YES"
      return
    for word in WORDS:
      if t.startswith(word):
        new_target = t[len(word):]
        output_targets.add(new_target)
  return f(output_targets)

f(targets)

print(result)

Submission status: Runtime Error

Solution code:
S=input()
l=len(S)
r=0
list5 = ['dream', 'erase']
list81 = ['dreamdre', 'dreamera', 'erasedre', 'eraseera']
list82 = ['dreamerd', 'dreamere']
list83 = ['eraserdr', 'eraserer']
if l<=4:
    print(NO)

while l>=5:
    if S[r:r+5] in list5:
        if r+5==l:
            print(YES)
            break
        elif r+5 == l-1:
            if S[r:r+6] == 'eraser':
                print(YES)
            else:
                print(NO)
            break
        elif r+5 == l-2:
             if S[r:r+7] == 'dreamer':
                 print(YES)
             else:
                 print(NO)
             break
        elif r+5 == l-3 or r+5 == l-4:
            print(NO)
            break
        else:
            if S[r:r+8] in list81:
                r=r+5
            elif S[r:r+8] in list82:
                r=r+7
            elif S[r:r+8] in list83:
                r=r+6
            else:
                print(NO)
                break
    else:
        print(NO)
        break

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = str(input())
str_list = ['dream', 'dreamer', 'erase', 'eraser']
dp = [0] * 10000

for i in range(len(S)):
    for s in str_list:
        if S[i:i+len(s)] == s:
            dp[i+len(s)] = 1

if dp[len(S)] == 1:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
str_list = ['dream', 'dreamer', 'erase', 'eraser']
dp = [0] * 10000

for i in range(len(S)):
    for s in str_list:
        if S[i:i+len(s)] == s:
            dp[i+len(s)] = 1

if dp[len(S)] == 1:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
str_list = ['dream', 'dreamer', 'erase', 'eraser']
dp = [0] * 100000

for i in range(len(S)):
    for s in str_list:
        if S[i:i+len(s)] == s:
            dp[i+len(s)] = 1

if dp[len(S)] == 1:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
import sys

s = sys.stdin.read().strip()
words = ["dream", "dreamer", "erase", "eraser"]

def dfs(i):
  for w in words:
    if s.startswith(w, i):
      n = i + len(w)
      if n == len(s):
        return True
      if dfs(n):
        return True
  return False

print("YES" if dfs(0) else "NO")

Submission status: Runtime Error

Solution code:
import sys

s = sys.stdin.read().strip()
words = ["dream", "dreamer", "erase", "eraser"]

def dfs(i):
  for w in words:
    if s.startswith(w, i):
      n = i + len(w)
      if n == len(s):
        print("YES")
        sys.exit(0)
      dfs(n)

dfs(0)
print("NO")

Submission status: Runtime Error

Solution code:
S = input()
for k in range(len(S)/5):
    for word in ["dream", "dreamer", "erase", "eraser"]:
        if S.endswith(word):
            S=S.rstrip(word)
if len(S)==0:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
S = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
while len(S) > 0:
  judge = [S.endwith(w) for w in words]
  # 逆から考えることで単語の重複をなくすのがポイント！
  if any(judge):
    hit_word = words[judge.index(True)]
    S = S[:-len(hit_words)]
    if len(S) == 0:
      print('YES')
      break
  else:
    print('NO')
    break

Submission status: Runtime Error

Solution code:
INPUT_STR = input()


match_patterns = [
    ''.join(list(reversed('dream'))),
    ''.join(list(reversed('dreamer'))),
    ''.join(list(reversed('erase'))),
    ''.join(list(reversed('eraser')))
]

reversed_input = ''.join(list(reversed(INPUT_STR)))


def is_concatted_string(string: str):
    if len(string) == 0:
        return True
    else:
        for pattern in match_patterns:
            if string.startswith(pattern):
                string = string[len(pattern):]
                return is_concatted_string(string)
        return False


if INPUT_STR != '' and is_concatted_string(reversed_input):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
INPUT_STR = input()


match_patterns = [
    ''.join(list(reversed('dream'))),
    ''.join(list(reversed('dreamer'))),
    ''.join(list(reversed('erase'))),
    ''.join(list(reversed('eraser')))
]

reversed_input = ''.join(list(reversed(INPUT_STR)))


def is_concatted_string(string: str):
    if len(string) == 0:
        return True
    else:
        for pattern in match_patterns:
            if string.startswith(pattern):
                string = string[len(pattern):]
                return is_concatted_string(string)


if INPUT_STR != '' and is_concatted_string(reversed_input):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
INPUT_STR = input()


match_patterns = [
    ''.join(list(reversed('dream'))),
    ''.join(list(reversed('dreamer'))),
    ''.join(list(reversed('erase'))),
    ''.join(list(reversed('eraser')))
]

reversed_input = ''.join(list(reversed(INPUT_STR)))


def is_concatted_string(string: str):
    if len(string) == 0:
        return True
    else:
        for pattern in match_patterns:
            if string.startswith(pattern):
                string = string[len(pattern):]
                return is_concatted_string(string)


if is_concatted_string(reversed_input):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

def dream(k):
    if k == N:
        return True
    if S[k] == 'd':
        if k+7 <= N:
            if S[k:k+7] == 'dreamer':
                if dream(k+7):
                   return True
        if k+5 <= N:
            if S[k:k+5] == 'dream':
                if dream(k+5):
                    return True
    elif S[k] == 'e':
        if k+6 <= N:
            if S[k:k+6] == 'eraser':
                if dream(k+6):
                    return True
        if k+5 <= N:
            if S[k:k+5] == 'erase':
                if dream(k+5):
                    return True
    return False

a = dream(0)
if a:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
S = input()
S.replace('dream','')
S.replace('dreamer','')
S.replace('erase','')
S.replace('eraser','')

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

Submission status: Runtime Error

Solution code:
s = input()
flag = True
while s:
    if s[0:5] == "dream":
        s = s[5:]
        if s[0:2] == "er":
            if s[0:5] != "erase":
                s = s[2:]
    elif s[0:5] == "erase":
        s = s[5:]
        if s[0] == "r":
            if s[0:5] != "erase":
                s = s[1:]
    else:
        flag = False
        break
if flag == True:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

N = int(input())
A = list(map(int, input().split()))

ans = 0
new_a = A.copy()
while 1:
    new_a = [a // 2 if a % 2 == 0 else -1 for a in new_a]
    if -1 in new_a:
        print(ans)
        exit()
    ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
daydream = ['reamd','reamerd','rasee','rasere']
S = input()
S = strip(S[0])
if 'reamd' in S:
    S = S.strip('reamed')
if 'reamrd' in S:
    S = S.strip('reamerd')
if 'rasee' in S:
    S = S.strip('rasee')
if 'rasere' in S:
    S = S.strip('rasere')
if not str:
    print('NO')
else:
    print('YES')

Submission status: Runtime Error

Solution code:
suf = ["dream", "dreamer", "erase", "eraser"]

s = input()
i = 0
while i < len(s):
  nx = s[i:i+5]
  if nx != suf[0] and nx != suf[2]:
    print("NO")
    exit(0)
  i += 5
  if s[i] == 'r':
  	i += 1
print("YES")

Submission status: Runtime Error

Solution code:
suf = ["dream", "dreamer", "erase", "eraser"]

s = input()
i = 0
while i < len(s):
	nx = s[i:i+5]
    if nx != suf[0] and nx != suf[2]:
      print("NO")
      exit(0)
    i += 5
    if s[i] == 'r':
      i += 1
print("YES")

Submission status: Runtime Error

Solution code:
S = input()
S_list = list(S)

while len(S_list) >= 5 :
    if S_list[0:5] == ['e', 'r', 'a', 's', 'e']:
        if S_list[5] == 'r' and len(S_list) >= 6:
            del S_list[0:6]
        else:
            del S_list[0:5]
    elif S_list[0:5] == ['d', 'r', 'e', 'a', 'm']:
        if S_list[5:8] == ['e', 'r', 'a'] and len(S_list) >= 8:
            del S_list[0:5]
        elif S_list[5:7] == ['e', 'r'] and S_list[7] != ['a'] and len(S_list) >= 8:
            del S_list[0:7]
        else :
            del S_list[0:5]
    else:
        print('NO')
        break


if len(S_list) == 0:
    print('YES')
elif 0<len(S_list)<5:
    print('NO')

Submission status: Runtime Error

Solution code:
S = input()
S_list = list(S)

while len(S_list) >= 5 :
    if S_list[0:5] == ['e', 'r', 'a', 's', 'e']:
        if S_list[5] == 'r':
            del S_list[0:6]
        else:
            del S_list[0:5]
    elif S_list[0:5] == ['d', 'r', 'e', 'a', 'm']:
        if S_list[5:8] == ['e', 'r', 'a']:
            del S_list[0:5]
        elif S_list[5:7] == ['e', 'r'] and S_list[7] != ['a']:
            del S_list[0:7]
        else :
            del S_list[0:5]
    else:
        print('NO')
        break


if len(S_list) == 0:
    print('YES')
elif 0<len(S_list)<5:
    print('NO')

Submission status: Runtime Error

Solution code:
S = input()
S_list = list(S)

while len(S_list) >= 5 :
    if S_list[0:5] == ['e', 'r', 'a', 's', 'e']:
        if S_list[5] == 'r':
            del S_list[0:6]
        else:
            del S_list[0:5]
    elif S_list[0:5] == ['d', 'r', 'e', 'a', 'm']:
        if S_list[5:8] == ['e', 'r', 'a']:
            del S_list[0:5]
        elif S_list[5:7] == ['e', 'r'] and S_list[7] != ['a']:
            del S_list[0:7]
        else :
            del S_list[0:5]
    else:
        print('No')
        break


if len(S_list) == 0:
    print('Yes')
elif 0<len(S_list)<5:
    print('No')

Submission status: Runtime Error

Solution code:

  print("No")

Submission status: Runtime Error

Solution code:
S = input()
r_S = S[::-1]
devide = ["dream", "dreamer", "erase", "eraser"]
r_devide = [d[::-1] for d in devide]
string = r_S

while string != '':
  can = False
  for d in r_devide:
    if string[:len(d)] == d:
      can = True
      string = string[len(d):]
      print(string)
  if can == False:
    break

if can:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
import sys
msg = str(input())

# 逆から、大きい文字数から、見ていけば重複は生じない
len_l1 = 0
while len(msg) != len_l1:
    len_l1 = len(msg)
    print(msg)
    
    # dreamer
    if msg[-7:] == "dreamer":
        msg = msg[:-7]
    # eraser
    if msg[-6:] == "eraser":
        msg = msg[:-6]
        
    # dreame
    if msg[-5:] == "dream":
        msg = msg[:-5]
    # erase
    if msg[-5:] == "erase":
        msg = msg[:-5]
        
    if len(msg) == 0:
        print('YES')
        sys.exit()    
    
print('NO')

Submission status: Runtime Error

Solution code:
S = input()

while True:
    if len(S) == 0:
        print('YES')
        break
    else:
        if S[-5:]=='dream':
            S = S[:-5]
        elif S[-7:] == 'dreamer':
            S = S[:-7]
        elif S[-5:]== 'erase':
            S = S[:-5]
        elif S[-6:] == X4:
            S = S[:-6]
        else:
            print('NO')
            break

Submission status: Runtime Error

Solution code:
s = str(input())[::-1]
while True:
    if s[:5]=="maerd" or s[:5]=="esare":
        s=s[5:]
        if len(s)==0:
            print("YES")
            exit()
    elif s[:6]=="resare"
        s=s[6:]
        if len(s)==0:
            print("YES")
            exit()
    elif s[:7]=="remaerd":
        s=s[7:]
        if len(s)==0:
            print("YES")
            exit()
    else:
        print("NO")
        exit()

Submission status: Runtime Error

Solution code:
def f(s):
    if len(s)==0:
        print("YES")
        exit()
    elif 1<=len(s)<=4:
        print("NO")
        exit()
    else:
        if s[0:5]=="maerd" or s[0:5]=="esare":
            s=s[5:]
            f(s)
        elif len(s)==5:
            print("NO")
            exit()
        elif s[0:6]=="resare":
            s=s[6:]
            f(s)
        elif len(s)==6:
            print("NO")
            exit()
        elif s[0:7]=="remaerd":
            s=s[7:]
            f(s)
        else:
            print("NO")
            exit()
S=input()
S=S[::-1]
f(S)

Submission status: Runtime Error

Solution code:
s = str(input())

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

new_s =reversed(s)
new_t = []
for item in T:
  new_t.append(reversed(item))

ans_t =''
  
for c in new_s:
  collector += c
  if collector in new_t:
    ans_t += collector
    collector = ''
    
if new_s == ans_t:
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
def rec(s):
  if s == '':
    return True
  else:
    res = False
    res = res or rec(s[7:]) if len(s) > 6 and s[0:7] == 'dreamer' else res
    res = res or rec(s[5:]) if len(s) > 4 and s[0:5] == 'dream' else res
    res = res or rec(s[5:]) if len(s) > 4 and s[0:5] == 'erase' else res
    res = res or rec(s[6:]) if len(s) > 5 and s[0:6] == 'eraser' else res
    return res
  
print('YES' if rec(input()) else 'NO')

Submission status: Runtime Error

Solution code:
def rec(s):
  if s == '':
    return True
  else:
    res = False
    res = res or rec(s[7:]) if s[0:7] == 'dreamer' else res
    res = res or rec(s[5:]) if s[0:5] == 'dream' else res
    res = res or rec(s[5:]) if s[0:5] == 'erase' else res
    res = res or rec(s[6:]) if s[0:6] == 'eraser' else res
    return res
  
print('YES' if rec(input()) else 'NO')

Submission status: Runtime Error

Solution code:
import numpy as np
S = str(input())
A = ['dream', 'dreamer', 'erase', 'eraseer']

N = len(S)
i = 0

def check(i): #i最初の文字
    flag0 = False
    flag1 = False
    flag2 = False
    flag3 = False
    flag4 = False
    flag5 = False
    if S[i:] == 'dream' or S[i:] == 'dreamer' or S[i:] == 'erase' or S[i:] == 'eraser':
        flag1 = True
    if S[i:i+7] == 'dreamer':
        flag2 = check(i+7)
    if S[i:i+5] == 'dream':
        flag3 =  check(i+5)
    if S[i:i+6] == 'eraser':
        flag4 =  check(i+6)
    if S[i:i+5] == 'erase':
        flag5 = check(i+5)
    return flag0 or flag1 or flag2 or flag3 or flag4 or flag5

if check(0):
    print ('YES')
else:
    print ('NO')

Submission status: Runtime Error

Solution code:
R = int(input())

if(R < 1200):
    print('ABC')
elif(R < 2800):
    print('ARC')
else :
    print('AGC')

Submission status: Runtime Error

Solution code:
S = input()

while True:
  if S[-5:] == 'dream':
    S = S[:-5]
    continue
  elif S[:-7] == 'dreamer':
    S = S[:-7]
    continue
  elif S[-5:] == 'erase':
    S = S[:-5]
    continue
  elif S[-7:] == 'eraser':
    S = S[:-7]
    continue
  break

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

Submission status: Runtime Error

Solution code:
from collections import deque

S = input()
q = deque(S)
temp = deque()
def delque(qu,str):
    for i in range(len(str)):
        qu.popleft()

while len(q) > 0:
    temp.append( q.popleft() )
    if len(temp) == 5:
        if ''.join(list(temp)) == 'dream':
            if len(q) > 0:
                a = q.popleft()
                temp.append(a)
            if a == 'd':
                delque(temp,'dream')
            elif a == 'e':
                if len(q) > 1:
                    b = q.popleft()
                    temp.append(b)
                    c = q.popleft()
                    temp.append(c)
                if b == 'r':
                    if c == 'a':
                        delque(temp,'dream')
                    elif c == 'd':
                        delque(temp,'dreamer')
                    elif c == 'e':
                        delque(temp,'dreamer')
                    
            
        if ''.join(list(temp)) == 'erase':
            if len(q) > 0:
                a = q.popleft()
                temp.append(a)
            if a == 'd' or a == 'e':
                delque(temp,'erase')
            elif a == 'r':
                delque(temp,'eraser')

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

Submission status: Runtime Error

Solution code:
q = deque(S)
temp = deque()
def delque(qu,str):
    for i in range(len(str)):
        qu.popleft()

while len(q) > 0:
    temp.append( q.popleft() )
    if len(temp) == 5:
        if ''.join(list(temp)) == 'dream':
            if len(q) > 0:
                a = q.popleft()
                temp.append(a)
            if a == 'd':
                delque(temp,'dream')
            elif a == 'e':
                if len(q) > 1:
                    b = q.popleft()
                    temp.append(b)
                    c = q.popleft()
                    temp.append(c)
                if b == 'r':
                    if c == 'a':
                        delque(temp,'dream')
                    elif c == 'd':
                        delque(temp,'dreamer')
                    elif c == 'e':
                        delque(temp,'dreamer')
                    
            
        if ''.join(list(temp)) == 'erase':
            if len(q) > 0:
                a = q.popleft()
                temp.append(a)
            if a == 'd' or a == 'e':
                delque(temp,'erase')
            elif a == 'r':
                delque(temp,'eraser')

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

Submission status: Runtime Error

Solution code:
s = input()
s = s.replace('eraser','z')
s = s.repalace('erase','z')
s = s.repalace('dreamer','z')
s = s.repalace('dream','z')
for  S in s:
    if S != 'z':
        print('NO')
    else:
        print('YES')

Submission status: Runtime Error

Solution code:
s = input()
s = s.replace('eraser','z')
s = s.repalace('erase','z')
s = s.repalace('dreamer','z')
s = s.repalace('dream','z')
for  S in s:
    if S != z:
        print('NO')
    else:
        print('YES')

Submission status: Runtime Error

Solution code:
def chk_str(instr):
    if instr == "" or instr == "er":
        return instr
    else:
        if instr[0:5] == "dream" or instr[0:5]== "erase":
            instr = instr[5:]
            return chk_str(instr)
        else:
            if instr[0:2] == "er":
                instr = instr[2:]
                return chk_str(instr)
            else:
                if instr[0:1] == "r":
                    instr = instr[1:]
                    return chk_str(instr)
                else:
                    return instr
            
# input
instr = str(input())
if instr[0:4] == "erer" or instr[-4:] == "erer" or instr == "" or instr == "er":
    print("NO")
else:
    if chk_str(instr) == "" or chk_str(instr) == "er":
        print("YES")
    else:
        print ("NO")

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
# sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

S = str(input())

def check(T,S):
    if T == S:
        return 1
    adds = ["dream","dreamer","erase","eraser"]
    for i,add in enumerate(adds):
        if S[len(T):len(T)+len(add)] == add:
            if check(T+add,S) == 1:
                return 1

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

Submission status: Runtime Error

Solution code:

def main():
    S = input()

    while True:
        result_1 = search('dreamer$', S)
        result_2 = search('eraser$', S)
        result_3 = search('erase$', S)
        result_4 = search('dream$', S)

        if result_1:
            S = S[:result_1.start()]
        elif result_2:
            S = S[:result_2.start()]
        elif result_3:
            S = S[:result_3.start()]
        elif result_4:
            S = S[:result_4.start()]
        else:
            print("NO")
            break

        if len(S) == 0:
            print("YES")
            break


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

def str_read(s):

    if len(s) == 0:
        return True
    else:
        flag: bool = False
        if s[0:5] in ['dream', 'erase']:
            flag = flag or str_read(s[5:])
        if s[0:6] in ['eraser']:
            flag = flag or str_read(s[6:])
        if s[0:7] in ['dreamer']:
            flag = flag or str_read(s[7:])
        return flag


si = input()

if str_read(si):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:

def str_read(s):

    if len(s) == 0:
        return True
    else:
        flag: bool = False
        if s[0:5] in ['dream', 'erase']:
            flag = flag or str_read(s[5:])
        if s[0:6] in ['eraser']:
            flag = flag or str_read(s[6:])
        if s[0:7] in ['dreamer']:
            flag = flag or str_read(s[7:])
        return flag


si = input()

if str_read(si):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:

def str_read(s):

    if len(s) == 0:
        return True
    else:
        flag = False
        if s[0:5] in ['dream', 'erase']:
            flag = flag or str_read(s[5:])
        if s[0:6] in ['eraser']:
            flag = flag or str_read(s[6:])
        if s[0:7] in ['dreamer']:
            flag = flag or str_read(s[7:])
        return flag


s = input()

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