CodeEff/ECCO huggingface dataset:
# Original solution
import queue
n,m=list(map(int,input().split()))
vis,ci,cb,cc=[0]*(n+1),0,0,0
g=[[] for i in range(n+1)]
def dfs(x):
	stk,flag=queue.LifoQueue(),True
	stk.put((x,1))
	while not stk.empty():
		u,col=stk.get()
		if vis[u]:
			flag&=(vis[u]==col)
			continue
		vis[u]=col
		for i in g[u]:
			stk.put((i,3-col))
	return flag
for i in range(m):
	u,v=list(map(int,input().split()))
	g[u]+=[v]
	g[v]+=[u]
for i in range(1,n+1):
	if vis[i]==0:
		if len(g[i])==0:
			ci+=1
		else:
			if dfs(i):
				cb+=1
			else:
				cc+=1
print((ci*ci+2*ci*(n-ci)+cc*cc+2*cb*cc+2*cb*cb))

# Optimized solution
n,m=list(map(int,input().split()))
vis,ci,cb,cc=[0]*(n+1),0,0,0
g=[[] for i in range(n+1)]
for i in range(m):
	u,v=list(map(int,input().split()))
	g[u]+=[v]
	g[v]+=[u]
for i in range(1,n+1):
	if vis[i]==0:
		if len(g[i])==0:
			ci+=1
		else:
			s,f=[(i,1)],True
			while len(s):
				u,col=s.pop()		
				if vis[u]:
					f&=(vis[u]==col)
					continue
				vis[u]=col
				for i in g[u]:
					s+=[(i,3-col)]
			cb+=f
			cc+=f^1
print((ci*ci+2*ci*(n-ci)+cc*cc+2*cb*cc+2*cb*cb))
# Original solution
print((2*input().count('+')-4))

# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = read().rstrip().decode('utf-8')

answer = 4-2*S.count('-')
print(answer)
# Original solution
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

S = LS2()
a = S.count('+')
b = S.count('-')
print((a-b))

# Optimized solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

S = LS2()
print((S.count('+')-S.count('-')))
# Original solution
print((-4+2*input().count('+')))


# Optimized solution
print((2*input().count('+')-4))
# Original solution
from bisect import bisect_left as bl

def search_left(in_ind, alst, outs, doors):
  tmp = bl(outs, in_ind)
  if tmp == 0:
    return 0
  out_ind = outs[tmp - 1]

  right_door = bl(doors, in_ind) - 1
  if right_door < 0:
    return alst[in_ind]
  left_door = bl(doors, out_ind)
  
  ret = alst[in_ind]
  for door_ind in doors[left_door:right_door + 1]:
    if out_ind < door_ind < in_ind:
      ret = min(ret, -alst[door_ind] - (in_ind - door_ind))
  ret = max(0, ret)
  return ret

def search_right(in_ind, alst, outs, doors):
  tmp = bl(outs, in_ind)
  if tmp == len(outs):
    return 0
  out_ind = outs[tmp]

  right_door = bl(doors, out_ind) - 1
  if right_door < 0:
    return alst[in_ind]
  left_door = bl(doors, in_ind)

  ret = alst[in_ind]
  for door_ind in doors[left_door:right_door + 1]:
    if in_ind < door_ind < out_ind:
      ret = min(ret, -alst[door_ind] - (door_ind - in_ind))
  ret = max(0, ret)
  return ret

def main():
  w = int(eval(input()))
  alst = list(map(int, input().split()))
  outs = []
  ins = []
  doors = []
  for ind, a in enumerate(alst):
    if a > 0:
      ins.append(ind)
    elif a == 0:
      outs.append(ind)
    else:
      doors.append(ind)
  ans = 0
  for in_ind in ins:
    ans += max(search_left(in_ind, alst, outs, doors), search_right(in_ind, alst, outs, doors))
  print(ans)
main() 


# Optimized solution
w = int(eval(input()))
alst = list(map(int, input().split()))
INF = 10 ** 20
acc = -INF
left = []
for i in range(w):
  a = alst[i]
  if a == 0:
    acc = INF
  elif a > 0:
    acc -= 1
  elif a < 0:
    acc = min(acc - 1, -a)
  left.append(acc)

