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: Accepted

Solution code:
#!/usr/bin/env python3


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


def can_construct(s):
    while len(s) > 0:
        for word in WORDS:
            i = s.rfind(word)
            if i != -1 and len(s) == i + len(word):
                s = s[:i]
                break
        else:
            return False
    return True


def main():
    print("YES" if can_construct(input()) else "NO")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = raw_input()
while True:
    # print s
    if s == "":
        print 'YES'
        break
    elif s[-5:] == "dream" or s[-5:] ==  "erase":
        s = s[:-5]
    elif s[-7:] == "dreamer":
        s = s[:-7]
    elif s[-6:] == "eraser":
        s = s[:-6]
    else:
        print "NO"
        break

Submission status: Accepted

Solution code:
from sys import stdin
a = stdin.readline().strip()
b = ['dream', 'dreamer', 'erase' , 'eraser']
c = []
for i in b:
    c.append(len(i))
n = len(a)
dp = [0] * (n+1)
dp[0] = 1
for i in xrange(1,n+1):
    ind = i-1
    for jj in xrange(4):
        j = b[jj]
        l = c[jj]
        pr = i - l 
        if pr >=0:
            if dp[pr] and j==a[pr:i]:
                dp[i] = 1
if dp[-1]:
    print 'YES'
else:
    print 'NO'

Submission status: Accepted

Solution code:
s = raw_input()
l = len(s)
dp = [0]*(l+1)
dp[0] = 1
for i in xrange(l):
    if dp[i] == 0: continue

    if i+5 <= l and s[i:i+5] in ["dream", "erase"]:
        dp[i+5] = 1
    if i+6 <= l and s[i:i+6] == "eraser":
        dp[i+6] = 1
    if i+7 <= l and s[i:i+7] == "dreamer":
        dp[i+7] = 1
print "YES"*dp[l]or"NO"

Submission status: Accepted

Solution code:
import re

S = raw_input()

if re.match(r'(?:dream(?:er)?|eraser?)+$', S):
    print "YES"
else:
    print "NO"

Submission status: Accepted

Solution code:
import re

print('YES' if re.fullmatch('(dream(er)?|eraser?)+', input()) else 'NO')

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
i = 0
while i < N:
    sig = 0
    S5 = S[i:i+5]
    if S5 == 'dream':
        sig = 1
        if S[i+5:i+7] == 'er' and S[i+7] != 'a':
            i += 2
        i += 5
    elif S5 == 'erase':
        sig = 1
        if S[i+5:i+6] == 'r':
            i += 1
        i += 5
    if sig == 0:
        sig = 2
        Answer = 'NO'
        break
if sig != 2:
    Answer = 'YES'
print(Answer)

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
i = 0
while i < N:
    sig = 0
    S5 = S[i:i+5]
    if S5 == 'dream':
        sig = 1
        if S[i+5:i+7] == 'er' and S[i+7] != 'a':
            i += 2
        i += 5
    elif S5 == 'erase':
        sig = 1
        if S[i+5:i+6] == 'r':
            i += 1
        i += 5
    if sig == 0:
        sig = 2
        Answer = 'No'
        break
if sig != 2:
    Answer = 'Yes'
print(Answer)

Submission status: Runtime Error

Solution code:
s=input()
s=s.replace('eraser','#')
s=s.replace('erase','#')
s=s.replace('dreamer','#')
s=s.replace('dream')
f=1
for it in s:
    if it !='#':
        f=0
        break

if f==1:
    print("YES")
else :
    print("NO")

Submission status: Runtime Error

