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

import re

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


while len(list(S)) > 8: 
    if S[0] == 'd':
        if S[0:5] == 'dream':
            if S[5:10] == 'erase':
                S = S[5:]
                print(S)
            elif S[5:10] == 'dream':
                S = S[5:]
                print(S)
            elif S[5:7] == 'er':
                if S[7:12] == 'dream':
                    S = S[7:]
                    print(S)
                elif S[7:12] == 'erase':
                    S = S[7:]
                    print(S)
            else:break

    else:
        if S[0:6] == 'eraser':
            S = S[6:]
            print(S)
        elif S[0:5] == 'erase':
            if S[5:10] == 'erase':
                S = S[5:]
                print(S)
            elif S[5:10] == 'dream':
                S = S[5:]
                print(S)
        else:break
k = 0 
for l in li:
    if S == l:k = 1
if k == 0:print('No')
else:print('Yes')

Submission status: Runtime Error

Solution code:
WORDS = ['dream', 'dreamer', 'erase', 'eraser']


def main(s):
    for word in WORDS:
        if delete_word(s, word):
            print('YES')
            break
    else:
        print('NO')


def delete_word(s, word):
    if s.endswith(word):
        s = s[:-len(word)]
        if len(s) == 0:
            return True
        for w in WORDS:
            if delete_word(s, w):
                return True
    else:
        return False


if __name__ == "__main__":
    main(input())

Submission status: Runtime Error

Solution code:
def main(s):
    for word in ['dream', 'dreamer', 'erase', 'eraser']:
        if delete_word(s, word):
            print('YES')
            break
    else:
        print('NO')


def delete_word(s, word):
    if s.startswith(word):
        s = s[len(word):]
        if len(s) == 0:
            return True
        for w in ['dream', 'dreamer', 'erase', 'eraser']:
            if delete_word(s, w):
                return True
    else:
        return False


if __name__ == "__main__":
    main(input())

Submission status: Runtime Error

Solution code:
WORDS = ['dream', 'dreamer', 'erase', 'eraser']


def main(s):
    for word in WORDS:
        if delete_word(s, word):
            print('YES')
            break
    else:
        print('NO')


def delete_word(s, word):
    if s.startswith(word):
        s = s[len(word):]
        if len(s) == 0:
            return True
        for w in WORDS:
            if delete_word(s, w):
                return True
    else:
        return False


if __name__ == "__main__":
    main(input())

Submission status: Runtime Error

Solution code:
WORDS = ['dream', 'dreamer', 'erase', 'eraser']


def main(s):
    for word in WORDS:
        if delete_word(s, word):
            print('YES')
            break
    else:
        print('NO')


def delete_word(s, word):
    if s.startswith(word):
        s = s[len(word):]
        if len(s) == 0:
            return True
        for word in WORDS:
            if delete_word(s, word):
                return True
    else:
        return False


if __name__ == "__main__":
    main(input())

Submission status: Runtime Error

Solution code:
def hantei(S):
  if S == 'dream' or S == 'dreamer' or S == 'erase' or S == 'eraser':
    return 1
  if S[:5] == 'dream':
    if S[:7] == 'dreamer':
      return hantei(S[5:]) | hantei(S[7:])
    else:
      return hantei(S[5:])
  if S[:5] == 'erase':
    if S[:6] == 'eraser':
      return hantei(S[5:]) | hantei(S[6:])
    else:
      return hantei(S[5:])
  else:
    return 0

S = input()
if(hantei(S)):
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
import sys
import resource
sys.setrecursionlimit(100000)

def hantei(S):
  if S == 'dream' or S == 'dreamer' or S == 'erase' or S == 'eraser':
    return 1
  if S[:5] == 'dream' 
    if S[:7] == 'dreamer'
      return hantei(S[5:]) | hantei(S[7:])
    else:
      return hantei(S[5:])
  if S[:5] == 'erase' 
    if S[:6] == 'eraser'
      return hantei(S[5:]) | hantei(S[6:])
    else:
      return hantei(S[5:])
  else:
    return 0

S = input()
if(hantei(S)):
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
s = input()


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