acc = -INF
right = []
for i in range(w):
  a = alst[w - i - 1]
  if a == 0:
    acc = INF
  elif a > 0:
    acc -= 1
  elif a < 0:
    acc = min(acc - 1, -a)
  right.append(acc)
right.reverse()

print((sum([max(0, min(alst[i], max(left[i], right[i]))) for i in range(w)])))
# Original solution
from queue import PriorityQueue

class State:
  def __init__(self,index,time):
    self.index=index
    self.time=time
  def __lt__(self,state):
    return self.time>state.time

while 1:
  try: n=int(eval(input()))
  except: break
  a=list(map(int,input().split()))
  
  ts=[float("inf")]*n
  vis=[False]*n
  pq=PriorityQueue()
  for i in range(n):
    if a[i]==0:
      pq.put(State(i,int(1e9)))
  
  while pq.qsize():
    cur=pq.get()
    if cur.index<0 or n<=cur.index or vis[cur.index] or cur.time<0: continue
    vis[cur.index]=True
    if a[cur.index]<0:
      cur.time=min(cur.time,-a[cur.index]-1)
    ts[cur.index]=cur.time
    pq.put(State(cur.index-1,cur.time-1))
    pq.put(State(cur.index+1,cur.time-1))
  
  res=0
  for i in range(n):
    if a[i]>0 and vis[i]:
      res+=min(a[i],ts[i]+1)
  print(res)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))

ts=[0]*n
for indices in list(range(n)),reversed(list(range(n))):
  t=0
  for i in indices:
    if a[i]==0: t=float("inf")
    if a[i]<0: t=min(t,-a[i])
    if a[i]>0: ts[i]=max(ts[i],min(a[i],t))
    t-=1
print((sum(ts)))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

x = []
y = []
P = sorted((a for a in A if a >= 0), reverse=True)
Q = sorted(a for a in A if a < 0)
if not Q:
    M = sum(P[:-2]) + (P[-2] - P[-1])
    for _ in range(N - 2):
        X = P.pop()
        Y = P.pop()
        x.append(X)
        y.append(Y)
        P.append(X - Y)
    Y = P.pop()
    X = P.pop()
    x.append(X)
    y.append(Y)
elif not P:
    M = -sum(Q[:-2]) - (Q[-2] - Q[-1])
    for _ in range(N - 1):
        X = Q.pop()
        Y = Q.pop()
        x.append(X)
        y.append(Y)
        Q.append(X - Y)
else:
    M = sum(abs(a) for a in A)
    for _ in range(N - 1):
        if len(P) == 1:
            X = P.pop()
            Y = Q.pop()
            x.append(X)
            y.append(Y)
            P.append(X - Y)
        else:
            X = Q.pop()
            Y = P.pop()
            x.append(X)
            y.append(Y)
            Q.append(X - Y)

print(M)
for X, Y in zip(x, y):
    print(('{} {}'.format(X, Y)))


# Optimized solution
# 入力
N = int(eval(input()))
A = list(map(int, input().split()))

# 正-負をなるべく多く達成するように操作する
P = sorted((a for a in A if a >= 0), reverse=True)
Q = sorted(a for a in A if a < 0)

x, y = [], []
if len(P) == 2 and not Q:
    Y, X = P.pop(), P.pop()
    x.append(X)
    y.append(Y)
    P.append(X - Y)
if len(P) >= 3 and not Q:
    X, Y = P.pop(), P.pop()
    x.append(X)
    y.append(Y)
    Q.append(X - Y)
if not P and len(Q) >= 2:
    X, Y = Q.pop(), Q.pop()
    x.append(X)
    y.append(Y)
    P.append(X - Y)
while len(P) >= 2 and Q:
    X, Y = Q.pop(), P.pop()
    x.append(X)
    y.append(Y)
    Q.append(X - Y)
while Q:
    X, Y = P.pop(), Q.pop()
    x.append(X)
    y.append(Y)
    P.append(X - Y)

ans = (
    '{}\n{}'.format(
        P[0],
        '\n'.join(
            '{} {}'.format(X, Y)
            for X, Y in zip(x, y)
        )
    )
)

