Problem:


Score : 300 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Another string T is initially empty.
Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:

Append one of the following at the end of T: dream, dreamer, erase and eraser.

Constraints

1≦|S|≦10^5

S consists of lowercase English letters.

Input

The input is given from Standard Input in the following format:

S

Output

If it is possible to obtain S = T, print YES. Otherwise, print NO.

Sample Input 1

erasedream

Sample Output 1

YES

Append erase and dream at the end of T in this order, to obtain S = T.

Sample Input 2

dreameraser

Sample Output 2

YES

Append dream and eraser at the end of T in this order, to obtain S = T.

Sample Input 3

dreamerer

Sample Output 3

NO



Sample input:
erasedream


Sample output:
YES

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    S = input()[::-1]

    flag = True
    while S:
        if S[:5] == 'maerd':
            S = S[5:]
        elif S[:6] == 'remaerd':
            S = S[6:]
        elif S[:5] == 'esare':
            S = S[5:]
        elif S[:6] == 'resare':
            S = S[6:]
        else:
            flag = False
            break

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

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import re
S = input()
"""
metacharacter
^ = 文字列の先頭
| = or
+ = 直前のパターンを1回以上繰り返す
$ = 文字列の末尾
"""
if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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:
                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 fws!='':
            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: Wrong Answer

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:
                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'
    return 'YES'

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

