peterverebics/CodeNet_Python_118 huggingface dataset:
N=int(input())
A=input()

i=0
ans=0
while(True):
  if i>N-3:
    break
  if A[i]=='A' and A[i+1]=='B' and A[i+2]=='C':
    ans+=1
    i+=3
  else:
    i+=1
N = int(input())
S = input()
thre = "ABC"
res = 0
for i in range(N-3):
  if thre == S[i:i+3]:
    res +=1
print(res)
N=int(input())
S=input()
ans=0
for i in range(N-3):
  if S[i:i+3]=='ABC':
    ans+=1
print(ans)
n = int(input())
s = input()

cnt = 0
for i in range(n-3):
    # print(s[i:i+3])
    if s[i:i+3] == 'ABC':
        cnt += 1
print(cnt)
N = int(input())
S = [i for i in range(N)]
cnt = 0

for i in range(0, N-2):
  if S[i]=='A' and S[i+1]=='B' and S[i+2]=='C':
    cnt+=1

print(cnt)
abc = 'ABC'
N = int(input().rstrip())
S = input().rstrip()
ret = 0
if N == 3 and S == abc:
    ret = 1
else:
    for i in range(N - len(abc)):
        if abc == S[i:i+3]:
            ret += 1
print(ret)
n = int(input())
letters = input()
cnt = 0
for i in range(n):
    if letters[i:i+3]=="abc":
        cnt += 1

print(cnt)
#coding:utf-8
n = int(input())
s = input()
count = 0

for i in range(0, n-3):
    if s[i:i+3] == 'ABC':
        count += 1
print(count)
abc = 'ABC'
N = int(input().rstrip())
S = input().rstrip()
ret = 0
for i in range(N-len(abc)):
    if 'ABC' == S[i:i+3]:
        ret += 1
print(ret)
S = input()

res = 0
for i in range(len(S)-2):
  if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
    res += 1
    
print(res)
N = int(input())
L = input()
K = 0
for i in range(N-3):
  if L[i] == "A" and L[i+1] =="B" and L[i+2] == "C":
    K = K+1
print(K)
import sys; readline = sys.stdin.readline
from collections import deque

N = int(readline())
S = readline().rstrip()

count = 0

for i in range(N - 3):
    if S[i:i+3] == 'ABC':
        count += 1

print(count)
#b
n=int(input())
s=input()
ans=0
for i in range(n-3):
     a=s[i]+s[i+1]+s[i+2]
     if a=="ABC":
         ans+=1
print(ans)
N = int(input())
S = list(input())
ans = 0
for k in range(N-4):
  if (S[k] == 'A') and (S[k+1] == 'B') and (S[k+2] == 'C'):
    ans += 1
print(ans)
N = int(input())
words = input()
ans = 0
for i in range(N-4):
    if words[i] == "A":
        if words[i+1] == "B":
            if words[i+2] == "C":
                ans += 1
print(ans)
n = int(input())
s = input()

ans = 0

for i in range(n-3):
  if s[i:i+3] == "ABC":
    ans +=1

print(ans)
n = int(input())
s = input()

ans = 0

p = 1

for i in range(n):
    if p == 1:
        if s[i] == "A":
            p += 1
    elif p == 2:
        if s[i] == "B":
            p += 1
        else:
            p = 1
    else:
        if s[i] == "C":
            ans += 1
        p = 1

print(ans)
n = int(input())
s = input()      
pattern = list('ABC')          
cnt = 0
match = True

for i in range(n-len(pattern)):
    if (s[i] == pattern[0]) and (s[i+ 1] == pattern[1]) and (s[i+ 2] == pattern[2]):
        cnt += 1
if n == 3 and s == "ABC":
    print(1)
else:
    print(cnt)
n = int(input())
s = input()
count = 0
for i in range(n-3):
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == "C":
        count += 1

print(count)
N = int(input())
S = input()
"""
10
ZABCDBABCQ
"""

num = 0
for i in range(len(S)-3):
    if S[i:i+3] == "ABC":
        num += 1

print(num)
n = input()
s = input()

if int(n) > 3 and int(n) < 50:
    abc = s.split('ABC')
    print(len(abc)-1)