Solution code:
S=input()
for x in S:
    if("dream" in S and "erase" in S):
        print("YES")
        break
    elif("dream" in S and "eraser" in S):
        print("YES")
        break
    elif( "dreamer" in S and "erase" in S):
        print("YES")
        break
    if( "dreamer" in S and "eraser" in S):
        print("YES")
        break
    else:
        print("NO"

Submission status: Runtime Error

Solution code:

s = input()
l = ["eraser","erase","dreamer","dream"]

while len(s) > 0:
    for i in range(len(l)):
        if l[i] in s:
            s = s.replase(l[i],"")
        else:
            break
            
if len(s) == 0:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:

s = input()
l = ["dream","dreamer","erase","eraser"]

while len(s) > 0:
    for i in range(len(l)):
        if l[i] in s:
            s = s.replase(l[i],"")
        else:
            break
            
if len(s) == 0:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
def main():

    import sys
    input = sys.stdin.readline
    from collections import defaultdict

    class Unionfind:

        __slots__ = ['parents','sizes']

        def __init__(self, n):
            self.parents = list(range(n))
            self.sizes = [1]*n

        def root(self, x):
            if self.parents[x] == x:
                return x
            else:
                root_x = self.root(self.parents[x])
                self.parents[x] = root_x
                return root_x

        def unite(self, x, y):
            x = self.root(x); y = self.root(y)
            if x == y:
                return
            if self.sizes[x] < self.sizes[y]:
                x, y = y, x
            self.sizes[x] += self.sizes[y]
            self.parents[y] = x

        def same(self, x, y):
            return self.root(x) == self.root(y)

        # 集合自体の数 ({1,2}, {3}, {4} : kind -> 3)
        def kind(self):
            for v in range(N):
                self.root(v)
            return len(list(set(self.parents)))

        # xが属する集合の要素の数　({1,2,3} : size(2) -> 3)
        def size(self, x):
            self.sizes[x] = self.sizes[self.root(x)]
            return self.sizes[x]

    N, K, L = map(int,input().split())
    road = Unionfind(N)
    train = Unionfind(N)

    for _ in range(K):
        p, q = map(int,input().split())
        p -= 1; q -= 1
        road.unite(p, q)

    for _ in range(L):
        r, s = map(int,input().split())
        r -= 1; s -= 1
        train.unite(r, s)

    ans_list = []

    r = defaultdict(set)
    t = defaultdict(set)
    for i in range(N):
        r[road.root(i)].add(i)
        t[train.root(i)].add(i)

    ans_list = []

    for i in range(N):
        ans = len(r[road.root(i)] & t[train.root(i)])
        ans_list.append(ans)

    print(*ans_list)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("YES")  # type: str


def no():
    print("NO")  # type: str


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


def dfs(s):
    if len(s) == 0:
        return True
    for t in template:
        if s.startswith(t):
            if dfs(s[len(t):]):
                return True
    return False


def solve(S: str):
    if dfs(S):
        yes()
    else:
        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()

Submission status: Runtime Error

Solution code:
from collections import*
class UNION_FIND(object):
    def __init__(self,n):
        #親の番号を格納する。親だった場合は-(その集合のサイズ)
        #作るときはParentの値を全て-1にする
        #こうすると全てバラバラになる
        self.parent=[-1 for i in range(n)]
        
    def root(self,x):
        #Aがどのグループに属しているか調べる
        if self.parent[x]<0:
            return x
        else:
            self.parent[x]=self.root(self.parent[x])  #親を再帰で探知 再帰は最後に上のifにひっかかる
            return self.parent[x]
 
    def size(self,x):
        #自分のいるグループの頂点数を調べる
        return -self.parent[self.root(x)]   #親をとってきたい
        
    def union(self,x,y):
        #AとBをくっ付ける
        #AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        #print(self.parent)
        x=self.root(x)
        y=self.root(y)
        #print(x,y)
        if x==y:   #すでにくっついてるからくっ付けない
            return False
            
        #大きい方(A)に小さいほう(B)をくっ付けたい
        #大小が逆だったらひっくり返しちゃう。
        if self.size(x)<self.size(y):
            x,y=y,x
        self.parent[x]+=self.parent[y]  #Aのサイズを更新する
        self.parent[y]=x   #Bの親をAに変更する
        return True
        
n,k,l=map(int,input().split())
u1=UNION_FIND(n)
u2=UNION_FIND(n)
d= defaultdict(int)
for i in range(k):
    p,q=map(int,input().split())
    u1.union(p-1,q-1)
for i in range(l):
    p,q=map(int,input().split())
    u2.union(p-1,q-1)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**9)
from collections import Counter
from collections import defaultdict

n,k,l=map(int,input().split())
p=[0]*(k+1)
q=[0]*(k+1)
rd=[[] for _ in range(n+1)]
r=[0]*(l+1)
s=[0]*(l+1)
rw=[[] for _ in range(n+1)]

for i in range(k):
    a,b=map(int,input().split())
    p[i],q[i]=a,b
    rd[a].append(b)
    rd[b].append(a)