Submission status: Wrong Answer

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 bool(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':
            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: Wrong Answer

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 not s:
        if jfws(s):
            return 'NO'
    return 'YES'

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

Submission status: Wrong Answer

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 not s:
        if jfws(s):
            return 'NO'
    return 'Yes'

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

Submission status: Wrong Answer

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

ans = 'YES'
i = 0
while i < len(s):
    ng = 1
    for j in range(4):
        if s[i:i+len(ls[j])] == ls[j]:
            i += len(ls[j])
            ng = 0
    if ng:
        ans = 'No'
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, deque, Counter
import math
 
# import copy
from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
 
def main():
    S = list(getS())
    tgt5 = [list(s) for s in ["dream", "erase"]]
    tgt6 = [list(s) for s in ["eraser"]]
    tgt7 = [list(s) for s in ["dreamer"]]
    dp = [0 for i in range(len(S)+1)]
    dp[0] = 1
    for i, c in enumerate(S):
        if dp[i] == 1:
            for tg in tgt5:
                if S[i: i+5] == tg and i+5 <= len(S):
                    dp[i+5] = 1
            for tg in tgt6:
                if S[i: i+6] == tg and i+6 <= len(S):
                    dp[i+6] = 1
            for tg in tgt7:
                if S[i: i+7] == tg and i+7 <= len(S):
                    dp[i+7] = 1

    print(dp)
    if dp[-1] == 1:
        print("YES")
    else: 
        print("NO")

    return


 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, deque, Counter
import math
 
# import copy
from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
 
def main():
    S = list(getS())
    tgt5 = [list(s) for s in ["dream", "erase", ]]
    tgt7 = [list(s) for s in ["dreamer", "eraser"]]
    dp = [0 for i in range(len(S)+1)]
    dp[0] = 1
    for i, c in enumerate(S):
        if dp[i] == 1:
            for tg in tgt5:
                if S[i: i+5] == tg and i+5 <= len(S):
                    dp[i+5] = 1
            for tg in tgt7:
                if S[i: i+7] == tg and i+7 <= len(S):
                    dp[i+7] = 1

    # print(dp)
    if dp[-1] == 1:
        print("YES")
    else: 
        print("NO")

    return


 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, deque, Counter
import math
 
# import copy
from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
 
def main():
    S = list(getS())
    tgt5 = [list(s) for s in ["dream", "erase", ]]
    tgt6 = [list(s) for s in ["dreamer", "eraser"]]
    dp = [0 for i in range(len(S)+1)]
    dp[0] = 1
    for i, c in enumerate(S):
        if dp[i] == 1:
            for tg in tgt5:
                if S[i: i+5] == tg and i+5 <= len(S):
                    dp[i+5] = 1
            for tg in tgt6:
                if S[i: i+6] == tg and i+6 <= len(S):
                    dp[i+6] = 1

    # print(dp)
    if dp[-1] == 1:
        print("YES")
    else: 
        print("NO")

    return


 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = input()
ls = {"dream","dreamer","erase","eraser"}
now = ""
for i in range(len(S)):
  now += S[i]
  if now in ls:
    if S[i] == "e":
      continue
    else:
      now = ""
if now == "":
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
S = input()
ls = {"dream","dreamer","erase","eraser"}
now = ""
for i in range(len(S)):
  now += S[i]
  if now in ls:
    now = ""
if now == "":
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
S = input()
K = S.replace("dream","")
L = K.replace("erase","")
M = L.replace("er","")
if M == "":
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
S = input()
ls = {"dream","dreamer","erase","eraser"}
now = ""
for i in range(len(S)):
  now += S[i]
  if now in ls:
    now = ""
if now == "":
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
r = 'YES'
while len(s):
    if s[:6] == 'dreamer'[::-1] or s[:6] == 'eraser'[::-1]:
        s = s[6:]
    elif s[:5] == 'dream'[::-1] or s[:5] == 'erase'[::-1]:
        s = s[5:]
    else:
        r = 'NO'
        break
print(r)

Submission status: Wrong Answer

Solution code:
s = input()
r = 'YES'
while len(s):
    if s[:6] == 'dreamer' or s[:6] == 'eraser':
        s = s[6:]
    elif s[:5] == 'dream' or s[:5] == 'erase':
        s = s[5:]
    else:
        r = 'NO'
        break
print(r)

Submission status: Wrong Answer

Solution code:
S = input()
replaced_t = S.replace('dreamer','').replace('dream', '').replace('eraseer', '').replace('erase', '')
if replaced_t:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
S = input ()
Z = ''.join(list(reversed(S)))
Z = Z.replace('resare', '')
Z = Z.replace('esare', '')
Z = Z.replace('remaerd', '')
Z = Z.replace('maerd', '')
z = len (Z)
if z == 0:
    print ('Yes')
else:
    print ('No')

Submission status: Wrong Answer

Solution code:
s = input()
 
kouho = ["dream", "dreamer", "erase", "eraser"]
 
s = s.replace(kouho[1], "").replace(kouho[3], "").replace(kouho[0], "").replace(kouho[2], "")
 
if s == "":
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
s = input()

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

s = s.replace(kouho[1], "").replace(kouho[0], "").replace(kouho[3], "").replace(kouho[2], "")

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

Submission status: Wrong Answer

Solution code:
s = input()

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

s = s.replace(kouho[0], "").replace(kouho[1], "").replace(kouho[2], "").replace(kouho[3], "")

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

Submission status: Wrong Answer

Solution code:
s = input()

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

s.replace(kouho[0], "").replace(kouho[1], "").replace(kouho[2], "").replace(kouho[3], "")

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	s = S().rstrip()
	while len(s) > 0:
		if s[-7:] == 'dreamer':
			s = s[:-7]
		if s[-5:] == 'dream':
			s = s[:-5]
		elif s[-6:] == 'eraser':
			s = s[:-6]
		elif s[-5:] == 'erase':
			s = s[:-5]
		else:
			print('NO')
			break
	else:
		print('YES')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = str(input())
string_array = ["dream", "dreamer", "erase", 'eraser']
output_string = []

def yes_no_func(value):
    if value == s:
        print("YES")
        exit()


after_string = string_array
for i in string_array:
    after_string = string_array.copy()
    after_string.remove(i)
    yes_no_func(i)
    for string in after_string:
        output_string.append(i + string)
        second_after_string = after_string.copy()
        yes_no_func(i + string)
        for second_string in second_after_string:
            output_string.append(i + string + second_string)
            third_after_string = second_after_string.copy()
            yes_no_func(i + string + second_string)
            for third_string in third_after_string:
                output_string.append(i + string + second_string + third_string)
                yes_no_func(i + string + second_string + third_string)


print("NO")

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
d = {'maerd', 'remaerd', 'esare', 'resare'}

cnt = 0
while cnt  < len(s):
    if s[cnt:cnt + 5] in d:
        cnt = cnt + 5
    elif cnt + 6 < len(s) and s[cnt:cnt + 6] in d:
        cnt = cnt + 6
    elif cnt + 7 < len(s) and s[cnt:cnt + 7] in d:
        cnt = cnt + 7
    else:
        print('NO')
        break
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
d = {'maerd', 'remaerd', 'esare', 'resare'}

cnt = 0
while cnt + 5 < len(s):
    if s[cnt:cnt + 5] in d:
        cnt = cnt + 5
    elif cnt + 6 < len(s) and s[cnt:cnt + 6] in d:
        cnt = cnt + 6
    elif cnt + 7 < len(s) and s[cnt:cnt + 7] in d:
        cnt = cnt + 7
    else:
        print('NO')
        break
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
S = list(input())
while True:
  if len(S) >= 5:
    if S[:5] == ["d", "r", "e", "a", "m"]:
      del S[:5]
    elif S[:5] == ["e", "r", "a", "s", "e"]:
      del S[:5]
    elif S[:6] == ["e", "r", "a", "s", "e", "r"]:
      del S[:6]
    elif S[:7] == ["d", "r", "e", "a", "m", "e", "r"]:
      del S[:7]
    else:
      print("NO")
      break
  elif len(S) == 0:
    print("YES")
    break
  else:
    print("NO")
    break

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    s=input()
    dp=[0]*(len(s)+1)
    dp[0]=1
    for i in range(5,len(s)+1):
        f=0
        if s[i-5:i]=="erase":
            dp[i]=dp[i]|dp[i-5]
        if s[i-5:i]=="dream":
            dp[i]=dp[i]|dp[i-5]
        if i>=6 and s[i-6:i]=="eraser":
            dp[i]=dp[i]|dp[i-6]
        if i>=7 and s[i-6:i]=="dreamer":
            dp[i]=dp[i]|dp[i-7]

    if dp[-1]:
        print('YES')
    else:print('NO')





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    s=input()
    dp=[0]*(len(s)+1)
    dp[0]=1
    for i in range(5,len(s)+1):
        f=0
        if s[i-5:i]=="erase":
            f=1
        if s[i-5:i]=="dream":
            f=1
        if i>=6 and s[i-6:i]=="eraser":
            f=1
        if i>=7 and s[i-6:i]=="dreamer":
            f=1
        dp[i]=f

    if dp[-1]:
        print('YES')
    else:print('NO')





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

#a,b =map(int, input().split())
incode=input()

while(len(incode)>0):
#後ろ５文字が切り抜けるか
    if (incode[len(incode)-5:] == "dream") or (incode[len(incode)-5:] =="erase"):
        incode = incode[0:len(incode)-5]
        continue
    if (incode[len(incode)-6:] == "eraser"):
        incode = incode[0:len(incode)-6]
        continue
    if (incode[len(incode)-7:] == "dreamer "):
        incode = incode[0:len(incode)-7]
        continue
    break
if len(incode) == 0: 
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

queue = deque()
queue.append(0)
candidates = ['dream', 'dreamer', 'erase', 'eraser']

while queue:
    index = queue.popleft()
    match = False
    for candidate in candidates:
        if s[index:index + len(candidate)] == candidate:
            match = True
            if index + len(candidate) == len(s):
                print('YES')
                sys.exit(0)
            queue.append(index + len(candidate))
    if not match:
        print('NO')
        sys.exit(0)

Submission status: Wrong Answer

Solution code:
import re
flag = re.match('^(deram|dreamer|erase|eraser)+$',input())
if flag:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

dreams = ['dream', 'dreamer', 'erase', 'eraser']
dreams = [dream[::-1] for dream in dreams]

i = 0
while i < len(S):
    flag = False
    for j in dreams:
        if S[i:i+len(j)] == j:
            print(S[i:i+len(j)], j)
            print(i)
            i = i + len(j)
            flag = True
    if not flag:
        break

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    s = input()
    s = s[::-1]
    flag = True
    i = 0

    while i < len(s) - 1:
        if s[i:i + 5] == 'maerd' or s[i:i + 5] == 'esare':
            i += 5
        elif s[i:i + 6] == 'resare':
            i += 6
        elif s[i:i + 7] == 'remaerd':
            i += 7
        else:
            flag = False
            break
    print('YES' if flag else 'NO')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
l = [ 'dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
	s1 = l[i][::-1]
	l[i] = s1

n = len(s)
i = 0
t1 = (l[1],l[3])
t2 = (l[0],l[2])

while i < n:
	judge = 0
	if s[i] == 'r' and n-i >= 6:
		s1 = s[i:i+6]
		if s1 in t1:
			i += 6
			judge = 1
	elif n-i >= 4:
		s1 = s[i:i+5]
		if s1 in t2:
			i += 5
			judge = 1
	
	if judge == 0:
		break

if i == n:
	print('YES')
else:
	print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

eraseS = S.split("erase")

rest1 = ""
for s in eraseS:
    if s[:0] == "r":
        rest1 += s[1:]
    else:
        rest1 += s

dreamS = rest1.split("dream")

rest2 = ""
for s in dreamS:
    if s[0:1] == "er":
        rest2 += s[2:]
    else:
        rest2 += s

if rest2 == "":
    res = "YES"
else:
    res = "NO"

print(res)

Submission status: Wrong Answer

Solution code:
s=input()
lst=['dream','dreamer','erase','eraser']
for i in lst:
  for j in lst:
    if s==i+j:
      print('YES')
      exit()
print('NO')

Submission status: Wrong Answer

Solution code:
a = input()

b = a[::-1]

i = 0
while i  < len(b):
    if b[i:i+5] == "esare":
        i += 5
    elif b[i:i+5] == "maerd":
        i += 5
    elif b[i:i+6] == "resare":
        i += 6
    elif b[i:i+7] == "remaerd":
        i += 7
    else:
        ans = "No"
        break

if i  == len(b):
    ans = "Yes"
else:
    ans = "No"

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()

flag = 0

while(len(s)>0):
  if (s[:6] == 'eraser'):
    s = s[6:]
  elif (s[:5] == 'erase'):
    s = s[5:]
  elif (s[:5] == 'dream'):
    if (s[5:8] == 'ere' or s[5:8] == 'erd'):
      s = s[7:]
    else:
      s = s[5:]
  else:
    flag = 1
    break

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

Submission status: Wrong Answer

Solution code:
s = input()

flag = 0

while(len(s)>0):
  if (s[:6] == 'eraser'):
    s = s[6:]
  elif (s[:5] == 'erase'):
    s = s[5:]
  elif (s[:5] == 'dream'):
    if (s[5:8] == 'ere' or s[5:8] == 'erd'):
      s = s[7:]
    else:
      s = s[5:]
  else:
    flag = 1
    break

if (flag == 0):
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
from sys import stdin
data = stdin.readline().rstrip()

def shorten_phrase(x):
    l = len(x)
    if x.startswith("eraser"):
        x = x[6:]
    elif x.startswith("erase"):
        x = x[5:]
    elif x.startswith("dreamera"):
        x = x[5:]
    elif x.startswith("dreamer"):
        x = x[7:]
    elif x.startswith("dream"):
        x = x[5:]
    m = len(x)
    return l != m

while shorten_phrase(data):
    if data.startswith("eraser"):
        data = data[6:]
    elif data.startswith("erase"):
        data = data[5:]
    elif data.startswith("dreamera"):
        data = data[5:]
    elif data.startswith("dreamer"):
        data = data[7:]
    elif data.startswith("dream"):
        data = data[5:]
if len(data) == 0:
    print("YES")
else:
    print("NO")
print(data)

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
n = len(s)
words = ['resare', 'remaerd', 'maerd',  'esare']
p = 1
for w in words:
    s = s.replace(w, '')
print('NO' if s else 'YES')

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
n = len(s)
words = ['maerd', 'remaerd', 'esare', 'resare']
p = 1
while p <= n:
    if s[:p] in words:
        s = s[p:]
    p += 1
print('NO' if s else 'YES')

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
n = len(s)
words = ['maerd', 'remaerd', 'esare', 'resare']
p = 1
while p < n:
    if s[:p] in words:
        s = s[p:]
    p += 1
print('NO' if s else 'YES')

Submission status: Wrong Answer

Solution code:
S = list(input())
T =[]
str_d = list('dream')
str_e = list('erase')

if S[0:5] ==str_d:
    T += str_d
elif S[0:5] ==str_e:
    T += str_e

while S[0:len(T)] == T:
    if S[len(T):len(T)+5] == str_d:
        T += str_d
        if (len(S) >= len(T))+2 and (S[len(T):len(T)+2] == list('er')):
            T += list('er')
    elif S[len(T):len(T)+5] == str_e:
        T += str_e
        if (len(S) >= len(T))+2 and (S[len(T):len(T)+1] == list('r')):
            T += list('r')
    else:
        break

print('YES' if S == T else 'NO')

Submission status: Wrong Answer

Solution code:
#わっかりません復習します

Submission status: Wrong Answer

Solution code:
S = input()[::-1]
word = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
judge = [True, True, True, True]
while any(judge):
  for i in range(len(word)):
    if S[:len(word[i])] == word[i]:
      S = S[len(word[i]):]
    else:
      judge[i] = False
    if S == '':
      print('YES')
      exit()
print('NO')

Submission status: Wrong Answer

Solution code:
S = input()[::-1]
word = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
judge = [True, True, True, True]
while any(judge):
  for i in range(len(word)):
    if S[:len(word[i])] == word[i]:
      S = S[len(word[i]):]
    else:
      judge[i] = False
    if S == '':
      print('YES')
      exit()
print('No')

Submission status: Wrong Answer

Solution code:
S=input()[::-1]
num=(len(S)//5)+1
while num > 0:
  for i in ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]:
    if S[:len(i)] == i:
      S = S[len(i):]
    if S == '':
      print('YES')
      exit()
  num -= 1
print('No')