n=int(input())
s=input()
cnt=0
for i in range(n-3+1):
    if s[i:i+4]=="ABC": cnt+=1
print(cnt)
length_count = input()
strings = input()

abc_count = 0
a = False
b = False

strings_list = list(strings)

for char in strings_list:
    if char == 'A':
        a = True
    elif char == 'B' and a:
        b = True
    elif char == 'C' and a and b:
        abc_count += 1
        a = False
        b = False
    else:
        a = False
        b = False

print(abc_count)
def main():
  N = int(input())
  S = str(input())
  l = 0
  ans = 0
  p = ''
  for i in range(N):
      if S[i] == 'A' and p == '':
          l += 1
          p = S[i]
      elif S[i] == 'B' and l == 1 and p == 'A':
          l += 1
          p = S[i]
      elif S[i] == 'C' and l == 2 and p == 'B':
          ans += 1
          l = 0
      else:
          l = 0
          p = ''
  print(ans)
main()
n = int(input())
s = input()
c = 0
for i in range(n-3):
  if s[i]=="a" and s[i+1]=="b" and s[i+2]=="c":
    c += 1
print(c)
n = int(input())
s = list(input())
a = []
count = 0

for i in range(n-3):
    a = s[i:i+3]
    if a == ["A","B","C"]:
        count += 1

print(count)
def main(N,S):
    N = int(N)
    S = str(S)

    c = 0
    for i in range(N-2):
        if S[i:i+2] == 'ABC':
            c += 1

    return c

if __name__ == '__main__':
    N = input()
    S = input()
    main(N,S)
n = int(input())
s = str(input())

i = 0
cnt = 0

while i < n:
    if i < n and s[i] == "A":
        i += 1
        if i < n and s[i] == "B":
            i += 1
            if i < n and s[i] == "C":
                cnt += 1
    i += 1

print(cnt)
N = int(input())
S = input()
count = 0
for i in range(N - 3 + 1):
  if S[i:i+2] == "ABC":
    count += 1
print(count)
N = int(input())
S = input()

count = 0
for i in range(N-3):
    if(S[i:(i+3)] == "ABC"):
        count += 1

print(count)
n = int(input())
s = input()
ans = 0


for i in range(n-2):
    if s[i:i+2] == 'ABC':
        res += 1

print(ans)
# 値の入力
N=int(input())
S=str(input())

i=N-1
result=0

# 処理
while True:
    if i-3<0:
        break
    if S[i]=='C' and S[i-1]=='B' and S[i-2]=='A' :
        result+=1
    i-=1

print(result)
n = int(input())
s = input()
ans = 0
for i in range(n-3):
  if s[i:i+3]=='ABC':
    ans+=1
print(ans)
def main():
  n = input()
  inp = input()
  sum = 0
  order = 0 # searching {a:0 b:1 c:2}
  for c in inp:
    if ord(c) == ord('A') + order:
      if order == 2:
        sum += 1
        order = 0
      else:
        order += 1
  print(sum)
n = int(input())
s = input()
flag = 0
for i in range(n-1):
    if i == n-3:
        break
    if s[i] == 'A':
        if s[i+1] == 'B':
            if s[i+2] == 'C':
                flag =+ 1
print(flag)
n=int(input())
s=input()

i=0
ans=0
while i<len(s)-2:
  if s[i]=="A":
    if s[i+1]=="B" and s[i+2]=="C":
      ans+=1
    i+=3
  else:
    i+=1
print(ans)
n = int(input())
s = input()

ans = 0

for i in range(n - 3):
    if (s[i] == "A"):
        if s[i + 1] == "B":
            if s[i + 2] == "C":
                ans += 1

print(ans)
n=int(input())
s=input()
s.replace('ABC','a')
print(s.count('a'))
n = int(input())
s = input()
c = 0
for i in range(n-3):
    if s[i] == 'A' and s[i:i+3] == 'ABC':
        c += 1
print(c)
N = int(input())
S = input()

count = 0
for i in range(0,N-3):
    if S[i]=='A' and S[i+1]=='B' and S[i+2]=='C':
        count += 1