# 出力
print(ans)
# Original solution
from collections import deque
N = int(eval(input()))
A = (list(map(int, input().split())))
A = sorted(A)
A = deque(A)
l = []
for i in range(N - 1):
    if i == N - 2:
        ans = A[1] - A[0]
        l.append("{} {}".format(A[1], A[0]))
    elif i == N - 3:
        left = A.popleft()
        right = A.pop()
        center = A.pop()

        temp_left = abs(right - (left - center))
        temp_right = abs(left - (right - center))

        if temp_left >= temp_right:
            A.appendleft(left - center)
            A.append(right)
            l.append("{} {}".format(left, center))
        else:
            A.append(right - center)
            A.appendleft(left)
            l.append("{} {}".format(right, center))


    else:
        left = A.popleft()
        left2 = A.popleft()
        right = A.pop()
        right2 = A.pop()
        
        temp_left = abs(right - (left - right2))
        temp_right = abs(left - (right - left2))
        if temp_left >= temp_right:
            A.appendleft(left2)
            A.appendleft(left - right2)
            A.append(right)
            l.append("{} {}".format(left, right2))
        else:
            A.append(right2)
            A.append(right - left2)
            A.appendleft(left)
            l.append("{} {}".format(right, left2))

print(ans)
for line in l:
    print(line)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
A = sorted(A)

leftest_val = A[0]
rightest_val = A[-1]
left_idx = 1
right_idx = N - 2
history = []
for i in range(N - 1):
    left_val = A[left_idx]
    right_val = A[right_idx]
    if i == N - 2:
        history.append("{} {}".format(rightest_val, leftest_val))
        print((rightest_val - leftest_val))
    elif left_val < 0:
        history.append("{} {}".format(rightest_val, left_val))
        rightest_val -= left_val
        left_idx += 1
    else:
        history.append("{} {}".format(leftest_val, right_val))
        leftest_val -= right_val
        right_idx -= 1

for h in history:
    print(h)
# Original solution
S = input()[::-1]
word = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
judge = [True, True, True, True]
count = 0
while any(judge):
  for i in range(len(word)):
    if S[:len(word[i])] == word[i]:
      S = S[len(word[i]):]
    else:
      count += 1
    if S == '':
      print('YES')
      exit()
    if count == 4:
      print('NO')
      exit()
  count = 0

# Optimized solution
a,b,c,d=[i[::-1] for i in ['dream','dreamer','erase','eraser']]
s,j=input()[::-1],True
while j:
  j=False
  for i in [a,b,c,d]:
    if s.startswith(i): s=s[len(i):];j=True
print(('YNEOS'[len(s)>0::2]))
# Original solution
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(S: str):
    while len(S)>4:
        if S[:11]=="dreameraser":
            S=S[11:]
        elif S[:10] == "dreamerase":
            S= S[10:]
        elif S[:6]=="eraser":
            S= S[6:]
        elif S[:5] == "erase" or S[:5]== "dream":
            S=S[5:]
        elif S[:7] == "dreamer":
            S=S[7:]
        else:
            print(NO)
        
    
    if len(S) == 0:
        print(YES)
    else:
        print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()



# Optimized solution
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(S: str):
    S = S[::-1]
    while len(S)>4:
        if S[:6]=="resare":
            S= S[6:]
        elif S[:5] == "esare" or S[:5]== "maerd":
            S=S[5:]
        elif S[:7] == "remaerd":
            S=S[7:]
        else:
            print(NO)
            return 
        
    
    if len(S) == 0:
        print(YES)
    else:
        print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()
# Original solution
S = input()[::-1]
day_dream_word = ["dreamer", "dream", "eraser", "erase"]
day_dream_word = list([s[::-1] for s in day_dream_word])
T = ""
res = False
partial_res = True
while not res and partial_res:
  partial_res = False
  for add_word in day_dream_word:
    nextT = T
    nextT += add_word
    if S == nextT:
      res = True
      break
    if S[:len(nextT)] == nextT:
      partial_res = True
      break
  T = nextT

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

