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:
i = input()

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

Submission status: Runtime Error

Solution code:
x,y,l=0,5,len(s)
for _ in range(10**5):
  if x>=l-7:
    if x==l-7 and s[x:l]=='dreamer':
      print('YES')
    elif x==l-6 and s[x:l]=='eraser':
      print('YES')
    elif x==l-5 and (s[x:l]=='dream' or s[x:l]=='erase'):
      print('YES')
    else:
      print('NO')
    exit()
    
  if s[x:y]=='erase':
    x=y+1 if s[y]=='r' else y
    y=x+5
  elif s[x:y]=='dream':
    x=y+2 if s[x:y+2]=='er' else y
    y=x+5
  else:
    print('NO')
    exit()

Submission status: Runtime Error

Solution code:
s=input()
x,y,l=0,5,len(s)
for _ in range(10**5):
  if s[x:y]=='erase':
    x=y+1 if s[y]=='r' else y
    y=x+5
  elif s[x:y]=='dream':
    x=y+2 if s[x:y+2]=='er' else y
    y=x+5
  else:
    print('NO')
    eixt()
  if y>=l:
    if y==l:
       break
    else:
      if x<l:
        print('NO')
        exit()
      else:
        break
print('YES')

Submission status: Runtime Error

Solution code:
i = input()

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

ans = False

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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000000)

S = input()


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

print('YES')

Submission status: Runtime Error

Solution code:
S = input()
while len(S) > 0:
    if S[0] == 'd':
        if S[0:5] == 'dream':
            if S[5:7] == 'er':
                if S[7] == 'a':
                    S = S[5:]
                else:
                    S = S[7:]
            else:
                S = S[5:]
        else:
            print('NO')
            exit()
    elif S[0] == 'e':
        if S[0:5] == 'erase':
            if S[5] == 'r':
                S = S[6:]
            else:
                S = S[5:]
        else:
            print('NO')
            exit()
    else:
        print('NO')
        exit()

print('YES')

Submission status: Runtime Error

Solution code:
S = input()

while len(S) > 4:
  if S[0:5] == "dream":
    if S[0:7] == "dreamer":
      if S[7] == "a":
        S = S[5:]
      else:
        S = S[7:]
    else:
      S = S[5:]
  else:
    if S[0:5] == "erase":
      if S[0:6] == "eraser":
        S = S[6:]
      else:
        S = S[5:]
    else:
      print("NO")
if len(S) == 0:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
s = input()
def dfs(t):
    if t==s:
        return True
    if len(t)>=len(s):
        return False
    for i in ['dream', 'dreamer', 'erase', 'eraser']:
        if dfs(t+i):
            return True
    return False
if dfs(''):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
s = input()

while s != []:
  if s=='erase':
    s = s[]
  elif len(s)>5 and s[0:5]=='erasee':
    s = s[5:]
  elif len(s)>5 and s[0:5]=='erased':
    s = s[5:]
  elif s=='eraser':
    s = s[]
  elif len(s)>6 and s[0:6]=='erasere':
	s = s[6:]
  elif len(s)>6 and s[0:6]=='eraserd':
	s = s[6:]
  elif s=='dreamer':
    s = []
  elif len(s)>7 and s[0:7]='dreamere':
    s = s[7:]
  elif len(s)>7 and s[0:7]='dreamerd':
    s = s[7:]
  elif s='dream':
    s = s[]
  elif len(s)>5 and s[0:5]='dreamd':
    s = s[6:]
  print(s)
    
# dream dreamer erase eraser

Submission status: Runtime Error

Solution code:
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0
num=0
count = [0]*10000
while True:
    tmp = dire[count[num]]
    ind = i

    #if ind + len(dire[j]) <=len(S)+1:
        #print(j)
    for k in range(len(dire[count[num]])):
        if S[ind] != tmp[k]  or  i + len(dire[count[num]]) >=len(S)+1 :
            flag =0
            count[num]  += 1
            break
        else:
            ind = ind + 1
            if k==len(dire[count[num]])-1:
                i = i + len(dire[count[num]])
                num +=1
                flag = 1


    if   count[num] >= 4 and flag == 0:
        count[num] = 0
        num -= 1
        i = i - len(dire[count[num]])
        if count[num] != 3:
            count[num] += 1
        else:
            count[num] = 0
    if i >= len(S):
        print('YES')
        break
    elif count[0]==0 and flag == 0 and i <=0:
        print('NO')
        break