solve(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = input()
if re.match("^(dream|dreamer|erase|eraser)+$", s):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return ''.join(sm)

def jfws(s):
    print(s)
    fws=fnw(5,s)
    # print(fws)
    if fws=='dream':
        fws=fnw(2,s)
        if fws=='er':
            if s:
                if s[0]=='a':
                    s.extendleft(deque(reversed(list(fws))))
        else:
            s.extendleft(deque(reversed(list(fws))))
        return False
    elif fws=='erase':
        fws=fnw(1,s)
        if fws!='r' or '':
            s.appendleft(fws)
        return False
    else:
        return True 

def main(s):
    while s:
        if jfws(s):
            return 'NO'
        print(s)
    return 'YES'

s=deque(sys.stdin.readline().strip())
print(main(s))

Submission status: Runtime Error

Solution code:
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return ''.join(sm)

def jfws(s):
    # print(s)
    fws=fnw(5,s)
    # print(fws)
    if fws=='dream':
        fws=fnw(2,s)
        if fws=='er':
            if s[0]=='a':
                s.extendleft(deque(reversed(list(fws))))
        else:
            s.extendleft(deque(reversed(list(fws))))
        return False
    elif fws=='erase':
        fws=fnw(1,s)
        if fws!='r':
            s.appendleft(fws)
        return False
    else:
        return True 

def main(s):
    while bool(s):
        if jfws(s):
            return 'NO'
    return 'YES'

s=deque(sys.stdin.readline().strip())
print(main(s))

Submission status: Runtime Error

Solution code:
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return ''.join(sm)

def jfws(s):
    print(s)
    fws=fnw(5,s)
    # print(fws)
    if fws=='dream':
        fws=fnw(2,s)
        if fws=='er':
            if s[0]=='a':
                s.extendleft(deque(reversed(list(fws))))
        else:
            s.extendleft(deque(reversed(list(fws))))
        return False
    elif fws=='erase':
        fws=fnw(1,s)
        if fws!='r':
            s.appendleft(fws)
        return False
    else:
        return True 

def main(s):
    while bool(s):
        if jfws(s):
            return 'NO'
    return 'YES'

s=deque(sys.stdin.readline().strip())
print(main(s))

Submission status: Runtime Error

Solution code:
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return ''.join(sm)

def jfws(s):
    fws=fnw(5,s)
    # print(fws)
    if fws=='dream':
        fws=fnw(2,s)
        if fws=='er':
            if s[0]=='a':
                s.extendleft(deque(reversed(list(fws))))
        else:
            s.extendleft(deque(reversed(list(fws))))
        return False
    elif fws=='erase':
        fws=fnw(1,s)
        if fws!='r':
            s.appendleft(fws)
        return False
    else:
        return True 

def main(s):
    while s:
        if jfws(s):
            return 'NO'
    return 'YES'

s=deque(sys.stdin.readline().strip(),10**5)
print(main(s))

Submission status: Runtime Error

Solution code:
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return ''.join(sm)

def jfws(s):
    fws=fnw(5,s)
    # print(fws)
    if fws=='dream':
        fws=fnw(2,s)
        if fws=='er':
            if s[0]=='a':
                s.extendleft(deque(reversed(list(fws))))
        else:
            s.extendleft(deque(reversed(list(fws))))
        return False
    elif fws=='erase':
        fws=fnw(1,s)
        if fws!='r':
            s.appendleft(fws)
        return False
    else:
        return True 

def main(s):
    while s:
        if jfws(s):
            return 'NO'
    return 'YES'

s=deque(sys.stdin.readline().strip())
print(main(s))

Submission status: Runtime Error

Solution code:
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return ''.join(sm)

def jfws(s):
    fws=fnw(5,s)
    print(fws)
    if fws=='dream':
        fws=fnw(2,s)
        if fws=='er':
            if s[0]=='a':
                s.extendleft(deque(reversed(list(fws))))
        else:
            s.extendleft(deque(reversed(list(fws))))
        return False
    elif fws=='erase':
        fws=fnw(1,s)
        if fws!='r':
            s.appendleft(fws)
        return False
    else:
        return True 

def main(s):
    while s:
        if jfws(s):
            return 'NO'
    return 'YES'

s=deque(sys.stdin.readline().strip())
print(main(s))

Submission status: Runtime Error

Solution code:
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return ''.join(sm)

def jfws(s):
    fws=fnw(5,s)
    if fws=='dream':
        fws=fnw(2,s)
        if fws=='er':
            if s[0]=='a':
                s.extendleft(deque(reversed(list(fws))))
        else:
            s.extendleft(deque(reversed(list(fws))))
        return False
    elif fws=='erase':
        fws=fnw(1,s)
        if fws!='r':
            s.appendleft(fws)
        return False
    else:
        return True 

def main(s):
    while True:
        if not list(s):
            return 'Yes"
        if jfws(s):
            return 'NO'
    return 'Yes'

s=deque(sys.stdin.readline().strip())
print(main(s))

Submission status: Runtime Error

Solution code:
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return ''.join(sm)

def jfws(s):
    fws=fnw(5,s)
    if fws=='dream':
        fws=fnw(2,s)
        if fws=='er':
            if s[0]=='a':
                s.extendleft(deque(reversed(list(fws))))
        else:
            s.extendleft(deque(reversed(list(fws))))
        return False
    elif fws=='erase':
        fws=fnw(1,s)
        if fws!='r':
            s.appendleft(fws)
        return False
    else:
        return True 

def main(s):
    while True:
        if jfws(s):
            return 'NO'
        if not bool(s):
            return 'Yes'

s=deque(sys.stdin.readline().strip())
print(main(s))

Submission status: Runtime Error

Solution code:
import sys

def eat(i,candies,counter):
    s=candies[i]+candies[i-1]
    nc=max(0,s-x)
    counter+=nc
    candies[i]-=nc
    return counter

def main(n,x,candies):
    counter=0
    if candies[0]>x:
        counter=candies[0]-x
        candies[0]=x
    for i in range(1,n):
        counter=eat(i,candies,counter)
    return counter

n,x=map(int,sys.stdin.readline().strip().split())
candies=list(map(int,sys.stdin.readline().strip().split()))
print(main(n,x,candies))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import deque

s = input()
q = deque(list(s))

while q:
  if len(q) >= 5:
    subs = q.popleft()+q.popleft()+q.popleft()+q.popleft()+q.popleft()
    if subs != 'erase' and subs != 'dream':
      print('NO')
      exit()
    if subs == 'erase' and len(q) != 0 and q[0] == 'r':
      q.popleft()
    if subs == 'dream' and len(q) == 2 and q[0]+q[1] == 'er':
      q.popleft()
      q.popleft()
    if subs == 'dream' and len(q) >= 3 and q[0]+q[1] == 'er' and q[2] != e:
      q.popleft()
      q.popleft()
  else:
    print('NO')
    exit()
    
print('YES')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import rs
li = input()
flag = 'No'

if re.match("^(dream|dreamer|erase|eraser)+$", li):
  flag = 'YES'
      
  
print(flag)

Submission status: Runtime Error

Solution code:
li = list(input())
list = ['dream','dreamer','erase','eraser']
flag = 'No'
for x in list:
  for y in list:
    if x + y = li:
      flag = 'YES'
  
print(flag)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

int main(){
  string S,T;
  cin >> S;
  
  string dream = "dream";
  string dreamer = "dreamer";
  string erase = "erase";
  string eraser = "eraser";

  
  while(T != S){
    int countall = 0;
    int count1 = 0;
  for(int i = T.size(); i<T.size()+dream.size(); i++){
    if(S[i] != dream[i-T.size()]){
      count1++;
    }
  }
  if(count1 == 0) T += dream;
  if(count1) countall++;
  if(T == S) {
    cout << "YES" << endl;
    break;
  }

    int count2 = 0;
  for(int i = T.size(); i<T.size()+dreamer.size(); i++){
    if(S[i] != dreamer[i-T.size()]){
      count2++;
    }
  }
  if(count2 == 0) T += dreamer;
  if(count2) countall++;
  if(T == S){
    cout << "YES" << endl;
    break;
  }
  
    int count3 = 0;
  for(int i = T.size(); i<T.size()+erase.size(); i++){
    if(S[i] != erase[i-T.size()]){
      count3++;
    }
  }
  if(count3 == 0) T += erase;
  if(count3) countall++;
  if(T == S){
    cout << "YES" << endl;
    break;
  }
  
    int count4 = 0;
  for(int i = T.size(); i<T.size()+eraser.size(); i++){
    if(S[i] != eraser[i-T.size()]){
      count4++;
    }
  }
  if(count4 == 0) T += eraser;
  if(count4) countall++;
  if(T == S){
    cout << "YES" << endl;
    break;
  }
  
  if(countall == 4){
    cout << "NO" << endl;
    break;
  }
  }
  return 0;
}

Submission status: Runtime Error

Solution code:
from collections import deque
s = input()
n = len(s)

deque = deque()
deque.append(0)

def str_plus(i):
    s1 = s[i]
    if s1 == "d":
        if s[i:i+5] == "dream":
            if s[i+5:i+7] == "er":
                return [i+5,i+7]
            else:
                return [i+5]
    if s1 == "e":
        if s[i:i+5] == "erase":
            if s[i+5] == "r":
                return [i+5,i+6]
            else:
                return [i+5]

ans = "NO"

while deque:
    i = deque.pop()
    if i == n:
        ans = "YES"
        break
    l = str_plus(i)
    if l != None:
        deque.extend(l)

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
str_l = ["dream", "dreamer", "erase" ,"eraser"]
s = input()
n = len(s)

deque = deque()
deque.append(0)

def str_plus(i):
    s1 = s[i]
    if s1 == "d":
        if s[i:i+5] == "dream":
            if s[i+5:i+7] == "er":
                return [i+5,i+7]
            else:
                return [i+5]
        else:
            return False
    if s1 == "e":
        if s[i:i+5] == "erase":
            if s[i+5] == "r":
                return [i+5,i+6]
            else:
                return [i+5]
        else:
            return False

ans = "NO"

while deque:
    i = deque.pop()
    if i == n:
        ans = "YES"
        break
    l = str_plus(i)
    if l != False and l != None:
        deque.extend(l)

print(ans)

Submission status: Runtime Error

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

answer = 'NO'


def possible(current):
    possible = []
    for string in U:
        if S.startswith(current + string):
            possible.append(string)
    return possible


def judge(current):
    if current == S:
        global answer
        answer = 'YES'
        return
    if answer == 'YES':
        return
    else:
        if possible(current) == []:
            return
        else:
            for candidate in possible(current):
                new = current + candidate
                if len(S) >= len(new):
                    judge(current + candidate)


judge('')

print(answer)

Submission status: Runtime Error

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

answer = 'NO'


def possible(current):
    possible = []
    for string in U:
        if S.startswith(current + string):
            possible.append(string)
    return possible


def judge(current):
    if current == S:
        global answer
        answer = 'YES'
        return
    if answer == 'YES' or len(S) < len(current):
        return
    else:
        if possible(current) == []:
            return
        else:
            for candidate in possible(current):
                new = current + candidate
                if len(S) >= len(new):
                    judge(current + candidate)


for string in U:
    judge(string)

print(answer)

Submission status: Runtime Error

Solution code:
import sys
def add_str(t="",wn=0,s=0):
    if t == st[s:s+wn] or t == "":
        if s+wn == len(st):
            print("YES")
            sys.exit()

        add_str("dream", 5, s+wn)
        add_str("dreamer", 7, s+wn)
        add_str("erase", 5, s+wn)
        add_str("eraser", 6, s+wn)
    else:
    	return
  

st=input()
add_str()
print("NO")

Submission status: Runtime Error

Solution code:
from sys import stdin
def S(): return stdin.readline().rstrip()

a = S()
def f(t,a):
    if t == a:
        return True
    elif len(a)<len(t):
        return False
    else:
        strl = {0:'dream',1:'dreamer',2:'erase',3:'eraser'}
        for i in range(4):
            tmp = strl[i]
            if t+tmp in a[:len(t+tmp)]:
                if f(t+tmp,a):
                    return True
        return False

if f('',a):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

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

## Library

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

## input

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

S = input()

## Logic

S = S[::-1]
print(S)

i = 0 
while i < len(S):
    if [i:i+7]=="remaerd":
        i = i + 7
    elif [i:i+6]=="resare":
        i = i + 6
    elif [i:i+5]=="maerd":
        i = i + 5
    elif [i:i+5]=="esare":
        i = i + 5
    else:
        print("NO")
        sys.exit()
print("YES")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import re

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

Submission status: Runtime Error

Solution code:
s = input()

dr = "dream"
dre = "dreamer"
er = "erase"
era = "eraser"

dr = dr[::-1]
dre = dre[::-1]
er = er[::-1]
era = era[::-1]

s = s[::-1]


flag = True
while True:
    if len(s) == 0:
        break
    elif s.startswith(dr):
        s.replace(dr, "", 1)
    elif s.startswith(dre):
        s.replace(dre, "", 1)
    elif s.startswith(er):
        s.repalce(er, "", 1)
    elif s.startswith(era):
        s.replace(era, "", 1)
    else:
        flag = False

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

Submission status: Runtime Error

Solution code:
s = input()

dr = "dream"
dre = "dreamer"
er = "erase"
era = "eraser"

dr = dr[::-1]
dre = dre[::-1]
er = er[::-1]
era = era[::-1]

s = s[::-1]

flag = True
while True:
    if s.length == 0:
        break
    elif s.startswith(dr):
        s.replace(dr, "", 1)
    elif s.startswi(dre):
        s.replace(dre, "", 1)
    elif s.startswith(er):
        s.repalce(er, "", 1)
    elif s.startswith(era):
        s.replace(era, "", 1)
    else:
        flag = False

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

Submission status: Runtime Error

Solution code:
IN = iter(Input.split('\n')).__next__
def input():
    return IN()
#ここから先

S=input()
T=[]

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

Submission status: Runtime Error

Solution code:
S = input()

while True:
    if len(S) == 0:
        print('YES')
        exit()
    if len(S) < 5:
        print('NO')
        exit()
    if S[:5] == 'dream':
        if len(S) > 6 and S[5:7] == 'er':
            if S[7] == 'a':
                S = S[5:]
            else :
                S = S[7:]
        else :
            S = S[5:]
    elif S[:5] == 'erase':
        if len(S) > 5 and S[5] == 'r':
            S = S[6:]
        else :
            S = S[5:]
    else :
        print('NO')
        exit()

Submission status: Runtime Error

Solution code:
S = input()
i = 0

while True:
    if len(S) == 0:
        print('YES')
        exit()
    if len(S) < 5:
        print('NO')
        exit()
    if S[:5] == 'dream':
        if S[5:7] == 'er':
            if S[7] == 'a':
                S = S[5:]
            else :
                S = S[7:]
        else :
            S = S[5:]
    elif S[:5] == 'erase':
        if S[5] == 'r':
            S = S[6:]
        else :
            S = S[5:]
    else :
        print('NO')
        exit()

Submission status: Runtime Error

Solution code:
s = input()

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

cnt = 0
t = ""
while cnt <= len(s) - 7:
    if s[cnt] == "d":
        if s[cnt+5] == "d":
            cnt += 5
            t += vocabs[0]
        elif s[cnt+5] == "e":
            if s[cnt+7] == "a":
                cnt += 5
                t += vocabs[0]
            else:
                cnt += 7
                t += vocabs[1]
        else:
            break
    elif s[cnt] == "e":
        if s[cnt+5] == "r":
            cnt += 6
            t += vocabs[3]
        else:
            cnt += 5
            t += vocabs[2]
    else:
        break

if s[cnt:] == vocabs[0]:
    t+= vocabs[0]
elif s[cnt:] == vocabs[1]:
    t+= vocabs[1]
elif s[cnt:] == vocabs[2]:
    t+= vocabs[2]
elif s[cnt:] == vocabs[3]:
    t+= vocabs[3]


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

Submission status: Runtime Error

Solution code:
スコード 

Copy
Copy
def main():
  S = input()
  while len(S)>=5:
    if len(S)>=7 and S[-7:]=="dreamer":
      S = S[:-7]
      continue
    
    elif len(S)>=6 and S[-6:]=="eraser":
      S = S[:-6]
      continue
    elif S[-5:]=="dream" or S[-5:]=="erase":
      S = S[:-5]
      continue
    else:
      break
  if len(S)==0:
    print('Yes')
  else:
    print('No')
    
main()

Submission status: Runtime Error

Solution code:
def dfs(string):
    can = ["dream", "dreamer", "erase", "eraser"]
    stack = []
    stack.append("dream")
    stack.append("dreamer")
    stack.append("erase")
    stack.append("eraser")
    while stack:
        judge = stack.pop()
        if judge == string:break
        for temp in can:
            ans = judge + temp
            print(ans)
            if ans == string[:len(ans)]:
                stack.append(ans)
    return "YES" if judge == string else "NO"

if __name__ == '__main__':
    s = input()
    print(dfs(s))

Submission status: Runtime Error

Solution code:
div = ["dream", "dreamer", "erase", "eraser"]
rev = []
t = ""
s_rev = s[::-1]
for d in div:
    rev.append(d[::-1])

result = True
i = 0
while i < len(s):
    can_divide = False
    for d in rev:
        if len(s_rev) - i >= len(d):
        	if s_rev[i:i + len(d)] == d:
	            can_divide = True
    	        i += len(d)
        	    break
    if not can_divide:
        result = False
        break

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

Submission status: Runtime Error

Solution code:
div = ["dream", "dreamer", "erase", "eraser"]
rev = []
t = ""
s_rev = s[::-1]
for d in div:
    rev.append(d[::-1])

result = True
i = 0
while i < len(s):
    can_divide = False
    for d in rev:
        print("rev:%d i:%d d:%d" % (len(s_rev), i, len(d)))
        if len(s_rev) - i > len(d) and s_rev[i:i + len(d)] == d:
            can_divide = True
            i += len(d)
            break
    if not can_divide:
        result = False
        break

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

Submission status: Runtime Error

Solution code:
div = ["dream", "dreamer", "erase", "eraser"]
rev = []
t = ""
s_rev = s[::-1]
for d in div:
    rev.append(d[::-1])

result = True
i = 0
while i < len(s):
    can_divide = False
    for d in rev:
        print("rev:%d i:%d d:%d" % (len(s_rev), i, len(d)))
        if len(s_rev) - i >= len(d) and s_rev[i:i + len(d)] == d:
            can_divide = True
            i += len(d)
            break
    if not can_divide:
        result = False
        break

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

Submission status: Runtime Error

Solution code:
div = ["dream", "dreamer", "erase", "eraser"]
rev = []
t = ""
s_rev = s[::-1]
for d in div:
    rev.append(d[::-1])

result = True
i = 0
while i < len(s):
    can_divide = False
    for d in rev:
        if len(s_rev) - i >= len(d) and s_rev[i:i + len(d)] == d:
            can_divide = True
            i += len(d)
    if not can_divide:
        result = False
        break

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

Submission status: Runtime Error

Solution code:
div = ["dream", "dreamer", "erase", "eraser"]
rev = []
t = ""
s_rev = s[::-1]
for d in div:
    rev.append(d[::-1])

result = True
i = 0
while i < len(s):
    print(i)
    can_divide = False
    for d in rev:
        if s_rev[i:i + len(d)] == d:
            can_divide = True
            i += len(d)
    if not can_divide:
        result = False
        break

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

Submission status: Runtime Error

Solution code:
s = input()
t = ""
while len(t) < len(s):
    target_len = len(s) - len(t)
    #print("target_len:%d s_len:%d t_len:%d" % (target_len, len(s), len(t)))

    if s[len(t)] == 'd':
        if target_len == 5:
            t += "dream"
        elif target_len == 7:
            t += "dreamer"
        elif target_len > 7:
            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 7 + 1] != "era":
                t += "dreamer"
            else:
                t += "dream"
        else:
            break
    else:
        if target_len == 5:
            t += "erase"
        elif target_len == 6:
            t += "eraser"
        elif target_len > 6:
            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 6 + 2] != "era":
                t += "eraser"
            else:
                t += "erase"
        else:
            break

    print(s, t, sep=" ")
    if s[0:len(t)] != t:
        break