print(count)
N = int(input())
S = str(input())
ans = 0
if N == 3:
  if S == 'ABC':
    ans += 1
else:
  for i in range(N-3):
    if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
      ans += 1
print(ans)
n = int(input())
s = input()

ans = 0
i = 0
while i < n - 3:
    if s[i:i + 3] == 'ABC':
        ans += 1
        i += 3
    else:
        i += 1

print(ans)
# 各桁の数値の総和を計算する.
def calc_digit_sum(num):
    sums = 0
    while num > 0:
        sums += num % 10
        num //= 10
    return sums


n = int(input())
s = input()

cnt = 0
for index in range(n-3):
    if s[index:index+3] == "ABC":
        cnt += 1
print(cnt)
n = int(input())
s = str(input())

i = 0
cnt = 0

for i in range(0,n-3):
    if s[i] == "A" and s[i+1] == "B" and s[i+2] == "C":
        cnt += 1

print(cnt)
N = int(input())
S = str(input())
S.replace("abc","pq")
print(N - len(S))
n = input()
s = input()
 
count = 0
last_is_A = False
last_is_B = False
 
for v in s:
  if v=='A':
    last_is_A = True
    continue
  if last_is_A and v=='B':
    last_is_A = False
    last_is_B = True
    continue
  if last_is_B and v=='C':
    count += 1
  last_is_A = False
  last_is_B = False
print(count)
n = int(input())
s = input()

c = 0
for i in range(len(s)- 3):
    if s[i] + s[i+1] + s[i + 2] == "ABC":
        c+=1
print(c)
N = int(input())
S = input()
c = 0
for i in range(N - 3):
    if S[i] == 'A' and S[i + 1] == 'B' and S[i + 2] == 'C':
        c += 1
print(c)
n = int(input())
s = input()

cnt = 0
for i in range(n):
    if i == n-3:
        break
    a_str = s[i] + s[i+1] + s[i+2]
    if a_str == 'ABC':
        cnt += 1


print(cnt)
import sys
N = int(input())
S = input()
array_S = list(S)

if not ( 3 <= N <= 50 and S.isupper() ): sys.exit()

count = 0
for I in range(N-3):
    if ''.join(array_S[I:I+3]) == 'ABC':
        count += 1
print(count)
n = int(input())
s = input()

res = 0
phase = 0
for c in s:
    if c == "A" and phase == 0:
        phase = 1
        continue
    elif c == "B" and phase == 1:
        phase = 2
        continue
    elif c == "C" and phase == 2:
        res += 1
    phase = 0

print(res)
N=int(input())
S=str(input())
count=0
if(N>3):
    for i in range(N-3):
        if(S[i:i+3]=="ABC"):
            count+=1
        else:
            pass
elif(N==3):
    if(S=="ABC"):
        count+=1
    else:
        pass
else:
    pass
print(count)
s = input()
N = len(s)
ans = 0
if N < 3:print(0);exit()
for i in range(N-2):
  if s[i]=='A' and s[i+1]=='B' and s[i+2] == 'C':ans += 1

print(ans)
n = input()
s = input()
ans = 0
for i in range(len(s)-3):
    if s[i:i+3] == 'ABC':
        ans += 1
print(ans)
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    s = input().strip()

    ans = 0
    for i in range(N-3):
        if s[i:i+3] == "ABC":
            ans += 1
    
    print(ans)


if __name__ == "__main__":
    main()
x=int(input())
s=input()
c=0
for i in range(x-3):
    if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
        c+=1
print(c)
S = input()
S = S.replace('eraser','')
S = S.replace('erase','')
S = S.replace('dreamer','')
S = S.replace('dream','')

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

while 1:
    for x in ('dream', 'dreamer', 'erase', 'eraser'):
        if s.endswith(x):
            s = s[:-len(x)]
            break
    else:
        print('NO')
        break
    if not s:
        print('YES')
        break
S=input()
S=S.replace("eraser","")
S=S.replace("erase","")
S=S.replace("dreamer","")
S=S.replace("dream","")
if len(S)==0:
  print("YES")
else:
  print("NO")