for i in range(l):
    a,b=map(int,input().split())
    r[i],s[i]=a,b
    rw[a].append(b)
    rw[b].append(a)

prd=[i for i in range(n+1)]


def union(x,y):
    rx=root(x)
    ry=root(y)
    if rx==ry:
        return
    p[rx]=ry
    
def root(x):
    if p[x]==x:
        return x
    p[x]=root(p[x])
    return p[x]
    
cnt=[[] for _ in range(n+1)]
#print(rd)
#print(rw)

p=prd
for i in range(1,n+1):
    for j in rd[i]:
        union(i,j)
for i in range(1,n+1):
    rt=root(i)
    prd[i]=rt
#    cnt[i].append(rt)

p=[i for i in range(n+1)]
for i in range(1,n+1):
    for j in rw[i]:
        union(i,j)
for i in range(1,n+1):
    rt=root(i)
    p[i]=rt
#    cnt[i].append(rt)
#print(cnt)
#c=Counter(cnt)
dc=defaultdict(int)
for i in range(1,n+1):
    dc[prd[i],p[i]] += 1

#for i in range(n+1):
print(*[dc[prd[i],p[i]] for i in range(1,n+1)])

Submission status: Runtime Error

Solution code:
from collections import deque

def solve(s):
    que = deque()
    que.append(s)
    while len(que) > 0:
        top = que.pop()
        if top == '':
            return 'YES'

        if top[:5] == 'dream':
            if top[5:7] == 'er':
                que.append(s[:7])
            que.append(s[:5])
        elif top[:5] == 'erase':
            if top[5] == 'r':
                que.append(top[:6])
            else:
                que.append(top[:5])
    return 'NO'

print(solve(input()))

Submission status: Runtime Error

Solution code:
s = input()
while s != '':
    if s[:5] == 'dream' or s[:5] == 'erase':
        if s[5] == 'r':
            s = s[6:]
        else:
            s = s[5:]
    else:
        print('NO')
        quit(0)

print('YES')

Submission status: Runtime Error

Solution code:
s = input()
while s != '':
    if s[:5] == 'dream' or s[:5] == 'erase':
        if s[5] = 'r':
            s = s[6:]
        else:
            s = s[5:]
    else:
        print('NO')
        quit(0)

print('YES')

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Feb  8 05:12:38 2019