# Optimized solution
S = input()[::-1]
day_dream_word = ["dreamer", "dream", "eraser", "erase"]
day_dream_word = list([s[::-1] for s in day_dream_word])
T = ""
Tindex = 0
res = False
partial_res = True
while not res and partial_res:
  partial_res = False
  for add_word in day_dream_word:
    nextTindex = Tindex + len(add_word)
    
    if S[Tindex:nextTindex] == add_word:
      if len(S) == nextTindex:
        res = True
        break
      else:
        partial_res = True
        break
  Tindex = nextTindex

if res:
  print('YES')
else:
  print('NO')
# Original solution
A = ["dream", "dreamer", "erase", "eraser"]
for i in range(4):
    A[i] = A[i][::-1]

S = input()[::-1]
idx = 0
while idx < len(S):
    flag = False
    for i in range(4):
        if len(S) - idx < len(A[i]):
            continue
        else:
            if S[idx:idx+len(A[i])] == A[i]:
                flag = True
                idx += len(A[i])
                break
            else:
                continue
    if idx >= len(S) or flag == False:
        break

print((["NO","YES"][idx == len(S)]))

# Optimized solution
A = ['dream', 'dreamer', 'erase', 'eraser']

for i in range(len(A)):
    A[i] = A[i][::-1]

s = input()[::-1]
i = 0
while True:
    f = True
    for a in A:
        if len(a) > len(s) - i:
            continue
        if s[i:i+len(a)] == a:
            i += len(a)
            f = False
            break
    else:
        if i == len(s):
            print('YES')
            exit()
        if f == True:
            print('NO')
            exit()


print('YES')
# Original solution
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
print(("YES" if s=="" else "NO"))

# Optimized solution
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s in "":
    print("YES")
else:
    print("NO")
# Original solution
# coding: utf-8
"""this is python work script"""

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

def check_word(word, check_word_list):
    find_word = False

    # print(word, check_word_list)
    for i, cw in enumerate(check_word_list):
        find_result = word.find(cw)
        # print(i, cw, find_result)

    # # remove check word if not find it in string
    # if find_result == -1:
    #     check_word_list.remove(cw)

    #  remove word if find it in string head
        if find_result == 0:
            word_length = len(cw)
            word = word[word_length:]
            find_word = True
        # print(word, check_word_list)

    return find_word, word

def solver(word, check_word_list):
    """solve this problem"""
    wip = True
    while wip:
        wip, word = check_word(word, check_word_list)

    answer = 'NO'
    if len(word) == 0:
        answer = 'YES'
    return answer

def reverse_string_list(string_list):
    answer_list = []
    for word in string_list:
        answer_list.append(word[::-1])

    return answer_list

def main():
    """main function"""
    word = input().rstrip()[::-1]
    word_list = reverse_string_list(CHECK_WORDS)
    answer = solver(word=word, check_word_list=word_list)
    print(answer)

if __name__ == '__main__':
    main()


# Optimized solution
# coding: utf-8
"""this is python work script"""

def solver(word):
    """solve this problem"""
    check_result = word.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')

    answer = 'YES'
    if check_result:
        answer = 'NO'

    return answer

def main():
    """main function"""
    input_word = input().rstrip()
    answer = solver(input_word)
    print(answer)

if __name__ == '__main__':
    main()
# Original solution
s = input()[::-1]

s = s.replace("eraser"[::-1], "")
s = s.replace("erase"[::-1], "")
s = s.replace("dreamer"[::-1], "")
s = s.replace("dream"[::-1], "")

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

# Optimized solution
s = input()[::-1]

words = ["eraser","erase","dreamer","dream"]
for i in words:
  s = s.replace(i[::-1], "")
if s == "": print("YES")
else: print("NO")
# Original solution
S = input()[::-1]
devide = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
    devide[i] = devide[i] [::-1]
    
flag = True
i = 0
while i < len(S):
    flag2 = False
    for j in range(4):
        if devide[j] == S[i : i+len(devide[j])]:
            flag2 = True
            i += len(devide[j])
    
    if not flag2:
        flag = False
        break

print(('YES' if flag == True else 'NO'))