#!/usr/bin/env python3
import re
s = input()


while True:
    # s = re.sub('dream$|dreamer$|erase$|eraser$','',s)

    l = len(s)
    if s.rfind('dream') == l-5:
        s = s[:-5]
    elif s.rfind('dreamer') == l-7:
        s = s[:-7]
    elif s.rfind('erase') == l-5:
        s = s[:-5]
    elif s.rfind('eraser') == l-6:
        s = s[:-6]
    else:
        break
        
if len(s)==0:
    print('YES')
else:
    print('NO')
S=input()[::-1]
W=("dream"[::-1],"dreamer"[::-1],"erase"[::-1],"eraser"[::-1])
ind=0
while ind<len(S):
  for w in W:
    if S[ind:ind+len(w)]==w:
      ind+=len(w)
      break
  else:
    print("NO")
    break
else:
  print("YES")
import re
if re.match("(dream|dreamer|erase|eraser)*$",input()):
  print("YES")
else:
  print("NO")
s = input()
s = s[::-1]
s = s.replace('resare','/')
s = s.replace('esare', '/')
s = s.replace('remaerd','/')
s = s.replace('maerd','/')

s = s.replace('/', '')
if len(s) == 0:
    print('YES')
else:
    print('NO')
s = input()
i = len(s)
while i > 0:
    if s[i-5:i] == 'dream' or s[i-5:i] == 'erase':
        i -= 5
    elif s[i-6:i] == 'eraser':
        i -= 6
    elif s[i-7:i] == 'dreamer':
        i -= 7
    else:
        print('NO')
        exit()
print('YES')
words = ("dream","dreamer","erase","eraser")
import sys
readline = sys.stdin.readline

S = readline().rstrip()

stack = [0]
while stack:
  ind = stack.pop()
  if ind == len(S):
    print("YES")
    break
  for w in words:
    if S[ind:ind + len(w)] == w:
      stack.append(ind + len(w))
else:
  print("NO")
import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$", input()) else "NO")
s=input()
# dream dreamer erase eraser 
while len(s)>0:
	if (s[-1]=="r") & (s[-7:]=="dreamer"):
		s=s[:-7]
	elif (s[-1]=="r") & (s[-6:]=="eraser"):
		s=s[:-6]
	elif (s[-1]=="e") & (s[-5:]=="erase"):
		s=s[:-5]
	elif (s[-1]=="m") & (s[-5:]=="dream"):
		s=s[:-5]
	else:
		break

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

tmp = data.replace('eraser', '')
tmp = tmp.replace('erase', '')
tmp = tmp.replace('dreamer', '')
tmp = tmp.replace('dream', '')
if tmp == '':
  print('YES')
  exit()
print('NO')
s=input()
s=s[::-1]

for i in range(100000):
    if s[:5] == 'maerd':
        s = s[5:]
    if s[:5] == 'esare':
        s = s[5:]
    if s[:6] == 'resare':
        s = s[6:]
    if s[:7] == 'remaerd':
        s = s[7:]

if len(s)==0:
    print('YES')
else:
    print('NO')
s=input()
while True:
    for flag in ["erase","eraser","dream","dreamer"]:
        if s.endswith(flag):
            s=s[:-len(flag)]
            break
    else:
        print("NO")
        break
    if len(s)==0:
        print("YES")
        break
s = 'HAKUTYUMU' + input()
 
 
while s != 'HAKUTYUMU':
    next_s = s
 
    if s[-5:] == 'dream':
        next_s = s[:-5]
    if s[-7:] == 'dreamer':
        next_s = s[:-7]
    if s[-5:] == 'erase':
        next_s = s[:-5]
    if s[-6:] == 'eraser':
        next_s = s[:-6]
 
    if s == next_s:
        print('NO')
        exit()
 
    s = next_s
 
print('YES')
s = input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
  print("NO")
else:
  print("YES")
s = input()
s = s.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")

if len(s) > 0:
    print("NO")
else:
    print("YES")
import re

s = input()
ptn = re.compile(r'maerd|remaerd|resare|esare')
tmp = s[::-1]

while(True):
  res = re.match(ptn , tmp)
  if res is None:
    break
  tmp = tmp.replace(res.group(),'',1)