print("YES" if s == t else "NO")

Submission status: Runtime Error

Solution code:
def resolve():
    '''
    code here
    '''
    S = input()
    is_flag = True
    while is_flag:
        # print(S, len(S))
        if len(S)>=5:
            temp = S[:5]
            # print(temp)
            if temp == 'dream':
                S = S[5:]
                if S[:5] == 'erase':
                    pass
                elif S[:2] == 'er':
                    S = S[2:]
                
            elif temp == 'erase':
                S = S[5:]
                if S[0] == 'r':
                    S = S[1:]
            else:
                print('NO')
                is_flag = False
        elif len(S) == 0:
            print('YES')
            is_flag = False
        else:
            print('NO')
            is_flag = False


if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
S = input()
l = []
def dfs(n):
  print(n)
  if n == len(S):
    l.append("Yes")
  if S[n:n+5] == "dream":
    dfs(n+5)
  if S[n:n+7] == "dreamer":
    dfs(n+7)
  if S[n:n+5] == "erase":
    dfs(n+5)
  if S[n:n+6] == "eraser":
    dfs(n+6)   
dfs(0)
if len(l) == 0:
  l.append("No")
print(l[0])

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
S = input()

    while len(S) >= 5:
        # Sを４つの単語で順に調べて刈っていく
        if len(S) >= 7 and S[-7:] == "dreamer":
            S = S[:-7]
            continue

        if len(S) >= 6 and S[-6:] == "eraser":
            S = S[:-6]
            continue

        elif S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue

        else:
            break

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

Submission status: Runtime Error

Solution code:
i = input().rstrip()

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

def exec(s):
    for t in T:
        if s.startswith(t):
            n = s.replace(t, '', 1)
            if len(n) == 0:
                print('YES')
                exit()
            else:
                exec(n)

exec(i)
print('NO')