Submission status: Runtime Error

Solution code:
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0
num=0
count = [0]*100
while True:
    tmp = dire[count[num]]
    ind = i

    #if ind + len(dire[j]) <=len(S)+1:
        #print(j)
    for k in range(len(dire[count[num]])):
        if S[ind] != tmp[k]  or  i + len(dire[count[num]]) >=len(S)+1 :
            flag =0
            count[num]  += 1
            break
        else:
            ind = ind + 1
            if k==len(dire[count[num]])-1:
                i = i + len(dire[count[num]])
                num +=1
                flag = 1


    if   count[num] >= 4 and flag == 0:
        count[num] = 0
        num -= 1
        i = i - len(dire[count[num]])
        if count[num] != 3:
            count[num] += 1
        else:
            count[num] = 0
    if i >= len(S):
        print('YES')
        break
    elif count[0]==0 and flag == 0 and i <=0:
        print('NO')
        break

Submission status: Runtime Error

Solution code:
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0
num=0
count = [0]*100
while True:

    tmp = dire[count[num]]
    ind = i

    #if ind + len(dire[j]) <=len(S)+1:
        #print(j)
    for k in range(len(dire[count[num]])):
        if S[ind] != tmp[k]  or  i + len(dire[count[num]]) >=len(S)+1 :
            flag =0
            count[num]  += 1
            break
        else:
            ind = ind + 1
            if k==len(dire[count[num]])-1:
                i = i + len(dire[count[num]])
                num +=1
                flag = 1


    if   count[num] >= 4 and flag == 0:
        count[num] = 0
        num -= 1
        i = i - len(dire[count[num]])
        count[num] += 1

    if i >= len(S):
        print('YES')
        break
    elif count[0]==0 and flag == 0 and i <=0:
        print('NO')
        break

Submission status: Runtime Error

Solution code:
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0

while True:

    tmp = dire[j]
    ind = i

    if ind + len(dire[j]) <=len(S)+1:
        #print(j)
        for k in range(len(dire[j])):
            if S[ind] != tmp[k]:
                flag =0
                j += 1
                break
            else:
                ind = ind + 1
                if k==len(dire[j])-1:
                    i = i + len(dire[j])
                    flag = 1
                    old = len(dire[j])
                    old_j  = j
                    j=0
    else:
        j+=1
        if j==4:
            i=i-old
            j=old_j+1
            flag = 0

    if   j >= 4 and flag == 0 and i != 0:
        i = i - old
        j = old_j+1

    if i >= len(S):
        print('YES')
        break
    elif i <= 0 and j >= 3 and flag == 0:
        print('NO')
        break

Submission status: Runtime Error

Solution code:
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0

while True:

    tmp = dire[j]
    ind = i

    if ind + len(dire[j]) <=len(S)+1:
        #print(j)
        for k in range(len(dire[j])):
            if S[ind] != tmp[k]:
                flag =0
                j += 1
                break
            else:
                ind = ind + 1
                if k==len(dire[j])-1:
                    i = i + len(dire[j])
                    flag = 1
                    old = len(dire[j])
                    old_j  = j
                    j=0
    else:
        j+=1
        if j==4:
            i=i-old
            j=old_j+1

    if   j >= 4 and flag == 0 and i != 0:
        i = i - old
        j = old_j+1

    if i >= len(S)-1:
        print('YES')
        break
    elif i <= 0 and j >= 3 and flag == 0:
        print('NO')
        break

Submission status: Runtime Error

Solution code:
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0

while True:

    tmp = dire[j]
    ind = i

    if ind + len(dire[j]) <=len(S)+1:
    #    print(j)
        for k in range(len(dire[j])):

            if S[ind] != tmp[k]:
                flag =0
                j += 1
                break
            else:
                ind = ind + 1
                if k==len(dire[j])-1:
                    i = i + len(dire[j])
                    flag = 1
                    old = len(dire[j])
                    old_j  = j
                    j=0

    if   j >= 4 and flag == 0 and i != 0:
        i = i - old
        j = old_j+1

    if i >= len(S)-1:
        print('YES')
        break
    elif i <= 0 and j >= 3 and flag == 0:
        print('NO')
        break

Submission status: Runtime Error