if len(tmp) == 0:
  print('YES')
else:
  print('NO')
import re
s = input()
print("YES" if re.match("(dream|dreamer|erase|eraser)+$", s) else "NO")
s = input()
s = s[-1::-1]
word = ['resare','esare','remaerd','maerd',]
for i in word:
    s = s.replace(i,'')
if s:
    print('NO')
else:
    print('YES')
S = input()
subT = ['eraser', 'erase', 'dreamer', 'dream', ]
for i in subT:
    S = S.replace(i, '')

if S == '':
    print('YES')
else:
    print('NO')
s=input()
while len(s)>7:
    if s[-7:]=="dreamer":
        s=s[:-7]
    elif s[-5:]=="dream":
        s=s[:-5]
    elif s[-6:]=="eraser":
        s=s[:-6]
    elif s[-5:]=="erase":
        s=s[:-5]
    else:
        break
if s in ["dreamer","dream","eraser","erase"]:
    print("YES")
else:
    print("NO")
s=input()
l=len(s)
while s!=0:
    l=len(s)
    if s.rfind("dream")==l-5:
        s=s[:l-5]
    elif s.rfind("dreamer")==l-7:
        s=s[:l-7]
    elif s.rfind("erase")==l-5:
        s=s[:l-5]
    elif s.rfind("eraser")==l-6:
        s=s[:l-6]
    else:
        break
if len(s)==0:
    print("YES")
else:
    print("NO")
# -*- coding: utf-8 -*-
# 整数の入力
s = input()

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

def check():
    tmp = s
    while(True):
      current_len = len(tmp)
      for w in words:
        if tmp.endswith(w):
          tmp = tmp[:-len(w)]
      if len(tmp) == 0:
          return "YES"

      if current_len == len(tmp):
          return "NO"

print(check())
s = input()

ans = True
while s != "":
    words = ["eraser", "dream", "erase", "dreamer"]

    found = False
    for word in words:
        if s[-len(word):] == word:
            s = s[:-len(word)]
            found = True
            break

    if not found:
        ans = False
        break

print("YES" if ans else "NO")
s = input()

import re
output ="NO"
s = re.sub('dreameraser', 'A', s)
s = re.sub('dreamerase', 'A', s)
s = re.sub('dreamer', 'A', s)
s = re.sub('eraser', 'A', s)
s = re.sub('erase', 'A', s)
s = re.sub('dream', 'A', s)
if s.isupper() :
    output = "YES"
print(output)
def main(S):
    listdreamereraser = ['dreamer','eraser','dream','erase']
    while True:
        for i in listdreamereraser:
            if i in S[-len(i):]:
                S = S[:-len(i)]
                break
        else:
            return False
        if len(S) == 0:
            return True

S = input()
print('YES' if main(S) else 'NO')
t=input()
trigger=1
key=''
d=-1
app=['dreamer','eraser','dream','erase']
while len(t)>0 and trigger:
    for i in range(4):
        key=app[i]
        if key==t[:len(key)]:
            t=t[len(key):]
            trigger+=1
            d=i
            break
    trigger-=1
    if trigger==0 and d==0 and t[:3]=='ase':
        t='er'+t
        trigger+=1
if t=='':
    print('YES')
else:
    print('NO')
# ABC 049 C
S = str(input())

ans = 'YES'
while len(S)>0:
  if S[-5:] == 'dream':
    S = S[:-5]
  elif S[-5:] == 'erase':
    S = S[:-5]
  elif S[-6:] == 'eraser':
    S = S[:-6]
  elif S[-7:] == 'dreamer':
    S = S[:-7]
  else:
    ans = 'NO'
    break
print(ans)
import sys

S = input()

while S:
    if S[-1] == 'r':
        if S[-7:] == 'dreamer':
            S = S[:-7]
        elif S[-6:] == 'eraser':
            S = S[:-6]
        else:
            print('NO')
            sys.exit()
    elif S[-5:] == 'dream' or S[-5:] == 'erase':
        S = S[:-5]
    else:
        print('NO')
        sys.exit()

