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:
s = list(input())
n = len(s)
temp = ['maerd', 'remaerd', 'esare', 'resare']
s.reverse()

i = 0
while i < n:
    flag = False
    for t in temp:
        if s[:len(t)] == list(t):
            i += len(t) - 1
            flag = True
            break

    if not flag:
        print("NO")
        exit()

print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
L = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(L)):
    L[i] = L[i][::-1]
S = S[::-1]
T = ''
for s in S:
    T += s
    for i in L:
        if T == i:
            T = ''
if T == '':
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
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: Wrong Answer

Solution code:
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: Wrong Answer

Solution code:
S = input()
T = ''
str_list = ['dream', 'erase', 'dreamer', 'eraser']
start = 0
T = ''
success_flag = False
continue_flag = False
while True:
    for str_name in str_list:
        if S[start:start + len(str_name)] == str_name:
            if len(S) == start + len(str_name):
                success_flag = True
                break
            if S[start + len(str_name)] != 'r':
                T += str_name
                start += len(str_name)
                continue_flag = True
    if success_flag:
        print('YES')
        break
    if not continue_flag:
        print('NO')
        break
    else:
        continue_flag = False

Submission status: Wrong Answer

Solution code:
def resolve():
    # 整数 1 つ
    s = input().rstrip()
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    flag = True
    for i in range(int(len(s) / 5)):
        if s[-5:] == "dream":
            s.rstrip("dream")
        elif s[-5:] == "erase":
            s.rstrip("erase")
        elif s[-6:] == "eraser":
            s.rstrip("eraser")
        elif s[-7:] == "dreamer":
            s.rstrip("dreamer")
        else:
            flag = False
            break
        if len(s) == 0:
            break

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

resolve()

Submission status: Wrong Answer

Solution code:
S = input()
i = 0
N = len(S)
while i < N:
    if S[i: i + 5] == "dream":
        if i == N - 5 or (i == N - 7 and S[i + 5: i + 7] == "er"):
            print("YES")
            exit()
        elif i == N - 6 or i == N - 8:
            print("NO")
            exit()
        elif S[i + 5: i + 7] == "er" and S[i + 7: i + 9] == "er":
            i += 7
        elif S[i + 5: i + 7] == "er":
            i += 5
    elif S[i: i + 5] == "erase":
        if i == N - 5:
            print("YES")
            exit()
        elif S[i + 5: i + 6] == "r":
            i += 6
        else:
            i += 5
    else:
        print("NO")
        exit()
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
S = str(input())

now = 0
while True:
    try:
        if now==len(S):
            print("YES")
            break
        elif S[now:now+7]=="dreamer":
            now += 7
        elif S[now:now+6]=="eraser":
            now += 6
        elif S[now:now+5]=="dream" or S[now:now+5]=="erase":
            now += 5
        else:
            print("NO")
            break
    except:
        try:
            if now==len(S):
                print("YES")
                break
            elif S[now:now+6]=="eraser":
                now += 6
            elif S[now:now+5]=="dream" or S[now:now+5]=="erase":
                now += 5
            else:
                print("NO")
                break
        except:
            try:
                if now==len(S):
                    print("YES")
                    break
                elif S[now:now+5]=="dream" or S[now:now+5]=="erase":
                    now += 5
                else:
                    print("NO")
                    break
            except:
                print("NO")
                break

Submission status: Wrong Answer

Solution code:
S = str(input())

S = S.replace("dreamer", "")
S = S.replace("eraser", "")
S = S.replace("dream", "")
S = S.replace("erase", "")

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

Submission status: Wrong Answer

Solution code:
s=input()
t=['dream','dreamer','erase','eraser']
t=sorted(t,reverse=True)
a=0
for i in range(4):
  for j in range(4):
    if t[i]+t[j]==s: 
      a+=1
print("YES"if a>0 else "NO")

Submission status: Wrong Answer