# Optimized solution
S = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
print(('YES' if len(S) == 0 else 'NO'))
# Original solution
def main():
    S = input()[::-1]
    tar = {'maerd', 'remaerd', 'esare', 'resare'}
    i = 0
    while i < len(S):
        if S[i] == 'm':
            if S[i:i+5] == 'maerd':
                i += 5
            else:
                return print("NO")
        elif S[i] == 'e':
            if S[i:i+5] == 'esare':
                i += 5
            else:
                return print("NO")
        elif S[i] == 'r':
            if S[i:i+6] == 'resare':
                i += 6
            elif S[i:i+7] == 'remaerd':
                i += 7
            else:
                return print("NO")
        else:
            return print("NO")
    print("YES")
if __name__ == '__main__':
    main()


# Optimized solution
def main():
    S = input()
    S = S[::-1]
    ans = ["maerd", "remaerd", "esare", "resare"]
    while S:
        for a in ans:
            if S[:5] in ans:
                S = S.replace(S[:5], "", 1)
                break
            elif S[:6] in ans:
                S = S.replace(S[:6], "", 1)
                break
            elif S[:7] in ans:
                S = S.replace(S[:7], "", 1)
                break
        else:
            return print("NO")
    else:
        return print("YES")


if __name__ == '__main__':
    main()
# Original solution
S = input()[::-1]
W = []
for w in ['dreamer', 'eraser', 'erase', 'dream']:
    W.append(w[::-1])
while 1:
    flg = False
    for w in W:
        if S.startswith(w):
            S = S[len(w):]
            flg = True

    if not flg:
        print('NO')
        exit()
    if not S:
        break

print('YES')


# Optimized solution
S = input()[::-1]
W = []
for w in ['dreamer', 'eraser', 'erase', 'dream']:
    W.append(w[::-1])
idx = 0
while 1:
    flg = False
    for w in W:
        if S.startswith(w, idx):
            idx += len(w)
            flg = True

    if not flg:
        print('NO')
        exit()
    if len(S) <= idx:
        break

print('YES')
# Original solution
import sys
input = sys.stdin.readline
S = list(input().rstrip())

while S:
    if S[-1] == "m":
        if S[-5:] == ["d", "r", "e", "a", "m"]:
            S = S[:-5]
        else:
            print("NO")
            sys.exit()
    elif S[-1] == "e":
        if S[-5:] == ["e", "r", "a", "s", "e"]:
            S = S[:-5]
        else:
            print("NO")
    elif S[-6:] == list("eraser"):
        S = S[:-6]
    elif S[-7:] == list("dreamer"):
        S = S[:-7]
    else:
        print("NO")
        sys.exit()
print("YES") 




# Optimized solution
import sys
input = sys.stdin.readline
S = input().rstrip()

while S:
    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:
        print("NO")
        sys.exit()
print("YES")
# Original solution
import sys
S=input()
judge=["dream","dreamer","erase","eraser"]

S_pointer=0

V=set()
V.add(0)

cnt=0
while cnt<len(S)/5+1:
	tmp=set()
	for i in V:
		for j in judge:
			if S[i:i+7].find(j)==0:
				if i+len(j)==len(S):
					tmp.add(i+len(j))
					print("YES")
					sys.exit()
				else:
					tmp.add(i+len(j))

	V=V|tmp
	cnt+=1

#print V

print("YES" if max(V)==len(S) else "NO")

# Optimized solution
import sys
S=input()
judge=["dream","dreamer","erase","eraser"]

V=set()
V.add(0)

cnt=0
while cnt<len(S):
	tmp=set()
	for i in V:
		for j in judge:
			if S[i:i+7].find(j)==0:
				tmp.add(i+len(j))
				if i+len(j)==len(S):
					print("YES")
					sys.exit()
	V=tmp
	cnt+=1
else:
	print("NO")
# Original solution
s=input()[::-1]
p=["maerd","remaerd","resare","esare"]
while True:
  if s[:5]==p[0]:s=s.replace(p[0],"",1)
  elif s[:5]==p[3]:s=s.replace(p[3],"",1)
  elif s[:7]==p[1]:s=s.replace(p[1],"",1)
  elif s[:6]==p[2]:s=s.replace(p[2],"",1)
  else:
    if s=="":print("YES");break
    else:print("NO");break


# Optimized solution
s=input()[::-1]
p=["maerd","remaerd","resare","esare"]
while True:
  if s[:5]==p[0]:s=s[5:]
  elif s[:5]==p[3]:s=s[5:]
  elif s[:7]==p[1]:s=s[7:]
  elif s[:6]==p[2]:s=s[6:]
  else:
    if s=="":print("YES");break
    else:print("NO");break