print('YES')
s=input()
if len(s)<5:
  print('NO')
  exit()
while len(s)>=5:
  if s[len(s)-5:len(s)]=='dream' or s[len(s)-5:len(s)]=='erase':
    s=s[:len(s)-5]
  elif len(s)>=6 and s[len(s)-6:len(s)]=='eraser':
    s=s[:len(s)-6]
  elif len(s)>=7 and s[len(s)-7:len(s)]=='dreamer':
    s=s[:len(s)-7]
  else:
    print('NO')
    exit()
if len(s)==0:
  print('YES')
else:
  print('NO')
#!/usr/bin/env python3
import sys

def main():
    s = input().replace("eraser","").replace("erase", "").replace("dreamer", "").replace("dream", "")
    ans = "NO" if s else "YES"
    print(ans)


if __name__ == '__main__':
    main()
s = input()
s = s.replace('eraser', '')
s = s.replace('erase', '')
s = s.replace('dreamer', '')
s = s.replace('dream', '')
if s == '':
    print('YES')
else:
    print('NO')
S = input()
Mozi = ["resare","esare","remaerd","maerd"]

S = S[::-1]
for i in Mozi:
    S = S.replace(i,"")
if not S:
    print("YES")
else:
    print("NO")
s = input()
while True:
    if s.endswith("dream"):
        s = s[:-5]
    elif s.endswith("dreamer"):
        s = s[:-7]
    elif s.endswith("erase"):
        s = s[:-5]
    elif s.endswith("eraser"):
        s = s[:-6]
    elif not s:
        print("YES")
        break
    else:
        print("NO")
        break
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')
import re
s = input()
str = ["dream","dreamer","erase","eraser"]
str = ["maerd","remaerd","esare","resare"]
s=s[::-1]
while len(s)>0:
  if len(s) < 5:
    print("NO")
    break
  if s[0:7] == str[1] :
    s=s[7:]
  elif s[0:6] == str[3]:
    s=s[6:]
  elif s[0:5] == str[0] or s[0:5] == str[2]:
    s=s[5:]
  else:
    print("NO")
    break
  if len(s)==0:
    print("YES")
    break
X=input()

for i in range(len(X)):
    if X[-7:] == "dreamer":
        X = X[:-7]
    elif X[-6:] == "eraser":
        X = X[:-6]
    elif X[-5:] == "dream":
            X = X[:-5]
    elif X[-5:] == "erase":
        X = X[:-5]

print("YES" if X=="" else "NO")
s = input()

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

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

flag = True

while s != "":
    if s[-5:] == "dream":
        s = s[:-5]
    elif s[-7:] == "dreamer":
        s = s[:-7]
    elif s[-5:] == "erase":
        s = s[:-5]
    elif s[-6:] == "eraser":
        s = s[:-6]
    else:
        flag = False
        break

if flag:
    print("YES")
else:
    print("NO")
def main():
    s = input().strip()

    while len(s):
        if s[-5:] in ("dream", "erase"):
            s = s[:-5]
        elif s[-6:] == "eraser":
            s = s[:-6]
        elif s[-7:] == "dreamer":
            s = s[:-7]
        else:
            print("NO")
            return

    print("YES")


if __name__ == "__main__":
    main()
S = input()
T = ''
words = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(words)):
    words[i] = words[i][::-1]
for i in S[::-1]:
    T += i
    for q in words:
        if T == q:
            T = ''
if T == '':
    print('YES')
else:
    print('NO')
def resolve():
	w = ['dream', 'dreamer', 'erase', 'eraser']
	for i in range(len(w)):
		w[i] = w[i][::-1]
	s = input()[::-1]
	t = ''
	for i in s:
		t += i
		if t in w:
			t = ''
	if len(t):
		print("NO")
	else:
		print("YES")
resolve()
S = input()

flg = 0
while flg==0:
    if S[len(S)-5:]=="dream":
        S = S[:len(S)-5]
    elif S[len(S)-7:]=="dreamer":
        S = S[:len(S)-7]
    elif S[len(S)-5:]=="erase":
        S = S[:len(S)-5]
    elif S[len(S)-6:]=="eraser":
        S = S[:len(S)-6]
    else:
        flg = 1
    if len(S)==0:
        flg = 0
        break