Solution code:
S = input()
lS = len(S)
i=0
while i<lS:
    ch = S[i:i+5]
    if ch == 'dream':
        if i+5<lS and S[i+5] =='d':
            i = i+5
        elif i+7<lS:
            if S[i:i+7]=='dreamer':
                if S[i+7]=='a':
                    i = i+5
                elif S[i+7]=='e' or S[i+7]=='d':
                    i = i+7
                else:
                    break
        else:
            if i+5>=lS:
                print('YES')
                exit()
            break
    elif ch=='erase':
        if i+5<lS:
            if S[i+5] =='d' or S[i+5] =='e':
                i = i+5
            elif S[i+5]=='r':
                i = i+6
                if i>=lS:
                    print('YES')
                    exit()
            else:
                break
        else:
            print('YES')
            exit()
    else:
        break
print('NO')

Submission status: Wrong Answer

Solution code:
S = input()
dream = "dream"
dreamer = "dreamer"
erase = "erase"
eraser = "eraser"


while True:
    if S.find(dream, len(S) - len(dream), len(S)) == len(S) - len(dream):
        S = S[:len(S) - len(dream)]
        continue
    elif S.find(dreamer, len(S) - len(dreamer), len(S)) == len(S) - len(dreamer):
        S = S[:len(S) - len(dreamer)]
        continue
    elif S.find(erase, len(S) - len(erase), len(S)) == len(S) - len(erase):
        S = S[:len(S) - len(erase)]
        continue
    elif S.find(eraser, len(S) - len(eraser), len(S)) == len(S) - len(eraser):
        S = S[:len(S) - len(eraser)]
        continue
    elif len(S) == 0:
        print("Yes")
        break
    else:
        print("No")
        break

Submission status: Wrong Answer

Solution code:
s=input()
import re
#re.match は複数を対象にすればマッチする該当のものが返される。一つの時ifの後に持ってくると条件式として利用可能。
if re.match("(dream|dreamer|erase|eraser)+",s) :
       print("YES")
else:
       print("NO")

Submission status: Wrong Answer

Solution code:
s=list(input())
end=0
def search(s,end):
    if len(s)-end>=6 and (s[end:end+6]==list("eraser")):
        return(end+6)
    elif len(s)-end>=7 and (s[end:end+7]==list("dreamer")):
        return(end+7)
    elif len(s)-end>=5 and (s[end:end+5]==["d","r","e","a","m"] or s[end:end+5]==["e","r","a","s","e"] ):
        return(end+5)
    elif len(s)-end==0:
      return(-2)#終了条件
    else:
        return(-1)#中断条件
while end>=0:
    end=search(s,end)
if end==-1:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
s=list(input())
end=0
def search(s,end):
    if len(s)-end>=5 and (s[end:end+5]==["d","r","e","a","m"] or s[end:end+5]==["e","r","a","s","e"] ):
        return(end+5)
    elif len(s)-end>=6 and (s[end:end+6]==list("eraser")):
        return(end+6)
    elif len(s)-end>=7 and (s[end:end+7]==list("dreamer")):
        return(end+7)
    elif len(s)-end==0:
      return(-2)#終了条件
    else:
        return(-1)#中断条件
while end>=0:
    end=search(s,end)
if end==-1:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
s=list(input())
end=0
def search(s,end):
    if len(s)-end>=5 and (s[end:end+5]==["d","r","e","a","m"] or s[end:end+5]==["e","r","a","s","e"] ):
        return(end+5)
    elif len(s)-end>=6 and (s[end:end+6]==list("eraser")):
        return(end+6)
    elif len(s)-end>=7 and (s[end:end+7]==list("dreamer")):
        return(end+7)
    elif len(s)-end==0:
      return(-2)#終了条件
    else:
        return(-1)#中断条件
while end>=0:
    end=search(s,end)
if end==-1:
    print("NO")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
s=input()

s = s[::-1] #文字の反転

t = 0;