Solution code:
s = input()
def check_and_cut(string):
    tmp = '123'
    flag = True
    if len(string) <= 4:
        pass
    else:
        if len(string) >4:
            if string[-5:] == 'dream':
                tmp = string[:-5]
                flag = False
            elif string[-5:] == 'erase':
                tmp = string[:-5]
                flag = False
        if len(string) >5 and flag:
            if string[-6:] == 'eraser':
                tmp = string[:-6]
                flag = False
        if len(string) >6 and flag:
            if string[-7:] == 'dreamer':
                tmp = string[:-7]
                flag = False
    #print(string,len(string),string[-6:],tmp,string[-6:] == 'eraser')
    if tmp == '':
        print('YES')
    else:
        if tmp == '123':
            print('NO')
        else:
            check_and_cut(tmp)
check_and_cut(s)

Submission status: Runtime Error

Solution code:
s = input()
def check_and_cut(string):
    tmp = '123'
    if len(string) <= 4:
        pass
    else:
        if len(string) >4:
            if string[-5:] == 'dream':
                tmp = string[:-5]
            elif string[-5:] == 'erase':
                tmp = string[:-5]
        if len(string) >5:
            if string[-6:] == 'eraser':
                tmp = string[:-6]
        if len(string) >6:
            if string[-7:] == 'dreamer':
                tmp = string[:-7]
    #print(string,len(string),string[-6:],tmp,string[-6:] == 'eraser')
    if tmp == '':
        print('YES')
    else:
        if tmp == '123':
            print('NO')
        else:
            check_and_cut(tmp)
check_and_cut(s)

Submission status: Runtime Error

Solution code:
def func(x):

    if len(x) == 0:
        return True
    elif len(x) < 5:
        return False
    else:
        if x[-5:] == "dream":
            return func(x[:-5])
        elif x[-7:] == "dreamer":
            return func(x[:-7])
        elif x[-5:] == "erase":
            return func(x[:-5])
        elif x[-6:] == "eraser":
            return func(x[:-6])
        else:
            return False

def solve(n):

    ans = func(n)
    return "YES" if ans else "NO"

if __name__ == "__main__":
    n = input()
    print(solve(n))

Submission status: Runtime Error

Solution code:
sys.setrecursionlimit(10000)
def func(x):

    if len(x) == 0:
        return True
    elif len(x) < 5:
        return False
    else:
        tmp = False
        if x[:5] == "dream":
            tmp = func(x[5:])

        if x[:7] == "dreamer" and not tmp:
            tmp = func(x[7:])

        if x[:5] == "erase" and not tmp:
            tmp = func(x[5:])

        if x[:6] == "eraser" and not tmp:
            tmp = func(x[6:])

    return tmp

def solve(n):

    ans = func(n)
    return "YES" if ans else "NO"

if __name__ == "__main__":
    n = input()
    print(solve(n))

Submission status: Runtime Error

Solution code:
def func(x):

    if len(x) == 0:
        return True
    elif len(x) < 5:
        return False
    else:
        tmp = False
        if x[:5] == "dream":
            tmp = func(x[5:])

        if x[:7] == "dreamer" and not tmp:
            tmp = func(x[7:])

        if x[:5] == "erase" and not tmp:
            tmp = func(x[5:])

        if x[:6] == "eraser" and not tmp:
            tmp = func(x[6:])

    return tmp

def solve(n):

    ans = func(n)
    return "YES" if ans else "NO"

if __name__ == "__main__":
    n = input()
    print(solve(n))

Submission status: Runtime Error

Solution code:
def func(x):

    if len(x) == 0:
        return True
    elif len(x) < 5:
        return False
    else:
        tmp = False
        if x[:5] == "dream":
            tmp = func(x[5:])

        if x[:7] == "dreamer" and not tmp:
            tmp = func(x[7:])

        if x[:5] == "erase" and not tmp:
            tmp = func(x[5:])

        if x[:6] == "eraser" and not tmp:
            tmp = func(x[6:])

    return tmp

def solve(n):

    t = ""
    ans = func(n, t)
    return "YES" if ans else "NO"

if __name__ == "__main__":
    n = input()
    print(solve(n))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