if flg==0:
    print("YES")
else:
    print("NO")
s = input()
for word in ["eraser","erase","dreamer","dream"]:
    s = s.replace(word,".")
if len(set(s)) == 1:
    print("YES")
else:
    print("NO")
S = input()

while len(S) > 0:
  if (len(S) >= 5):
    if (S[-5:] == 'dream' or S[-5:] == 'erase'):
      S = S[:-5]
      continue
  if (len(S) >= 6):
    if (S[-6:] == 'eraser'):
      S = S[:-6]
      continue
  if (len(S) >= 7):
    if (S[-7:] == 'dreamer'):
      S = S[:-7]
      continue
  break
if (len(S) == 0):
  print('YES')
else:
  print('NO')
s = input()[::-1]

while True:
    if len(s) == 0:
        break
    if s[:7] == "remaerd":
        s = s[7:]
    elif s[:6] == "resare":
        s = s[6:]
    elif s[:5] == "maerd" or s[:5] == "esare":
        s = s[5:]
    else:
        print("NO")
        exit()

print("YES")
S = input()
n = len(S)
T = ['dreamer', 'eraser', 'dream', 'erase']
idx = n
res = 'YES'
while idx > 0:
    for t in T:
        if S[idx-len(t):idx] == t:
            idx -= len(t)
            break
    else:
        res = 'NO'
        idx = -1
print(res)
from sys import stdin
def S(): return stdin.readline().rstrip()

a = S()
strl = ['dream','dreamer','erase','eraser']
t = ''
for i in range(len(a)-1,-1,-1):
    if 7<len(t):
        print('NO')
        exit()
    else:
        t = a[i]+t
        if t in strl:
            t = ''

print('YES')
def reverse_str(s):
    return ''.join(list(s)[::-1])


words = list(map(reverse_str, 'dream dreamer erase eraser'.split()))
S = reverse_str(input())
ok = True
while S:
    for r in range(5, 8):
        tmp = S[:r]
        if tmp in words:
            # print(S, end=' => ')
            S = S[r:]
            # print(S)
            break
    else:
        ok = False
        break
print('YES' if ok else 'NO')
S = input()
ch = ["dream", "dreamer", "erase", "eraser"]
while S:
  N = len(S)
  if S[N-5:N] == ch[0] or S[N-5:N] == ch[2]:
    S = S[:N-5]
  elif S[N-6:N] == ch[3]:
    S = S[:N-6]
  elif S[N-7:N] == ch[1]:
    S = S[:N-7]
  else:
    print("NO")
    exit()
print("YES")
s = input()
n = len(s)

s = "".join(reversed(list(s)))
while n:
    if s.startswith("maerd"):
        n -= 5
        s = s[5:]
    elif s.startswith("remaerd"):
        n -= 7
        s = s[7:]
    elif s.startswith("esare"):
        n -= 5
        s = s[5:]
    elif s.startswith("resare"):
        n -= 6
        s = s[6:]
    else:
        break
print("YES" if n == 0 else "NO")
s = input()
l = len(s)
while len(s)>0:
    l=len(s)
    if s[l-5:]=='dream' or s[l-5:]=='erase':
        s=s[:l-5]
    elif s[l-6:]=='eraser':
        s=s[:l-6]
    elif s[l-7:]=='dreamer':
        s=s[:l-7]
    else:
        print('NO')
        exit()
print('YES')
s = input()
s = s[::-1]
j = 0
p = len(s)
while True:
    if s[j:j+5] == 'maerd':
        j += 5
    elif s[j:j+7] == 'remaerd':
        j += 7
    elif s[j:j+5] == 'esare':
        j += 5
    elif s[j:j+6] == 'resare':
        j += 6
    else:
        print('NO')
        break
    if j == p:
        print('YES')
        break
import re

s = input()
flag = re.match('^(dream|dreamer|erase|eraser)+$',s)

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

S_ = (S
    .replace('eraser', '')
    .replace('erase', '')
    .replace('dreamer', '')
    .replace('dream', '')
)

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