while t ==0:
    a = s.find("maerd")
    b = s.find("remaerd")
    c = s.find("esare")
    d = s.find("resare")

    if a == 0 or c== 0:
        s = s[5:]
        continue
    if b == 0:
        s = s[7:]
        continue
    if d == 0:
        s = s[6:]
        continue
    t=1


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

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    while len(s) > 0:
        if s[-6:] == "dreamer":
            s = s[:-7]
        elif s[-6:] == "eraser":
            s = s[:-6]
        elif s[-5:] == "dream":
            s = s[:-5]
        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 = input()
t = ""
while len(t) < len(s):
    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) + 7] != 'a':
                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) + 4] != 'd' and s[len(t) + 6] != 'a':
                t += "eraser"
            else:
                t += "erase"
        else:
            break

    if s[0:len(t)] != t:
        break

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

Submission status: Wrong Answer

Solution code:
s = input()
t = ""
while len(t) < len(s):
    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) + 7] != 'a':
                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) + 4] != 'd' and s[len(t) + 6] != 'a':
                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: Wrong Answer

Solution code:
import re
s = input()

s = re.sub("dreameraser", "", s)
s = re.sub("dreamerase", "", s)
s = re.sub("dreamer", "", s)
s = re.sub("dream", "", s)
s = re.sub("eraser", "", s)
s = re.sub("erase", "", s)

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc049/tasks/arc065_a
# まえからっ読んでいくと文字列のオーバーラップが多くいし、末尾のオーバーラップも多くてしんどい
# 逆から読んでくと3文字で即時決定できる

S = read()[:-1]
S = deque(reversed('xxxxxxxxxx' + S))  # よしなにpaddingすることで終端処理を楽に

# print(S)
while len(S) > 10:
    end3 = ''.join([S[4], S[3], S[2], S[1], S[0]])
    # print(end3)
    if end3 == 'dream':
        num_pop = 5
    elif end3 == 'eamer':
        num_pop = 7
    elif end3 == 'erase':
        num_pop = 5
    elif end3 == 'raser':
        num_pop = 6
    else:
        print('NO')
        exit()
    for _ in ra(num_pop):
        S.popleft()

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

Submission status: Wrong Answer

Solution code:
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']
T = set([s[::-1] for s in T])

A = ''
for s in S[::-1]:
    A += s
print('YES' if A == '' else 'NO')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc049/tasks/arc065_a
# まえからっ読んでいくと文字列のオーバーラップが多くいし、末尾のオーバーラップも多くてしんどい
# 逆から読んでくと3文字で即時決定できる

S = read()[:-1]
S = deque(reversed('xxxxxxxxxx' + S))  # よしなにpaddingすることで終端処理を楽に

# print(S)
while len(S) > 10:
    end3 = ''.join([S[3], S[2], S[1], S[0]])
    # print(end3)
    if end3 == 'ream':
        num_pop = 5
    elif end3 == 'amer':
        num_pop = 7
    elif end3 == 'rase':
        num_pop = 5
    elif end3 == 'aser':
        num_pop = 6
    else:
        print('NO')
        exit()
    for _ in ra(num_pop):
        S.popleft()

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

Submission status: Wrong Answer

Solution code:
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']
T = set([s[::-1] for s in T])

A = ''
for s in S[::-1]:
    A += s
    if A in T:
        A = ''
print('Yes' if A == '' else 'No')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc049/tasks/arc065_a
# まえからっ読んでいくと文字列のオーバーラップが多くいし、末尾のオーバーラップも多くてしんどい
# 逆から読んでくと3文字で即時決定できる

S = read()[:-1]
S = deque(reversed('xxxxxxxxxx' + S))

# print(S)
while len(S) > 10:
    end3 = ''.join([S[2], S[1], S[0]])
    if end3 == 'eam':
        num_pop = 5
    elif end3 == 'mer':
        num_pop = 7
    elif end3 == 'ase':
        num_pop = 5
    elif end3 == 'ser':
        num_pop = 6
    else:
        print('NO')
        exit()
    for _ in ra(num_pop):
        S.popleft()