import random
def resolve():
    
    S=input()
    A="dream dreamer erase eraser".split()
    #print(A)
    que=[S]
    while(que!=[]):
        t=len(que)
        print(t)
        vS=que.pop(random.randint(0,t-1))
        if vS=="":
            print("YES")
            return
        for w in A:
            r=len(w)
            if vS[:r]==w:
                que.append(vS[r:])
        print(que,"k")    

    print("NO")
#%%submit!
resolve()

Submission status: Runtime Error

Solution code:
s = input()
while True:
    if s == '':
        print('YES')
        break
    if s.ends_with('eraser'):
        s.rstrip('eraser')
    elif s.ends_with('dreamer'):
        s.rstrip('dreamer')
    elif s.ends_with('dream'):
        s.rstrip('dream')
    elif s.ends_with('erase'):
        s.rstrip('erase')
    else:
        print('NO')
        break

Submission status: Runtime Error

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

def func(T):
  if len(T) > len(S): return False
  if T != S[:len(T)]: return False

  res = T == S
  if not res:
    for t in arr: res |= func(T+t)
  return res

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

Submission status: Runtime Error

Solution code:
import sys


def start_with(s):
    if s == '':
        print('YES')
        sys.exit(0)

    try:
        if s[0:5] == 'dream':
            start_with(s[5:])
        if s[0:7] == 'dreamer':
            start_with(s[7:])
        if s[0:5] == 'erase':
            start_with(s[5:])
        if s[0:6] == 'eraser':
            start_with(s[6:])
    except IndexError:
        return


S = input()
start_with(S)
print('NO')

Submission status: Runtime Error

Solution code:
n = int(input())
ti = [0] * (n-1)
xi = [0] * (n-1)
yi = [0] * (n-1)

P = 'Yes'


for i in range(n):
    tii, xii, yii = map(int, input().split())
    ti.append(tii)
    xi.append(xii)
    yi.append(yii)
    tc = ti[i-1] - ti[i]
    dest = abs(xi[i-1]+yi[i-1]+xi[i]+yi[i])
    if tc == dest: pass
    else: P = "No"

print(P)

Submission status: Runtime Error

Solution code:
s = input()
dp = [0]*(len(s) + 1)
dp[0] = 1
judge = 'NO'
word = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(s)):
  if d[i] = 0:
    continue
  for w in words():
    if s[i:i+len(w)] == w:
      dp[i+len(w)] = 1
    if dp[len(s)] == 1:
      judge = 'YES'
      break
print(judge)

Submission status: Runtime Error

Solution code:
s = input()
dp = [0]*(len(s) + 1)
dp[0] = 1
judge = 'No'
word = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(s)):
  if d[i] = 0:
    continue
  for w in words():
    if s[i:i+len(w)] == w:
      dp[i+len(w)] = 1
    if dp[len(s)] == 1:
      judge = 'Yes'
      break
print(judge)

Submission status: Runtime Error

Solution code:
S = input()
Srev = S[::-1]
 
if Srev.startswith('maerd'):
  Srev = Srev[5::]
  continue
elif Srev.startswith('remaerd'):
  Srev = Srev[7::]
  continue
elif Srev.startswith('esare'):
  Srev = Srev[5::]
  continue
elif Srev.startswith('resare'):
  Srev = Srev[6::]
  continue
elif Srev == '':
  print('YES')
  break
else:
  print('NO')
  break

Submission status: Runtime Error

Solution code:
S = input()
Srev = S.sort(reverse = True)

if Srev.startswith('maerd'):
  Srev = Srev[5::]
  continue
elif Srev.startswith('remaerd'):
  Srev = Srev[7::]
  continue
elif Srev.startswith('esare'):
  Srev = Srev[5::]
  continue
elif Srev.startswith('resare'):
  Srev = Srev[6::]
  continue
elif Srev == '':
  print('YES')
  break
else:
  print('NO')
  break

Submission status: Runtime Error

Solution code:
s = input()
s = s.replase('eraser', '')
s = s.replase('erase', '')
s = s.replase('dreamer', '')
s = s.replase('dream', '')

