Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

(N, K) = [int(x) for x in input().split()]
P = [int(x) - 1 for x in input().split()]  # 0 indexed
C = [int(x) for x in input().split()]


inf = float("inf")


ans = max(C)  # at least one move
for pos in range(N):
    i = pos
    score = 0
    cycleLen = None
    cycleGain = None
    bestInc = 0
    for k in range(K):
        i = P[i]
        score += C[i]
        ans = max(ans, score)
        bestInc = max(bestInc, score)

        if cycleLen is not None and k == K % cycleLen:
            numCycles = (K - k) // cycleLen

            ans = max(ans, cycleGain * numCycles + bestInc)
            break

        if i == pos:
            cycleLen = k
            cycleGain = score

print(ans)


### FIXED CODE ###

(N, K) = [int(x) for x in input().split()]
P = [int(x) - 1 for x in input().split()]  # 0 indexed
C = [int(x) for x in input().split()]


inf = float("inf")


ans = max(C)  # at least one move
for pos in range(N):
    i = pos
    score = 0
    cycleLen = None
    cycleGain = None
    bestInc = 0
    k = 0
    while k < K:
        i = P[i]
        score += C[i]
        ans = max(ans, score)

        if i == pos:
            cycleLen = k + 1
            numCycles = max(0, (K - k - cycleLen) // cycleLen)
            if k + numCycles * cycleLen < K:
                k += numCycles * cycleLen
                score += numCycles * score
        k += 1

print(ans)
### BUGGY CODE ###

N = int(input())
numbers = list(map(int, input().split()))

l = []
amount = 0
for i in range(N):
    for j in range(N-1):
        if numbers[j] == i+1:
            amount = amount + 1
    l.append(amount)
    amount = 0

for i in range(N):
    print(l[i])

### FIXED CODE ###

N = int(input())
numbers = list(map(int, input().split()))

result = [0] * N
for i in numbers:
    result[i- 1] += 1
    
for i in range(N-1):
    print(result[i])
print(0)
### BUGGY CODE ###

import numpy as np
n,w=map(int,input().split())
wv=[]
for _ in range(n):
    wv.append(list(map(int,input().split())))
maxvalue=n*100**3
dp=np.full(maxvalue+1,w+1) # dp[j]:価値総和jをちょうど実現できる最小の重さ総和
dp[0]=0
for i in range(n):# i番目までの商品について全ての重さについて調べる
    w_=wv[i][0]
    v_=wv[i][1]
    dp[v_:]=np.minimum(dp[v_:],dp[:-v_]+w_)

print(np.where(dp<=w)[0][-1])


### FIXED CODE ###

import numpy as np
n,w=map(int,input().split())
wv=[]
for _ in range(n):
      wv.append(list(map(int,input().split())))
# dp[i]:価値の総和をちょうどiにできる最小の重さ総和
# dp[i]=w+1となる価値総和iにはできない。
# 求めるのはdp[i]<=wとなる最大のi
dp=np.full(10**5+1,w+1) # ndarray(1000,1000,...,1000])
dp[0]=0
# 10**5:viの総和の最大
for i in range(n):
      w_=wv[i][0]
      v_=wv[i][1]
      # i番目までの商品を取るか取らないかの全ての組み合わせをためすことができる。
      dp[v_:]=np.minimum(dp[v_:], dp[:-v_]+w_)
print(np.where(dp<=w)[0][-1])
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))

for i in range(N):
  for j in range(N):
    if (i == j):
      continue
    if (A[i] == A[j]):
      print("NO")
      exit()
print("YES")

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

if (len(A) == len(set(A))):
  print("YES")
else:
  print("NO")
### BUGGY CODE ###

n = int(input())
hs = [int(x) for x in input().split()]

curr_height = 0
max_stepnum = 0
for start_point in range(n):
  stepnum = 0
  curr_height = hs[start_point]
  for i in range(start_point+1, n):
    if curr_height >= hs[i]:
      stepnum += 1
      curr_height = hs[i]
    else:
      break
  if stepnum > max_stepnum:
    max_stepnum = stepnum

print(max_stepnum)


### FIXED CODE ###

n = int(input())
hs = [int(x) for x in input().split()]

curr_height = 0
max_stepnum = 0
start_point = 0