# print(S)
if len(S) == 10:
    print('YES')
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc049/tasks/arc065_a
# まえからっ読んでいくと文字列のオーバーラップが多くいし、末尾のオーバーラップも多くてしんどい
# 逆から読んでくと3文字で即時決定できる

S = read()[:-1]
S = deque(reversed(S))

# print(S)
while S:
    end3 = ''.join([S[2], S[1], S[0]])
    if end3 == 'eam':
        num_pop = 5
    elif end3 == 'mer':
        num_pop = 7
    elif end3 == 'ase':
        num_pop = 5
    elif end3 == 'ser':
        num_pop = 6
    else:
        print('NO')
        exit()
    for _ in ra(num_pop):
        if S:
            S.popleft()
        else:
            print('NO')
            exit()

print('YES')

Submission status: Wrong Answer

Solution code:
s=input()
i=0
flag=True
while i<len(s):
  if s[i]=="d":

    if s[i:i+7]=="dreamer":
      if i+7<len(s) and s[i+7]!="a":
        i=i+7
      elif i+7==len(s):
        i=i+7
      elif s[i:i+5]=="dream":
        i=i+5
      else:
        flag=False
        break
    elif s[i:i+5]=="dream":
        i=i+5
    else:
      flag=False
      break
      
      
  elif s[i]=="e":
    if s[i:i+7]=="eraser":
      i=i+7
    elif s[i:i+5]=="erase":
      i=i+5
    else:
      flag=False
      break
      
      
  else:
    flag=False
    break
if flag==True:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
s=input()
i=0
flag=True
while i<len(s):
  if s[i]=="d":

    if s[i:i+7]=="dreamer":
      if i+7<len(s) and s[i+7]!="a":
        i=i+7
      elif i+7==len(s)-1:
        i=i+7
      elif s[i:i+5]=="dream":
        i=i+5
      else:
        flag=False
        break
    elif s[i:i+5]=="dream":
        i=i+5
    else:
      flag=False
      break
      
      
  elif s[i]=="e":
    if s[i:i+7]=="eraser":
      i=i+7
    elif s[i:i+5]=="erase":
      i=i+5
    else:
      flag=False
      break
      
      
  else:
    flag=False
    break
if flag==True:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
s=input()
i=0
flag=True
while i<len(s):
  if s[i]=="d":
    if s[i:i+7]=="dreamer":
      if i+7<=len(s) and s[i+7]!="a":
        i=i+7
      elif s[i:i+5]=="dream":
        i=i+5
      else:
        flag=False
        break
    elif s[i:i+5]=="dream":
        i=i+5
    else:
      flag=False
      break
  elif s[i]=="e":
    if s[i:i+7]=="eraser":
      i=i+7
    elif s[i:i+5]=="erase":
      i=i+5
    else:
      flag=False
      break
  else:
    flag=False
    break
if flag==True:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

a="maerd"
b="remaerd"
c="esare"
d="resare"
s="".join(list(reversed(SI())))
n=len(s)
ind=0
while ind<n:
    #print(ind)
    if s[ind:ind+5]==a or s[ind:ind+5]==c:
        ind+=5
    elif s[ind:ind+6]==d:
        ind+=6
    elif s[ind:ind+6]==b:
        ind+=7
    else:
        print("NO")
        sys.exit()
    #print(ind)
if ind==n:
    print("YES")

Submission status: Wrong Answer

Solution code:
s=input()
i=0
flag=True
while i<len(s):
  if s[i]=="d":
    if s[i:i+7]=="dreamer":
      if i+7!=len(s) and s[i+7]!="a":
        i=i+7
      elif s[i:i+5]=="dream":
        i=i+5
    elif s[i:i+5]=="dream":
        i=i+5
    else:
      flag=False
      break
  elif s[i]=="e":
    if s[i:i+7]=="eraser":
      i=i+7
    elif s[i:i+5]=="erase":
      i=i+5
    else:
      flag=False
      break
  else:
    flag=False
    break