if l == '':
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
def checks(s) :
	ret = 'NO'
	if len(s) < 5 :
		return 'NO'
	elif( s[0] == 'd' ) :
		#dream
		if s[:5] == 'dream' :
			if len(s) != 5 :
				ret = checks(s[5:])
			else :
				return 'YES'
		#dreamer
		if ( len(s) > 6 ) and ( ret != 'YES' ) and s[:7] == 'dreamer' :
			if len(s) != 7 :
				ret = checks(s[7:])
			else :
				return 'YES'
	elif( s[0] == 'e' ) :
		#erase
		if s[:5] == 'erase' :
			if len(s) != 5 :
				ret = checks(s[5:])
			else :
				return 'YES'
		#eraser
		if ( len(s) > 5 ) and ( ret != 'YES' ) and s[:6] == 'eraser' :
			if len(s) != 6 :
				ret = checks(s[6:])
			else :
				return 'YES'
	else :
		return ret

S = input()

print(checks(S))

Submission status: Runtime Error

Solution code:
def checks(s) :
	ret = 'NO'
	if len(s) < 5 :
		return 'NO'
	elif( s[0] == 'd' ) :
		#dream
		if s[:5] == 'dream' :
			if len(s) != 5 :
				ret = checks(s[5:])
			else :
				return 'YES'
		#dreamer
		if ( len(s) > 6 ) and ( ret != 'YES' ) and (s[:7] == 'dreamer') :
			if len(s) != 7 :
				ret = checks(s[7:])
			else :
				return 'YES'
	elif( s[0] == 'e' ) :
		#erase
		if s[:5] == 'erase' :
			if len(s) != 5 :
				ret = checks(s[5:])
			else :
				return 'YES'
		#eraser
		if ( len(s) > 5 ) and ( ret != 'YES' ) and ( s[:6] == 'eraser' ) :
			if len(s) != 6 :
				ret = checks(s[6:])
			else :
				return 'YES'
	return ret

S = input()

print(checks(S))

Submission status: Runtime Error

Solution code:
def checks(s) :
	ret = 'NO'
	if len(s) < 5 :
		return 'NO'
	elif( s[0] == 'd' ) :
		#dream
		if s[:5] == 'dream' :
			if len(s) != 5 :
				ret = checks(s[5:])
			else :
				return 'YES'
		#dreamer
		if ( len(s) > 6 ) and ( ret != 'YES' ) and s[:7] == 'dreamer' :
			if len(s) != 7 :
				ret = checks(s[7:])
			else :
				return 'YES'
	elif( s[0] == 'e' ) :
		#erase
		if s[:5] == 'erase' :
			if len(s) != 5 :
				ret = checks(s[5:])
			else :
				return 'YES'
		#eraser
		if ( len(s) > 5 ) and ( ret != 'YES' ) and s[:6] == 'eraser' :
			if len(s) != 6 :
				ret = checks(s[6:])
			else :
				return 'YES'
	return ret

S = input()

print(checks(S))

Submission status: Runtime Error

Solution code:
from sys import stdin
import sys

S = stdin.readline().rstrip()
T = ''

#data = ['dream', 'dreamer', 'erase', 'eraser']
#data = ['dreamer', 'dream', 'eraser', 'erase']
data = ['dream', 'erase', 'dreamer', 'eraser']

pos = 0
while pos < len(S):
    if S[pos:pos+len(data[0])] == data[0]:
        pos = pos + len(data[0])
        flag_dream = True
    elif S[pos:pos+len(data[1])] == data[1]:
        pos = pos + len(data[1])
        flag_erase = True
    elif S[pos:pos+len(data[2])] == data[2]:
        pos = pos + len(data[2])
    elif S[pos:pos+len(data[3])] == data[3]:
        pos = pos + len(data[3])
    elif flag_dream and S[pos:pos+len('er')] == 'er':
        pos = pos + len('er')
        flag_dream = False
        flag_erase = False
    elif flag_erase and S[pos:pos+len('r')] == 'r':
        pos = pos + len('er')
        flag_dream = False
        flag_erase = False
    else:
        print('NO')
        sys.exit()


print('YES')

Submission status: Runtime Error

Solution code:
def resolve():
	s = input()
	if re.search("^(dream|dreamer|erase|eraser)+$", s):
		print("YES")
	else:
		print("NO")