while start_point < n-1:
  stepnum = 0
  curr_height = hs[start_point]
  for i in range(start_point+1, n):
    if curr_height >= hs[i]:
      stepnum += 1
      curr_height = hs[i]
    else:
      start_point = i
      break
  else:
     start_point = n-1

  if stepnum > max_stepnum:
    max_stepnum = stepnum

print(max_stepnum)
### BUGGY CODE ###

import math
l, r = map(int, input().split(' '))

min_x = 2018
for i in range(l, r+1):
    for j in range(i+1, r+1):
        x = (i*j) % 2019
        if x < min_x:
            min_x = x
print(min_x)


### FIXED CODE ###

import math
l, r = map(int, input().split(' '))

R = min(l+2018, r)
min_x = 2018

for i in range(l, R+1):
    for j in range(i+1, R+1):

        x = (i*j) % 2019
        if x < min_x:
            min_x = x
print(min_x)
### BUGGY CODE ###

R, G, B, N = map(int, input().split())
ans = 0
NpB = N//B
for x in range(N // R + 1):
	for y in range(N // G + 1):
		if (N - R * x - G * y) % B == 0 and 0 <= (N - R * x - G * y) // B <= NpB:
			ans += 1
print(ans)

### FIXED CODE ###

R, G, B, N = map(int, input().split())
ans = 0
 
for Rx in range(0, N+1, R):
    for Gy in range(0, N+1, G):
        check = N - Rx - Gy
        if check % B == 0 and 0 <= check // B <= N // B:
            ans += 1
print(ans)
### BUGGY CODE ###

n = int(input())
a = [int(e) for e in input().split()]

for i in range(n):
  temp = [a[k] for k in range(n) if k != i]
  cnt = [temp.count(k) for k in list(set(temp))]
  print(sum([ c * (c-1) for c in cnt]) // 2)
 

### FIXED CODE ###

n = int(input())
s = list(map(int,input().split()))

import collections

cnt = collections.Counter(s)
ans = sum([(v * (v-1)) // 2 for k, v in cnt.items()])

for i in range(len(s)):
  print(ans - cnt[s[i]] + 1)
### BUGGY CODE ###

mod = 10**9+7

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [0 for __ in range(1 << n)]
dp[0] = 1

for bit in range(1 << n):
    i = bin(bit).count("1")
    for j in range(n):
        bit_new = bit | (1 << j)
        if bit_new != bit and a[i-1][j] == 1:
            dp[bit_new] += dp[bit]
            dp[bit_new] %= mod

print(dp[-1])


### FIXED CODE ###

mod = 10**9+7

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [-1 for __ in range(1 << n)]
dp[0] = 1


def dfs(bit, i):
    if dp[bit] != -1:
        return dp[bit]
    else:
        tmp = 0
        for j in range(n):
            if bit & (1 << j) and a[i][j]:
                tmp += dfs(bit ^ (1 << j), i+1)
    dp[bit] = tmp % mod
    return dp[bit]


print(dfs(2**n-1, 0))
### BUGGY CODE ###

import itertools

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
if X > K:
    A.sort(reverse=True)
    A = A[:K]
B = list(map(int, input().split()))
if Y > K:
    B.sort(reverse=True)
    B = B[:K]
C = list(map(int, input().split()))
if Z > K:
    C.sort(reverse=True)
    C = C[:K]

AB = []
for p in itertools.product(A, B):
    AB.append(sum(p))
AB.sort(reverse=True)
AB = AB[:K]

l = []
for p in itertools.product(AB, C):
    l.append(sum(p))
l.sort(reverse=True)
for i in range(K):
    print(l[i])
    

### FIXED CODE ###

x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for num in lisb:
    for nu in lisa:
        an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:
        ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])
### BUGGY CODE ###

def main():
    n, k= map(int, input().split())
    a = list(map(int, input().split()))
    
    pre = 1
    for b in a[0:k]:
        pre *= b
    now = pre
        
    for i in range(1, n-k+1):
        now = pre // a[i - 1] * a[k+ i -1]
        if pre < now:
            print('Yes')
        else:
            print('No')
        pre = now
    
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n, k= map(int, input().split())
    a = list(map(int, input().split()))

    for i in range(1, n-k+1):
        if a[i - 1] < a[k+ i -1]:
            print('Yes')
        else:
            print('No')
            
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
score=[0]*(n-k+1)
for i in range(k-1,n):
    score[i-k+1]=1
    for j in range(k):
        score[i-k+1]*=a[i-j]
for i in range(1,n-k+1):
    if score[i-1]<score[i]:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(k,n):
    if a[i]>a[i-k]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import sys
from collections import deque

N = int(input())
A = [deque([int(i) for i in input().split()]) for i in range(N)]

ans=0
empty = [deque() for n in range(N)]

while True:
    change=0
    stamina=[1]*N
    for g in range(N):
        if A[g]!=deque() and stamina[g]==1 and stamina[A[g][0]-1]==1:
            if g+1 == A[A[g][0]-1][0]:
                _pop = A[g].popleft()#popはゴミ
                A[_pop-1].popleft()
                stamina[g]=0
                stamina[_pop-1]=0
                change+=1
    ans+=1
    if change==0:
        break
    if A==empty:
        print(ans)
        sys.exit()

print(-1)

### FIXED CODE ###

import sys
from collections import deque

N = int(input())
A = [deque([int(i) for i in input().split()]) for i in range(N)]

ans=0
empty = [deque() for i in range(N)]
pre_fight = set([i for i in range(N)])
record = set()

while True:
    for g in pre_fight:
        if A[g]!=deque():
            if g+1 == A[A[g][0]-1][0]:
                record.add(g)
                record.add(A[g][0]-1)
    if record==set():
        break
    else:
        for i in record:
            A[i].popleft()
    ans+=1
    pre_fight = record
    record = set()
    if A==empty:
        print(ans)
        sys.exit()

print(-1)
### BUGGY CODE ###

N = int(input())

def sol(n):
  if n == 0:
    return 2
  elif n == 1:
    return 1
  else:
    return sol(n-1) + sol(n-2)

print(sol(N))
  

### FIXED CODE ###

N = int(input())

dp = [0] * (N+10)
dp[0] = 2
dp[1] = 1

for i in range(2,N+1):
  dp[i] = dp[i-1] + dp[i-2]

print(dp[N])
### BUGGY CODE ###

mod=998244353
def mod_pow(x,n):
    res=1
    while n>0:
        if n&1:
            res=res*x%mod
        x=x*x%mod
        n>>=1
    return res
def inverse_element(t):
    return mod_pow(t,mod-2)

n,m,k=map(int,input().split())
ans=0
p1=m*mod_pow(m-1,n-1)%mod
p2=1
for i in range(0,k+1):
    ans+=p1*p2%mod
    ans%=mod
    p1*=inverse_element(m-1)
    p2*=(n-i-1)
    p2*=inverse_element(i+1)
    p1%=mod
    p2%=mod
print(ans)

### FIXED CODE ###

mod=998244353
def mod_pow(x,n):
    res=1
    while n>0:
        if n&1:
            res=res*x%mod
        x=x*x%mod
        n>>=1
    return res
def inverse_element(t):
    return mod_pow(t,mod-2)

n,m,k=map(int,input().split())
if m==1:
    if k==n-1:
        print(m)
    else:
        print(0)
    exit(0)
ans=0
p1=m*mod_pow(m-1,n-1)%mod
p2=1
for i in range(0,k+1):
    ans+=p1*p2%mod
    ans%=mod
    p1*=inverse_element(m-1)
    p2*=(n-i-1)
    p2*=inverse_element(i+1)
    p1%=mod
    p2%=mod
print(ans%mod)
### BUGGY CODE ###

def main():
    n = int(input())
    r = []
    ans = 0
    for i in range(n):
        r.append(int(input()))

    ans = min(r) - max(r)
    for i in reversed(range(n)):
        for j in reversed(range(i)):
            tmp = r[i] - r[j]
            if tmp > ans:
                ans = tmp
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n = int(input())
    ans = 0
    minr = int(input())
    ans = -1 * 10**9
    for i in range(n-1):
        r = int(input())
        ans = max(ans, r-minr)
        minr = min(minr, r)

    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

from operator import itemgetter
n, m = map(int, input().split())
a = list(map(int, input().split()))
op = [list(map(int, input().split())) for _ in range(m)]
op.sort(key=itemgetter(1), reverse=True)
a.sort()

idx = 0
for b, c in op:
    for i in range(b):
        if idx < n and a[idx] < c:
            a[idx] = c
            idx += 1
        if idx >= n:
            break
    if idx >= n:
        break


print(sum(a))


### FIXED CODE ###

from operator import itemgetter
n, m = map(int, input().split())
a = list(map(int, input().split()))
op = [list(map(int, input().split())) for _ in range(m)]
op.sort(key=itemgetter(1), reverse=True)
a.sort()

idx = 0
ans = 0
for i in range(n):
    if idx < m and op[idx][1] > a[i]:
        ans += op[idx][1]
    else:
        ans += a[i]

    if idx < m and op[idx][0] > 1:
        op[idx][0] -= 1
    else:
        idx += 1


print(ans)
### BUGGY CODE ###

def men(t):
    xmin = min(st + i * t for i, st in enumerate(mg[0]))
    xmax = max(st + i * t for i, st in enumerate(mg[1]))
    ymin = min(st + i * t for i, st in enumerate(ue[0]))
    ymax = max(st + i * t for i, st in enumerate(ue[1]))
    return (xmax - xmin) * (ymax - ymin)

n = int(input())
inf = float("inf")
mg = [[inf, inf, inf], [-inf, -inf, -inf]]
ue = [[inf, inf, inf], [-inf, -inf, -inf]]
for _ in range(n):
    x, y, d = input().split()
    x = int(x)
    y = int(y)
    if d == "U":
        mv = 1
        uv = 2
    elif d == "D":
        mv = 1
        uv = 0
    elif d == "R":
        mv = 2
        uv = 1
    else:
        mv = 0
        uv = 1
    if x < mg[0][mv]: mg[0][mv] = x
    if x > mg[1][mv]: mg[1][mv] = x
    if y < ue[0][uv]: ue[0][uv] = y
    if y > ue[1][uv]: ue[1][uv] = y
mn = inf
mx = -inf
for x in mg:
    if x[0] < mn: mn = x[0]
    if x[1] > mx: mx = x[1]
dx = mx - mn
mn = inf
mx = -inf
for x in ue:
    if x[0] < mn: mn = x[0]
    if x[1] > mx: mx = x[1]
dy = mx - mn
L = 0
R = (max(mg[1] + ue[1]) - min(mg[0] + ue[0])) * 2
while R - L > 10 ** -10:
    l = (2 * L + R) / 3
    r = (L + 2 * R) / 3
    if men(l) > men(r):
        L = l
    else:
        R = r
t = (R + L) / 2
print(men(t))


### FIXED CODE ###

def men(t):
    xmin = min(st + i * t for i, st in enumerate(mg[0]))
    xmax = max(st + i * t for i, st in enumerate(mg[1]))
    ymin = min(st + i * t for i, st in enumerate(ue[0]))
    ymax = max(st + i * t for i, st in enumerate(ue[1]))
    return (xmax - xmin) * (ymax - ymin)

n = int(input())
inf = 10**9
mg = [[inf, inf, inf], [-inf, -inf, -inf]]
ue = [[inf, inf, inf], [-inf, -inf, -inf]]
mg0=mg[0]
mg1=mg[1]
ue0=ue[0]
ue1=ue[1]
for _ in range(n):
    x, y, d = input().split()
    x = int(x)
    y = int(y)
    if d == "U":
        mv = 1
        uv = 2
    elif d == "D":
        mv = 1
        uv = 0
    elif d == "R":
        mv = 2
        uv = 1
    else:
        mv = 0
        uv = 1
    if x < mg0[mv]: mg0[mv] = x
    if x > mg1[mv]: mg1[mv] = x
    if y < ue0[uv]: ue0[uv] = y
    if y > ue1[uv]: ue1[uv] = y
t=set([0])
for lst in [mg0,mg1,ue0,ue1]:
    v0,v1,v2=lst
    for tk in [v0-v1,v1-v2,(v0-v2)/2]:
        if tk>=0:
            t.add(tk)
print(min(men(tk) for tk in t))
### BUGGY CODE ###

n=int(input())

robotLEFT=[]
robotRIGHT={}

for _ in range(n):
    x,l=map(int,input().split())
    if x-l not in robotLEFT:
        robotLEFT.append(x-l)
        robotRIGHT[x-l]=x+l
    else:
        robotRIGHT[x-l]=min(robotRIGHT[x-l],x+l)

robotLEFT.sort()
#print(robotRIGHT)
#print(robotLEFT)

temp=robotLEFT[0]
LL=temp-2
RR=temp-1
cnt=0

for item in robotLEFT:
    #print(LL,RR,cnt)
    if RR<=item:
        cnt+=1
        LL=item
        RR=robotRIGHT[LL]
    else:
        if RR>=robotRIGHT[item]:
            RR=robotRIGHT[item]
            LL=item
print(cnt)




### FIXED CODE ###

n=int(input())

robot=[]

for _ in range(n):
    x,l=map(int,input().split())
    robot.append([x-l,x+l])
robot.sort()



RR=robot[0][0]-1
cnt=0

for item in robot:
    if RR<=item[0]:
        cnt+=1
        RR=item[1]
    elif RR>=item[1]:
        RR=item[1]

print(cnt)
### BUGGY CODE ###

N = int(input())

def f(n):
    total = 0
    for x in range(1,100):
        for y in range(1,100):
            for z in range(1,100):
                if (x + y + z)**2 - (x*y + y*z + x*z) == n:
                    total += 1
    return total

for i in range(1,N+1):
    print(f(i))

### FIXED CODE ###

N = int(input())


ans = [0]*(N+1)
i = 102
for x in range(1,i):
    for y in range(1,i):
        for z in range(1,i):
            total = (x + y + z)**2 - (x*y + y*z + x*z)
            if total <= N:
                ans[total] += 1

for i in range(1,N+1):
    print(ans[i])
### BUGGY CODE ###

from itertools import product

N = int(input())
r = range(N)
A = [list(map(int, input().split())) for _ in r]

for i in r: A[i][i] = float('inf')
possible = True
ans = 0
for i in r :
    for j in range(i+1,N):
        for k in r:
            if A[i][j] < A[i][k] + A[k][j]:
                continue
            elif A[i][j] == A[i][k] + A[k][j]:
                break
            else:
                possible = False
            break
        else:
            ans += A[i][j]
print(ans if possible else -1)

### FIXED CODE ###

def main():
    inf=float("inf")
    n=int(input())
    alst=[list(map(int,input().split())) for _ in range(n)]
 
    for i in range(n):
        alst[i][i]=inf
 
    sm=0
    token=0
 
    for i in range(n):
        for j in range(i+1,n):
            for k in range(n):
                if alst[i][k]+alst[k][j]>alst[i][j]:
                    continue
                elif alst[i][k]+alst[k][j]==alst[i][j]:
                    break
                else:
                    token=1
                    break
            else :
                sm+=alst[i][j]
    
    if token : sm=-1
 
    print(sm)
 
main()
### BUGGY CODE ###

n,k,q = map(int,input().split())
a = [int(input()) for _ in range(q)]
m = [k]*n 
for i in range(q):
  m = list(map(lambda x: x-1,m))
  m[a[i]-1] += 1
for j in range(n):
  if m[j] > 0:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

n,k,q = map(int,input().split())
a = [int(input()) for _ in range(q)]
m = [k-q]*n 
for i in range(q):
  m[a[i]-1] += 1
for j in range(n):
  if m[j] > 0:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

L, R = map(int, input().split())
mini = mod = 2019

for i in range(L, R+1):
    for j in range(i+1, R+1):
        mod = (i * j) % 2019
        mini = min(mini, mod)
        
        if (mini == 0):
            break

print(mini)

### FIXED CODE ###

L, R = map(int, input().split())
mini = mod = 2019

for i in range(L, R+1):
    for j in range(i+1, R+1):
        mod = (i * j) % 2019
        mini = min(mini, mod)
        
        if (mini == 0):
            print(mini)
            exit()
        
print(mini)
### BUGGY CODE ###

def e_flatten(MOD=10**9 + 7):
    from fractions import gcd
    from functools import reduce
    N = int(input())
    A = [int(i) for i in input().split()]

    def lcm(a, b):
        return a * b // gcd(a, b)

    l = reduce(lcm, A)
    ans = [l // a for a in A]
    return sum(ans) % MOD

print(e_flatten())

### FIXED CODE ###

def e_flatten(MOD=10**9 + 7):
    from fractions import gcd
    from functools import reduce
    N = int(input())
    A = [int(i) for i in input().split()]

    def lcm(a, b):
        return a * b // gcd(a, b)

    def inv(n, mod=MOD):
        return pow(n, mod - 2, mod)

    l = reduce(lcm, A) % MOD
    ans = [(l * inv(a)) % MOD for a in A]
    return sum(ans) % MOD

print(e_flatten())
### BUGGY CODE ###

#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re

BIGNUM = 10 ** 9 + 7

def main():
    #A, B, C = map(int, input().split())
    #N = int(input())
    #Hs = list(map(int, input().split()))

    S = input().strip()
    result = [0] * len(S)

    for i in range(len(S)):
        if S[i] == 'R':
            for j in range(i+1, len(S)):
                if S[j] == 'L':
                    break
            dist = j - i
            if dist % 2 == 0:
                result[j] += 1
            else:
                result[j-1] += 1
        else:
            # S[i] == 'L'
            for k in range(1, i+1):
                j = i - k
                if S[j] == 'R':
                    break
            dist = k
            if dist % 2 == 0:
                result[j] += 1
            else:
                result[j+1] += 1

    print(' '.join(map(str, result)))


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re
import bisect

BIGNUM = 10 ** 9 + 7

def main():
    #A, B, C = map(int, input().split())
    #N = int(input())
    #Hs = list(map(int, input().split()))

    S = input().strip()
    result = [0] * len(S)

    L_list, R_list = {}, {}
    prev_L, prev_R = [], []
    for i in range(len(S)):
        if S[i] == 'L':
            for j in prev_L:
                L_list[j] = i
            prev_L = []
        else:
            prev_L.append(i)
    for i in range(len(S)):
        i = len(S) - 1 - i
        if S[i] == 'R':
            for j in prev_R:
                R_list[j] = i
            prev_R = []
        else:
            prev_R.append(i)

    for i in range(len(S)):
        if S[i] == 'R':
            j = L_list[i]
            dist = j - i
            if dist % 2 == 0:
                result[j] += 1
            else:
                result[j-1] += 1
        else:
            # S[i] == 'L'
            j = R_list[i]
            dist = i - j
            if dist % 2 == 0:
                result[j] += 1
            else:
                result[j+1] += 1

    print(' '.join(map(str, result)))


if __name__ == '__main__':
    main()
### BUGGY CODE ###

S = list(input())
strs = ["dream","dreamer","erase","eraser"]
ind = 0
while True:
    if S[ind] == "e":
        if S[ind:ind+5] == list("erase"):
            if ind+5 == len(S): 
                print("YES")
                exit()
            if S[ind+5] == "r": 
                if ind + 6 ==len(S):
                    print("YES")
                    exit()
                ind+=6 #eraserで確定
            elif S[ind+5] == "d" or S[ind+5]=="e": 
                ind+=5 #dreamかeraser
            else:
                print("NO")
                exit()
        else:
            print("NO")
            exit()
    elif S[ind] == "d":
        if S[ind:ind+5] == list("dream"):
            if ind + 5 == len(S):
                print("YES")
                exit()
            if S[ind+5] == "d" : ind += 5 #"dreamで確定"
            if S[ind+5] == "e":
                if S[ind+6] == "r":
                    if ind + 7 == len(S):
                        print("YES")
                        exit()
                    if S[ind+7] == "e" or S[ind+7] =="d": ind += 7 #dreamerで確定
                    elif S[ind+7] == "a": ind += 5 #"dream->eraseで確定"
                else:
                    print("NO")
                    exit()
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()

### FIXED CODE ###

S = input()
strs = ["erase", "eraser", "dreamer","dream"]
rtss = [s[::-1] for s in strs]
S = S[::-1]

ind = 0
while True:
    # print(ind,S[ind])
    if S[ind:ind+5] in rtss:
        ind += 5
    elif S[ind:ind+6] in rtss:
        ind += 6
    elif S[ind:ind+7] in rtss:
        ind +=7
    else:
        print("NO")
        exit()
    if ind == len(S):
        print("YES")
        exit()