if flag==True:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

a="maerd"
b="remaerd"
c="esare"
d="resare"
s="".join(list(reversed(SI())))
n=len(s)
ind=0
while ind<n:
    #print(ind)
    if s[ind:ind+5]==a or s[ind:ind+5]==c:
        ind+=5
    elif s[ind:ind+6]==b or s[ind:ind+6]==d:
        ind+=6
    else:
        print("NO")
        sys.exit()
    #print(ind)
if ind==n:
    print("YES")

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

a="maerd"
b="ermaerd"
c="esare"
d="resare"
s="".join(list(reversed(SI())))
n=len(s)
ind=0
while ind<n:
    #print(ind)
    if s[ind:ind+5]==a or s[ind:ind+5]==c:
        ind+=5
    elif s[ind:ind+6]==b or s[ind:ind+6]==d:
        ind+=6
    else:
        print("NO")
        sys.exit()
    #print(ind)
if ind==n:
    print("YES")

Submission status: Wrong Answer

Solution code:
import sys
import resource
sys.setrecursionlimit(10 ** 9)

S = input()
l = []
def dfs(n):
  print(n)
  if n == len(S):
    l.append("YES")
  if n < len(S):
    if S[n:n+5] == "erase":
      dfs(n+5)    
    if S[n:n+5] == "dream":
      dfs(n+5)  
    if S[n:n+6] == "eraser":
      dfs(n+6)              
    if S[n:n+7] == "dreamer":
      dfs(n+7)
dfs(0)
if len(l) == 0:
  l.append("NO")
print(l[0])

Submission status: Wrong Answer

Solution code:
import sys
import resource
sys.setrecursionlimit(10 ** 9)

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

Submission status: Wrong Answer

Solution code:
import re
s = input()
re.sub('eraser','0',s)
re.sub('erase','0',s)
re.sub('dreamer','0',s)
re.sub('dream','0',s)


print('YES' if set(s) == set('0') else 'NO')

Submission status: Wrong Answer

Solution code:
S = str(input())[::-1]
words = ['maerd', 'esare', 'remaerd', 'resare']

leng = len(S)
while leng>=5:
    if S[:5] in words:
        S = S[5:]
        leng -= 5
    elif S[:7] in words:
        S = S[7:]
        leng -= 7
    elif S[:6] in words:
        S = S[6:]
        leng -= 6
    else:
        print('NO')
        break

if leng==0:
    print('YES')

Submission status: Wrong Answer

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

cur = 0
while cur < n:

  if s[cur:cur+5:] == "maerd" or "esare":
    cur += 5
    continue
  if s[cur:cur+6:] == "resare":
    cur += 6
    continue
  if s[cur:cur+7:] == "remaerd":
    cur += 7
    continue
  print("NO")
  exit()

print("YES")

Submission status: Wrong Answer

Solution code:
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

S = list(input())
i = len(S) - 1

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

while i > 0:
    if S[i] == 'm':
        for j in range(5):
            if S[i - j] == T[0][4 - j]:
                continue
            else:
                print ('NO')
                exit()
        i -= 5
    elif S[i] == 'r':
        if S[i - 2] == 'm':
            for j in range(7):
                if S[i - j] == T[1][6 - j]:
                    continue
                else:
                    print ('NO')
                    exit()
            i -= 7
        else:
            for j in range(6):
                if S[i - j] == T[3][5 - j]:
                    continue
                else:
                    print ('NO')
                    exit()
            i -= 6
    else:
        for j in range(5):
            if S[i - j] == T[2][4 - j]:
                continue
            else:
                print ('NO')
                exit()
        i -= 5

if i == -1:
    print ('Yes')
else:
    print ('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
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[y:y+2]=='er' else y
    y=x+5
  else:
    print('NO')
    exit()

Submission status: Wrong Answer

Solution code:
s=input()
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: Wrong Answer

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