resolve()

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 = input()
if (len(S) > 0) and (len(S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')) == 0):
print('YES')
else:
print('NO')

Submission status: Runtime Error

Solution code:
S = input()
if len(S) > 0 and len(S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')) == 0:
print('YES')
else:
print('NO')

Submission status: Runtime Error

Solution code:
S = input()

ans = 'NO'
def func(T):
    global ans
    if len(T) > len(S):
        return
    if S == T:
        ans = 'YES'
        return

    if S[len(T)] == 'd':
        func(T+'dream')
        func(T+'dreamer')
    if S[len(T)] == 'e':
        func(T+'erase')
        func(T+'eraser')

func('')

print(ans)

Submission status: Runtime Error

Solution code:
S = input()

ans = 'NO'
def func(T):
    global ans
    if len(T) > len(S):
        return
    if S == T:
        ans = 'YES'
        return

    func(T+'dream')
    func(T+'dreamer')
    func(T+'erase')
    func(T+'eraser')

func('')

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#C - Day dream
S_input = input()
S = S_input
for i in range(len(S_input)):
    S = S[:i]+S_input[len(S_input)-1-i]+S[i+1:]
#print(S)
#S_input = input()
    
#S = S_input[::-1]
end_flg = 1
while end_flg:
    if S.startswith('maerd'):
        S = S.replace('maerd', '', 1)
    elif S.startswith('remaerd'):
        S = S.reaplace('remaerd','',1)
    elif S.startswith('esare'):
        S = S.replace('esare','',1)
    elif S.startswith('resare'):
        S = S.replace('resare', '', 1)
    else:
        end_flg = 0
if len(S_input) == 0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
#C - Day dream
S_input = input()
S = S_input
for i in range(len(S_input)):
    S = S[:i]+S_input[len(S_input)-1-i]+S[i+1:]
#print(S)
#S_input = input()
    
#S = S_input[::-1]
end_flg = 1
while end_flg:
    if S.startswith('maerd'):
        S = S.replace('maerd', '', 1)
    elif S.startswith('remaerd'):
        S = S.reaplace('remaerd','',1)
    elif S.startswith('esare'):
        S = S.replace('esare','',1)
    elif S.startswith('resare'):
        S = S.replace('resare', '', 1)
    else:
        end_flg = 0
if len(S) == 0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
S_input = input()
    
S = S_input[::-1]
end_flg = 1
while end_flg:
    if S.startswith('maerd'):
        S = S.replace('maerd', '', 1)
    elif S.startswith('remaerd'):
        S = S.reaplace('remaerd','',1)
    elif S.startswith('esare'):
        S = S.replace('esare','',1)
    elif S.startswith('resare'):
        S = S.replace('resare', '', 1)
    else:
        end_flg = 0
if len(S) == 0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
#C - Day dream
S_input = input()
S = S_input[::-1]
end = 1
while end:
    if S.startswith('maerd'):
        S = S.replace('maerd', '', 1)
    elif S.startswith('remaerd'):
        S = S.reaplace('remaerd','',1)
    elif S.startswith('esare'):
        S = S.replace('esare','',1)
    elif S.startswith('resare'):
        S = S.replace('resare', '', 1)
    else:
        end = 0
if len(S) == 0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
#C - Day dream
S = input()
S = S[::-1]
end = 1
while end:
    if S.startswith('maerd'):
        S = S.replace('maerd', '', 1)
    elif S.startswith('remaerd'):
        S = S.reaplace('remaerd','',1)
    elif S.startswith('esare'):
        S = S.replace('esare','',1)
    elif S.startswith('resare'):
        S = S.replace('resare', '', 1)
    else:
        end = 0
if len(S) == 0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
S = input()
S = S[::-1]
isStrip = 0
end = 1
while end:
    isStrip = 0
    if S.startswith('maerd'):
        S = S.replace('maerd', '', 1)
    elif S.startswith('remaerd'):
        S = S.reaplace('remaerd','',1)
    elif S.startswith('esare'):
        S = S.replace('esare','',1)
    elif S.startswith('resare'):
        S = S.replace('resare', '', 1)
    else:
        end = 0
if len(S) == 0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
#C - Day dream
S = input()
S = S[::-1]
isStrip = 0
end = 1
while end:
    isStrip = 0
    if S.startswith('maerd'):
        S = S.replace('maerd', '', 1)
    elif S.startswith('remaerd'):
        S = S.reaplace('remaerd','',1)
    elif S.startswith('esare'):
        S = S.replace('esare','',1)
    elif S.startswith('resare'):
        S = S.replace('resare', '', 1)
    else:
        end = 0
if len(S) == 0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
s = input()


def solve(query):
    if query == "":
        print("YES")
        exit()
    for frag in ("eraser", "erase", "dream", "dreamer"):
        if query.startswith(frag):
            solve(query[len(frag):])


solve(s)
print("NO")

Submission status: Runtime Error

Solution code:
def check(string):
  l = len(string)

  if l == 0:
    return True
  
  if l < 5:
    return False

  if string[-5:] == 'dream':
    return check(string[:-5])
  if l >= 7 and string[-7:] == 'dreamer':
    return check(string[:-7])
  if string[-5:] == 'erase':
    return check(string[:-5])
  if l >= 6 and string[-6:] == 'eraser':
    return check(string[:-6])
      
  return False

S = input()
if check(S):
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
def main():
    Ss = input()
    S = list(Ss)
    now = 0
    T = ''
    Sr = []
    for i in range(1,len(S)+1):
        Sr[-i] = S[i-1]

    while True:
        tmp5 = Sr[now:now+5]
        tmp6 = Sr[now:now+6]
        tmp7 = Sr[now:now+7]
        if tmp5[0] == 'e' and tmp5 == ['e','s','a','r','e']:
            T += 'erase'
            now += 5
        elif tmp5[0] == 'm' and tmp5 == ['m','a','e','r','d']:
            T += 'dream'
            now += 5
        elif tmp6[0] == 'r' and tmp6 == ['r','e','s','a','r','e']:
            T += 'eraser'
            now += 6
        elif tmp7[0] == 'r' and tmp7 == ['r','e','m','a','e','r','d']:
            T += 'dreamer'
            now += 7
        else:
            print('NO')
            return

        if now >= len(S):
            break
    if Ss == T:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
S = input()

# print(S)
# print(len(S))


t_sub = ["dreamer", "dream", "eraser", "erase"]
i = 0


def check_1(S, i, t_sub):
    # print("check_1(",S,", ",i,")")
    for t in t_sub:
        # print("check ",t)
        if (S.find(t, i) == i):
            # print("hit " ,t,"at ",i)
            if (i+len(t) == len(S)):
                return "YES"
            else:
                if(check_1(S, i + len(t), t_sub) == "YES"):
                    return "YES"

    # print("cant find ",i )                
    return "NO"


print(check_1(S, i, t_sub))

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)

left = 0
right = 5
ok = True
while left <n:
    if left >n-1 or right > n:break
    if s[left:right] == "dream":
        
        if s[right:right+2] == "er" and s[right:right+5] != "erase" and s[right:right+6] != "eraser": 
            left = right+2
            right = min(left+5,n)
        else:
            left = right
            right = min(n,left+5)
    
    elif s[left:right] == "erase":
        
        if s[right] == 'r':
         
            left = right+1
            right = min(n,left+5)
        else:
            left = right
            right = min(n,left+5)
    else:
        ok = False
        break
if ok:print("YES")
else:print("NO")

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)

left = 0
right = 5
ok = True
while left <n:
    if s[left:right] == "dream":
        
        if s[right:right+2] == "er" and s[right:right+5] != "erase" and s[right:right+6] != "eraser": 
            left = right+2
            right = min(left+5,n)
        else:
            left = right
            right = min(n,left+5)
    
    elif s[left:right] == "erase":
        
        if s[right] == 'r':
         
            left = right+1
            right = min(n,left+5)
        else:
            left = right
            right = min(n,left+5)
    else:
        ok = False
        break
if ok:print("YES")
else:print("NO")

Submission status: Runtime Error

Solution code:
S = input()
T = ""
words = ["dream", "dreamer", "erase", "eraser"]
n = len(S)
def dfs(T, n):
  if len(T) == n:
    return T == S
  if len(T) < n:
    for i in words:
      nT = T + i
      if dfs(nT, n):
        return True
  return False
 
if dfs(T, n):
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
S = input()
T = ""
words = ["dream", "dreamer", "erase", "eraser"]
n = len(S)
def dfs(T, n):
  if len(T) == n:
    return T == S
  if len(T) < n:
    for i in words:
      nT = T + i
      if dfs(nT, n):
        return True
  return False

if dfs(T, n):
  print("YES")

Submission status: Runtime Error

Solution code:
import re

S = input()

s = re.sub(r"(dreamer)|(eraser)", "", s)
s = re.sub(r"(dream)|(erase)", "", S)

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