@author: shinjisu
"""


def db(x):
    global debug
    if debug:
        print(x)


def gen(tstr):
    if len(tstr) <= len(S):
        for w in words:
            yield w + tstr
            for w2 in gen(w + tstr):
                yield w2
    else:
        yield tstr


debug = False
words = ('dream', 'dreamer', 'erase', 'eraser')
S = input()
ans = False
db(S)
for genstr in gen(''):
    db(genstr)
    if genstr == S:
        ans = True
        break
if ans:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
S = ' ' + input()
while True:
  if len(S) >= 5 and S[len(S)-5:] == 'dream':
    S = S[:len(S)-5]
  elif len(S) >= 7 and S[len(S)-7:] == 'dreamer':
    S = S[:len(S)-7]
  elif len(S) >= 5 and S[len(S)-5:] == 'erase':
    S = S[:len(S)-5]
  elif len(S) >= 6 and S[len(S)-6:] == 'eraser':
    S = S[:len(S)-6]
  else:
    break
if S == ' ':
  print(YES)
else:
  print(NO)

Submission status: Runtime Error

Solution code:
S = input()
while True:
  if len(S) >= 5 and S[len(S)-5:] == 'dream':
    S = S[:len(S)-5]
  elif len(S) >= 7 and S[len(S)-7:] == 'dreamer':
    S = S[:len(S)-7]
  elif len(S) >= 5 and S[len(S)-5:] == 'erase':
    S = S[:len(S)-5]
  elif len(S) >= 6 and S[len(S)-6:] == 'eraser':
    S = S[:len(S)-6]
  else:
    break
if S:
  print(NO)
else:
  print(YES)

Submission status: Runtime Error

Solution code:
S = input()
while True:
  if len(S) >= 5 and S[len(S)-5:] == 'dream':
    S = S[len(S)-5:]
  elif len(S) >= 7 and S[len(S)-7:] == 'dreamer':
    S = S[len(S)-7:]
  elif len(S) >= 5 and S[len(S)-5:] == 'erase':
    S = S[len(S)-5:]
  elif len(S) >= 6 and S[len(S)-6:] == 'eraser':
    S = S[len(S)-6:]
  else:
    break
if S:
  print(NO)
else:
  print(YES)

Submission status: Runtime Error

Solution code:
S = input()
while True:
  if len(S) >= 5 and S[len(S)-5:] == 'dream':
    S = S[len(S)-5:]
  elif len(S) >= 7 and S[len(S)-7:] == 'dreamer':
    S = S[len(S)-7:]
  elif len(S) >= 5 and S[len(S)-5:] == 'erase':
    S = S[len(S)-5:]
  elif len(S) >= 6 and S[len(S)-6:] == 'eraser':
    S = S[len(S)-6:]
  else:
    break
if S:
  print(YES)
else:
  print(NO)

Submission status: Runtime Error

Solution code:
S = input()
while True:
  if len(S) >= 5 and S[len(S)-5:] == 'dream':
    S = S[len(S)-5]
  elif len(S) >= 7 and S[len(S)-7:] == 'dreamer':
    S = S[len(S)-7]
  elif len(S) >= 5 and S[len(S)-5:] == 'erase':
    S = S[len(S)-5]
  elif len(S) >= 6 and S[len(S)-6:] == 'eraser':
    S = S[len(S)-6]
  else:
    break
if S:
  print(YES)
else:
  print(NO)

Submission status: Runtime Error

Solution code:
S = input()
while True:
 if len(S) >= 5 and S[len(S)-5:] == 'dream':
  S = S[len(S)-5]
 elif len(S) >= 7 and S[len(S)-7:] == 'dreamer':
  S = S[len(S)-7]
 elif len(S) >= 5 and S[len(S)-5:] == 'erase':
  S = S[len(S)-5]
 elif len(S) >= 6 and S[len(S)-6:] == 'eraser':
  S = S[len(S)-6]
 else:
  break
if S:
  print(YES)
else:
  print(NO)

Submission status: Runtime Error

Solution code:
S = input()
while True:
 if len(S) >= 5 and S[len(S)-5:] == 'dream':
  S = S[len(S)-5]
 elif len(S) >= 7 and S[len(S)-7:] == 'dreamer':
  S = S[len(S)-7]
 elif len(S) >= 5 and S[len(S)-7:] == 'erase':
  S = S[len(S)-5]
 elif len(S) >= 7 and S[len(S)-7:] == 'eraser':
  S = S[len(S)-6]
 else:
  break
if S:
  print(YES)
else:
  print(NO)

Submission status: Runtime Error

Solution code:
S = input()
while True:
 if len(S) >= 5 and S[len(s)-5:] == 'dream':
  S = S[len(s)-5]
 elif len(S) >= 7 and S[len(s)-7:] == 'dreamer':
  S = S[len(s)-7]
 elif len(S) >= 5 and S[len(s)-7:] == 'erase':
  S = S[len(s)-5]
 elif len(S) >= 7 and S[len(s)-7:] == 'eraser':
  S = S[len(s)-6]
 else:
  break
if S:
  print(YES)
else:
  print(NO)

Submission status: Runtime Error

Solution code:
s1 = "maerd"
s2 = "remaerd"
s3 = "esare"
s4 = "resare"

i = input()
s = ''
for c in reversed(i):
    s += c

l = len(s)

i = 0


def dfs(i):
    if i == l:
        print("YES")
        exit()
    if i+5 <= l and s[i:i+5] == s1:
        dfs(i+5)
    elif i+7 <= l and s[i:i+7] == s2:
        dfs(i+7)
    elif i+5 <= l and s[i:i+5] == s3:
        dfs(i+5)
    elif i+6 <= l and s[i:i+6] == s4:
        dfs(i+6)
    else:
        print("NO")
        exit()


dfs(0)

Submission status: Runtime Error

Solution code:
s = input()

l = len(s)


def dfs(i):
    #    print("->", s[i:])
    if i == l:
        print("YES")
        exit()
    if s[i:i+5] == "dream":
        if i+7 < l and s[i+5:i+7] == "er":
            dfs(i+7)
        dfs(i+5)
    elif s[i:i+5] == "erase":
        if i+5 < l and s[i+5] == "r":
            dfs(i+6)
        dfs(i+5)


dfs(0)
print("NO")

Submission status: Runtime Error

Solution code:
s = input()

l = len(s)


def dfs(i):
    if i == l:
        print("YES")
        exit()
    if s[i:i+5] == "dream":
        if i+7 < l and s[i+5:i+7] == "er":
            dfs(i+7)
        dfs(i+5)
    elif s[i:i+5] == "erase":
        if i+6 < l and s[i+5] == "r":
            dfs(i+6)
        dfs(i+5)


dfs(0)

Submission status: Runtime Error

Solution code:
ans = "NO"
s = input()


def dfs(s):
    ret = 0
    if len(s) == 0:
        return 1

    if s[:5] == 'dream' or s[:5] == 'erase':
        ret += dfs(s[5:])
    if s[:7] == 'dreamer':
        ret += dfs(s[7:])
    if s[:6] == 'eraser':
        ret += dfs(s[6:])
    return ret


if dfs(s):
    ans = "YES"
print(ans)

Submission status: Runtime Error

Solution code:
dreameraser

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

def f(s):
    # print(s)
    if s.startswith("dream"):
        return f(s[5:]) or f(s[7:])
    elif s.startswith("erase"):
        return f(s[5:]) or f(s[6:])
    elif s=="":
        return True
    else:
        return False

if f(input()):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s = input()

def solve(s):
    i = 0
    n = len(s)

    while i < n:
        if s[i:i+5] == 'dream':
            if s[i+5:i+7] != 'er':
                i += 5
            elif i+7 < n and s[i+7] == 'a':
                i += 5
            else:
                i += 7
        elif s[i:i+5] == 'erase':
            if s[i+5] == 'r':
                i += 6
            else:
                i += 5
        else:
            return False
    return True

if solve(s):
    print("Yes")
else:
    print('No')

Submission status: Runtime Error

Solution code:
S = raw_input()
t = ['dreamer','dream','eraser','erase']
while len(S) > 0:
    for i in t:
        if S[S.rfind(i):]==i:
            S = S[:S.rfind(t)]
            break
        elif i == t[-1]:
            print "NO"
            exit()
print "YES"

Submission status: Runtime Error

Solution code:
S = raw_input()
t = ['dreamer','dream','eraser','erase']
while len(S) > 0:
    for i in t:
        if S[S.rfind(i):]==i:
            S = S[:S.rfind(t)]
            continue
        elif i == t[-1]:
            print "NO"
            exit()
print "YES"

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
f=[-1]*(n+1)
def check(x):
	if(f[x]!=-1):return f[x]
	if(x==n):return 1
	if(n-x>6 and s[x:x+7]=='dreamer'and check(x+7)):f[x]=1;return 1
	if(n-x>5 and s[x:x+6]=='eraser'and check(x+6)):f[x]=1;return 1
	if(n-x>4 and s[x:x+5]in ['erase','dream']and check(x+5)):f[x]=1;return 1
	f[x]=0
	return 0
if(check(0)):print("YES")
else:print("NO")

Submission status: Runtime Error

Solution code:
from collections import defaultdict
class UnionFind:
    def __init__(self, size):
        self.rank = [0] * size
        self.par = range(size)

    def find(self, x):
        if x == self.par[x]: return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return

        if (self.rank[x] > self.rank[y]):
            self.par[y] = x
        else:
            self.par[x] = y
            if (self.rank[x] == self.rank[y]): self.rank[y] += 1

N, K, L = map(int, raw_input().split())
pq = [map(int, raw_input().split()) for i in xrange(K)]
rs = [map(int, raw_input().split()) for i in xrange(L)]

road = UnionFind(N)
rail = UnionFind(N)
for p, q in pq:
    road.unite(p - 1, q - 1)
for r, s in rs:
    rail.unite(r - 1, s - 1)

for i in xrange(N):
    road.find(i)
    rail.find(i)

pair = defaultdict(int) 
for i, j in zip(road.par, rail.par):
    pair[i, j] += 1

print " ".join(map(str, [pair[road.par[i], rail.par[i]] for i in xrange(N)]))

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

class UnionFind:

    def __init__(self, n):
        self.p = list(range(n))
        self.rank = [0] * n

    def find_root(self, x):
        if x != self.p[x]:
            self.p[x] = self.find_root(self.p[x])

        return self.p[x]

    def is_same(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def unite(self, x, y):
        u = self.find_root(x)
        v = self.find_root(y)

        if u == v:
            return

        if self.rank[u] < self.rank[v]:
            self.p[u] = v
        else:
            self.p[v] = u

            if self.rank[u] == self.rank[v]:
                self.rank[u] += 1


N, K, L = map(int, sys.stdin.readline().split())

uf1 = UnionFind(N)
uf2 = UnionFind(N)

for i in range(K):
    p, q = map(int, sys.stdin.readline().split())
    p, q = p - 1, q - 1
    uf1.unite(p, q)

for i in range(L):
    r, s = map(int, sys.stdin.readline().split())
    r, s = r - 1, s - 1
    uf2.unite(r, s)

cntr = Counter()

for i in range(N):
    u = uf1.find_root(i)
    v = uf2.find_root(i)

    cntr[(u, v)] += 1

ans = []

for i in range(N):
    u = uf1.find_root(i)
    v = uf2.find_root(i)

    ans.append(cntr[(u, v)])

print(*ans)

Submission status: Runtime Error

Solution code:
s = input().strip()
strings = "eraser erase dreamer dream".split()
exceptions = "dreameraser dreamerase".split()
while 1:
  for string in strings:
    if s.startswith(string):
      if string == "dreamer":
        for exception in exceptions:
          if startswith(exception):
            s = s[len(exception):]
      else:
s = s[len(string):]
      break
  else:
    break
print("NO" if s else "YES")

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;

const int MAXN = 200005;

int N, K, L, u, v, visited[2][MAXN], cnt[2] = {1, 2};
vector<int> adjList[2][MAXN];

map<ii,int> m;

void dfs(int id, int node) {
    if (visited[id][node]) {
        return;
    } else {
        visited[id][node] = cnt[id];

        for (int i = 0; i < adjList[id][node].size(); i++) {
            int neighbor = adjList[id][node][i];

            dfs(id, neighbor);
        }
    }
}

int main() {

    scanf("%d%d%d", &N, &K, &L);
    for (int i = 0; i < K; i++) {
        scanf("%d%d", &u, &v);

        adjList[0][u].push_back(v);
        adjList[0][v].push_back(u);
    }

    for (int i = 0; i < L; i++) {
        scanf("%d%d", &u, &v);

        adjList[1][u].push_back(v);
        adjList[1][v].push_back(u);
    }

    for (int i = 1; i <= N; i++) {
        if (!visited[0][i]) {
            dfs(0, i); cnt[0] += 2;
        }
        if (!visited[1][i]) {
            dfs(1, i); cnt[1] += 2;
        }
    }

    for (int i = 1; i <= N; i++) {
        m[ii(visited[0][i], visited[1][i])]++;
    }

    for (int i = 1; i <= N; i++) {
        cout << m[ii(visited[0][i], visited[1][i])] << " ";
    }

    return 0;
}

Submission status: Runtime Error

Solution code:
no

Submission status: Runtime Error

Solution code:
S = input()
for i in ['eraser', 'erase', 'dreamer', 'dream']:
    S=S.replace(i, 'R')
print(['NO', 'YES'][len(s) == 1 and 'R' in s])

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
import re
import math
import itertools
import collections
import bisect
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.141592653589
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)]
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

class UnionFind:
    def __init__(self, size):
        self.rank=[0]*size
        self.par =range(size)
        self.grp =size

    def find(self, x):
        if x==self.par[x]: return x

        self.par[x]=self.find(self.par[x])
        return self.par[x]

    def same(self, x, y): #2つの頂点が同じグループであるかを判定する
        return self.find(x)==self.find(y)

    def unite(self, x, y): #辺で接続されている2つの頂点を投げて統合する
        x,y=self.find(x),self.find(y)
        if x==y:
            return

        self.grp-=1
        if self.rank[x]<self.rank[y]:
            self.par[x]=y
        else:
            self.par[y]=x
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def group_num(self):
        return self.grp
    def ra(self):
        return self.rank

n,k,l=map(int,raw_input().split())
uf=UnionFind(n)
q1,q2=[],[]
ans=[0]*n
for i in range(k):
    a,b=map(int,raw_input().split())
    uf.unite(a-1,b-1)
    q1.append((a-1,b-1))
    ans[a-1]=1
    ans[b-1]=1

for i in range(l):
    a,b=map(int,raw_input().split())
    if ans[a-1]==0: ans[a-1]=1
    if ans[b-1]==0: ans[b-1]=1
    if uf.same(a-1,b-1):
        ans[a-1]=2
        ans[b-1]=2

uf=UnionFind(n)
for i in q2:
    uf.unite(i[0],i[1])
for i in q1:
    if uf.same(i[0],i[1]):
        ans[i[0]]=2
        ans[i[1]]=2
    
print ' '.join(map(str,ans))

Submission status: Runtime Error

Solution code:
S = raw_input()

def pick_greedy(S):
    if S[0:5] == 'dream':
        if S[5:7] == 'er':
            if S[7] == 'a':
                ret = 'dream'
            else:
                ret = 'dreamer'
        else:
            ret = 'dream'
    elif S[0:5] == 'erase':
        if S[5] == 'r':
            ret = 'eraser'
        else:
            ret = 'erase'
    else:
        ret = 'no'
    return ret

sol = 'YES'

while len(S) > 0:
    r = pick_greedy(S)
    if r == 'no':
        sol = 'NO'
        break
    else:
        if len(S) < len(r):
            sol = 'NO'
            break
        else:
            S = S[len(r):]
        
print sol

Submission status: Runtime Error

Solution code:
T = ["maerd", "remaerd", "esare", "resare"]

def match(s):
	if s == "":
		return True
	elif s[0] == "m" and len(s) >= len(T[0]) and s[:len(T[0])] == T[0]:
		return match(s[len(T[0]):])
	elif s[0] == "r" and len(s) > 2:
		if s[2] == "m" and len(s) >= len(T[1]) and s[:len(T[1])] == T[1]:
			return match(s[len(T[1]):])
		elif s[2] == "s" and len(s) >= len(T[3]) and s[:len(T[3])] == T[3]:
			return match(s[len(T[3]):])
		else:
			return False
	elif s[0] == "e" and len(s) >= len(T[2]) and s[:len(T[2])] == T[2]:
		return match(s[len(T[2]):])
	else:
		return False

S = raw_input()
S = S[::-1]
if match(S):
	print "YES"
else:
	print "NO"

Submission status: Runtime Error

Solution code:
T = ["dream", "dreamer", "erase", "eraser"]

def match(s):
	if s == "":
		return True
	else:
		ans = False
		for i in T:
			if len(i) <= len(s) and s[:len(i)] == i:
				ans |= match(s[len(i):])
		return ans

S = raw_input()
if match(S):
	print "YES"
else:
	print "NO"

Submission status: Runtime Error

Solution code:
s = raw_input()

def func(st):
    head = st[:8]
    if head[5:8] == 'dre' or head[5:8] == 'era':
        return st[5:]
    elif head[5:8] == 'erd' or head[5:8] == 'ere':
        return st[7:]
    elif head[5:8] == 'rdr' or head[5:8] == 'rer':
        return st[6:]
    else:
        return ''

while True:
    if len(t) < 8:
        if t == 'dream' or t == 'erase' or t == 'dreamer' or t == 'eraser':
            print 'YES'
        else:
            print 'NO'
        break
    else:
        t = func(t)

Submission status: Runtime Error

Solution code:
s = raw_input()

def func(st):
    head = st[:8]
    if head[5:8] == 'dre' or head[5:8] == 'era':
        return st[5:]
    elif head[5:8] == 'erd' or head[5:8] == 'ere':
        return st[7:]
    elif head[5:8] == 'rdr' or head[5:8] == 'rer':
        return st[6:]
    else:
        return ''

while True:
    print t
    if len(t) < 8:
        if t == 'dream' or t == 'erase' or t == 'dreamer' or t == 'eraser':
            print 'YES'
            break
        else:
            print 'NO'
            break
    else:
        t = func(t)

Submission status: Runtime Error

Solution code:
S = raw_input()

def pick_greedy(S):
    if S[0:5] == 'dream':
        if S[5:7] == 'er':
            if S[7] == 'a':
                ret = 'dream'
            else:
                ret = 'dreamer'
        else:
            ret = 'dream'
    elif S[0:5] == 'erase':
        if S[5] == 'r':
            ret = 'eraser'
        else:
            ret = 'erase'
    else:
        ret = 'no'
    return ret

sol = 'YES'

while len(S) > 0:
    r = pick_greedy(S)
    if r == 'no':
        sol = 'NO'
        break
    else:
        S = S[len(r):]
        
print sol