# Original solution
from re import sub

dest = input().rstrip("\n")

suffixes = ["dream$", "dreamer$", "erase$", "eraser$"]

while True:
    len_before = len(dest)
    for suffix in suffixes:
        dest = sub(suffix, "", dest)
    if len(dest) == len_before:
        break

print(("YES" if not dest else "NO"))


# Optimized solution
dest = input().rstrip("\n")

suffixes = ["dream", "dreamer", "erase", "eraser"]
cut_lens = [-5, -7, -5, -6]

while True:
    for suffix, cut_len in zip(suffixes, cut_lens):
        if dest.endswith(suffix):
            dest = dest[:cut_len]
            break
    else:
        break

print(("YES" if not dest else "NO"))
# Original solution
S = input().strip()
cur = 0
flag = 0
while cur<len(S):
    if S[cur:cur+11]=="dreameraser":
        cur += 11
    elif S[cur:cur+10]=="dreamerase":
        cur += 10
    elif S[cur:cur+7]=="dreamer":
        cur += 7
    elif S[cur:cur+6]=="eraser":
        cur += 6
    elif S[cur:cur+5]=="dream" or S[cur:cur+5]=="erase":
        cur += 5
    else:
        flag = 1
        break
if flag==0:
    print("YES")
else:
    print("NO")

# Optimized solution
S = input().strip()
N = len(S)
if N<5:
    print("NO")
else:
    flag = 0
    cur = N
    while cur>0:
        if cur>=7 and S[cur-7:cur]=="dreamer":
            cur -= 7
        elif cur>=6 and S[cur-6:cur]=="eraser":
            cur -= 6
        elif cur>=5 and S[cur-5:cur] in ["dream","erase"]:
            cur -= 5
        else:
            flag = 1
            break
    if flag==0:
        print("YES")
    else:
        print("NO")
# Original solution
S = input().strip()
N = len(S)
cur = 0
flag = 0
while cur<N:
    if S[cur:cur+5]=="dream":
        if cur+5==N:
            cur += 5
        elif cur+5<N and S[cur+5]=="d":
            cur += 5
        elif S[cur:cur+7]=="dreamer":
            if cur+7==N:
                cur += 7
            elif S[cur+7] in ["d","e"]:
                cur += 7
            elif S[cur+7]=="a":
                cur += 5
            else:
                flag = 1
                break
    elif S[cur:cur+5]=="erase":
        if cur+5==N:
            cur += 5
        elif cur+5<N and S[cur+5]=="r":
            cur += 6
        elif cur+5<N and S[cur+5] in ["d","e"]:
            cur += 5
        else:
            flag = 1
            break
    else:
        flag=1
        break
if flag==0:
    print("YES")
else:
    print("NO")

# Optimized solution
S = input().strip()
N = len(S)
cur = 0
flag = 0
while cur<N:
    if S[cur:cur+5]=="dream":
        if cur+5==N:
            cur += 5
        elif cur+5<N and S[cur+5]=="d":
            cur += 5
        elif S[cur:cur+7]=="dreamer":
            if cur+7==N:
                cur += 7
            elif S[cur+7] in ["d","e"]:
                cur += 7
            elif S[cur+7]=="a":
                cur += 5
            else:
                flag = 1
                break
        else:
            flag=1
            break
    elif S[cur:cur+5]=="erase":
        if cur+5==N:
            cur += 5
        elif cur+5<N and S[cur+5]=="r":
            cur += 6
        elif cur+5<N and S[cur+5] in ["d","e"]:
            cur += 5
        else:
            flag = 1
            break
    else:
        flag=1
        break
if flag==0:
    print("YES")
else:
    print("NO")
# Original solution
S = input()
words = ("dream", "dreamer", "erase", "eraser")

for _ in range((len(S) + 4) // 5):
    for word in words:
        if S.endswith(word):
            S = S[: -len(word)]
print("NO") if S else print("YES")


# Optimized solution
S = input()
for w in ("eraser", "erase", "dreamer", "dream"):
    S = S.replace(w, "")
print("NO") if S else print("YES")