Harryxun/stf_run huggingface dataset:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, k = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
c = [int(x) for x in input().split()]

ans = -float('inf')
for i in range(n):
    now = i
    cnt = 0
    c_sum = [0]
    s = set()
    while True:
        s.add(now)
        c_sum.append(c_sum[-1] + c[now])
        now = p[now]
        cnt += 1
        if now in s:
            break
    if k <= cnt:
        ans = max(ans, max(c_sum[1: min(k + 1, len(c_sum))]))
    else:
        temp = c_sum[-1]
        q = k // cnt
        temp *= q
        q = k - q*cnt
        temp += max(c_sum[1:min(q + 1, len(c_sum))])
        ans = max(ans, temp, max(c_sum[1:]))
print(ans)




    

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, k = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
c = [int(x) for x in input().split()]

ans = -float('inf')
for i in range(n):
    now = i
    c_sum = [0]
    s = set()
    cnt = 0
    while True:
        s.add(now)
        c_sum.append(c_sum[-1] + c[now])
        cnt += 1
        now = p[now]
        if now in s:
            break
    c_sum = c_sum[1:]
    if k < cnt:
        ans = max(ans, max(c_sum[: k]))
    else:
        score = c_sum[-1]
        count = k // cnt
        k_ = k - count*cnt
        score *= count
        score_2 = score - c_sum[-1]
        score_2 += max(c_sum)
        if k_ > 0:
            score += max(0, max(c_sum[:k_]))
        ans = max(ans, score, max(c_sum), score_2)
print(ans)
a,b =(int(i) for i in input.split())
if a > b:
 print("a > b")
elif  a == b:
 print("a == b")
else , 
 print("a < b")


### FIXED CODE ###

a,b =map(int, input().split())
if a > b:
 print("a > b")
elif  a == b:
 print("a == b")
else : 
 print("a < b")
n, t = input().split()
ret = 1001
for i in range(n):
  a, b = map(int, input().split())
  if b <= t:
    ret = min(a, ret)
    
if ret == 1001:
  print('TLE')
else:
  print(ret)

### FIXED CODE ###

n, t = map(int, input().split())
ret = 1001
for i in range(n):
  a, b = map(int, input().split())
  if b <= t:
    ret = min(a, ret)
    
if ret == 1001:
  print('TLE')
else:
  print(ret)
from itertools import accumulate
from collections import Counter
from math import ceil

n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))

a.sort(reverse=True)
acm = list(accumulate(a))
c = Counter(a)
c = list(c.values())
#print(c)
always_ok = a[p-1]
cnt = 0
j = 0
prev = -1

for i, e in enumerate(a):
    if e != prev:
        cnt += c[j]
        j += 1
        prev = e
    if e >= always_ok:
        continue

    if n - i + p - 1 >= v:
        if e + m >= always_ok:
            continue
        else:
            #print(i, e, "break")
            break

    cnt -= c[j-1]
    #print(i, e)
    left = v - (n - i + p - 1)
    #print(left)
    sm = acm[i-1] - acm[cnt-1]
    #print(sm)
    mx = max(a[p-1], ceil((sm + left * m) / (i - cnt + 1)))
    #print(mx)
    cnt += c[j-1]
    if mx > e + m:
        break

cnt = 0
for ae in a:
    if ae == e:
        break
    cnt += 1

print(cnt)


### FIXED CODE ###

n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))

a.sort(reverse=True)


def can_be_used(x):
    # x: 0-index
    if x < p:
        return True

    if a[x] + m < a[p-1]:
        return False

    vote_max = (p - 1 + n - x) * m
    for i in range(p-1, x):
        vote_max += a[x] + m - a[i]

    if vote_max < m * v:
        return False

    return True


l = 0
r = n

while r - l > 1:
    mid = (l + r) // 2

    if can_be_used(mid):
        l = mid
    else:
        r = mid

ans = l + 1
print(ans)
import sys
from operator import itemgetter
from itertools import permutations

def solve(a: list):
    length = len(a)
    if length <= 3:
        return min((p1[0]-p2[0])**2+(p1[1]-p2[1])**2 for p1, p2 in permutations(a, 2))

    x_set_len = len(set(x for (x, _) in a))
    axis = 0 if x_set_len > length/2 else 1
    a.sort(key=itemgetter(axis))
    mid_index = length//2
    left, right = a[:mid_index], a[mid_index:]
    delta = min(solve(left), solve(right))
    median = a[mid_index][axis]
    m_a = []
    append = m_a.append
        
    for p in left[::-1]:
        if p[axis] < median-delta:
            break
        append(p)
    for p in right:
        if p[axis] > median+delta:
            break
        append(p)
    m_a.sort(key=itemgetter(not axis))

    for i, p1 in enumerate(m_a):
        ub = p1[not axis] + delta
        for j, p2 in enumerate(m_a[i+1:]):
            if p2[not axis] > ub:
                break
            delta = min(delta, (p1[0]-p2[0])**2+(p1[1]-p2[1])**2)

    return delta

if __name__ == "__main__":
    N = int(input())
    a = [tuple(map(int, l.split())) for l in sys.stdin.readlines()]
    print(solve(a))


### FIXED CODE ###

import sys
from operator import itemgetter
from itertools import combinations, takewhile
from math import sqrt

def solve(a: list, sorted_axis: int = -1):
    length = len(a)
    if length <= 3:
        return min((x1-x2)**2+(y1-y2)**2 for (x1, y1), (x2, y2) in combinations(a, 2))

    x_set_len = len(set(x for x, _ in a))
    axis1 = 0 if x_set_len > length/2 else 1

    if sorted_axis != axis1:
        a.sort(key=itemgetter(axis1))

    mid_index = length//2
    left, right = a[:mid_index], a[mid_index:]
    delta = min(solve(left, axis1), solve(right, axis1))

    axis2 = not axis1
    median = a[mid_index][axis1]
    mid_a = sorted([p for _iter in (
        (takewhile(lambda p: median-sqrt(delta) < p[axis1], left[::-1])),
        (takewhile(lambda p: p[axis1] < median+sqrt(delta), right))
    ) for p in _iter], key=itemgetter(axis2))

    for i, (x1, y1) in enumerate(mid_a):
        ub = (x1 if axis1 else y1) + sqrt(delta)
        for x2, y2 in takewhile(lambda p: p[axis2] < ub, mid_a[i+1:]):
            delta = min(delta, (x1-x2)**2+(y1-y2)**2)

    return delta

if __name__ == "__main__":
    N = int(input())
    a = [tuple(map(int, l.split())) for l in sys.stdin.readlines()]
    print(solve(a))
N, T = [int(i) for i in input().split()]
ans = LTE
for i in range(N):
    c1, c2 = [int(j) for j in input().split()]

    if c2 <= T:
        ans = c1

print(ans)

### FIXED CODE ###

N, T = [int(i) for i in input().split()]
ans = 1500
for i in range(N):
    c1, c2 = [int(j) for j in input().split()]

    if c2 <= T:
        ans = min(c1,ans)

if ans == 1500:
    ans = "TLE"
print(ans)
n = input()
num = []
num = input().split(" ")

t = 0 
 a=0 
  while True: 
    num2=[] 
    for i in num: 
      if not (int(i)%2): 
        a =1 
        break 
        num2.append(int(i)%2) 
        num = num2 
        t+=1 
        if a==1: 
          print(t) 
          break 

### FIXED CODE ###

n = input()
num = []
num = input().split(" ")
 
t = 0 
a=0 
while True: 
  num2=[] 
  for i in num: 
    if not int(i)%2==0:
      a =1
      break
    num2.append(int(i)/2)
  num = num2
  if a==1: 
     print(t) 
     break
  t+=1
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
data = [0] * N
for _ in range(N):
    A,B = [int(x) for x in stdin.readline().rstrip().split()]
    data[_] = (A,B)
max_value = 0
diff = []
for j in range(0,N-1):
    for i in range(j+1,N):
        diff.append((data[j][0]-data[i][0],data[j][1]-data[i][1]))
    d=Counter(diff)
    #max_value = max(max_value,max(d.values()))
print(N-max(d.values()))

### FIXED CODE ###

from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
data = [0] * N
if N != 1:
    for _ in range(N):
        A,B = [int(x) for x in stdin.readline().rstrip().split()]
        data[_] = (A,B)
    data=sorted(data)
    max_value = 0
    diff = []
    for j in range(0,N-1):
        for i in range(j+1,N):
            diff.append((data[j][0]-data[i][0],data[j][1]-data[i][1]))
    d=Counter(diff)
        #max_value = max(max_value,max(d.values()))
    print(N-max(d.values()))
else:
    print(1)
N = int(''.join(input().split()))
sq = False
for k in range(1, N):
  sq |= k*k==N:
print('Yes' if sq else 'No')

### FIXED CODE ###

N = int(''.join(input().split()))
sq = False
for k in range(1, N):
  sq |= k*k==N
print('Yes' if sq else 'No')
N,W=map(int,input().split())
A = [list(map(int, input().split())) for i in range(N)]



max_sum = sum([i[1] for i in A])

max_value=1000001
dp = [[max_value for i in range(max_sum+1) ] for j in range(N+1)]
dp[0][0]=0

for i in range(N):
    for v in range(max_sum+1):
        if v>=A[i][1]:
            dp[i+1][v] = min([dp[i][v-A[i][1]]+A[i][0], dp[i][v]])

        else:
            dp[i+1][v] = dp[i][v]

#ここでindexは価値と同値、複数あることを考慮して反転後indexで最も価値のある個所を取得
print(max_sum-dp[N][::-1].index(W))
#     print(int(dp[N][W]))

### FIXED CODE ###

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



max_sum = sum([i[1] for i in A])

max_value=10**10
dp = [[max_value for i in range(max_sum+1) ] for j in range(N+1)]
dp[0][0]=0

for i in range(N):
    for v in range(max_sum+1):
        if v>=A[i][1]:
            dp[i+1][v] = min([dp[i][v-A[i][1]]+A[i][0], dp[i][v]])

        else:
            dp[i+1][v] = dp[i][v]

#ここでindexは価値と同値、複数あることを考慮して反転後indexで最も価値のある個所を取得
# try:
#     print(max_sum-dp[N][::-1].index(W))
# except:
#     print(max_sum-dp[N][::-1].index(W))
for i,w in enumerate(dp[N][::-1]):
    if w <=W:
        print(max_sum-i)
        break
#     print(int(dp[N][W]))
from itertools import combinations
import math
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n = int(readline())
m = map(float,read().split())
points = [[x, y] for x, y in zip(m, m)]


def center(a, b, c):
    M = pow(a[0], 2) - pow(b[0], 2) + pow(a[1], 2) - pow(b[1], 2)
    N = pow(a[0], 2) - pow(c[0], 2) + pow(a[1], 2) - pow(c[1], 2)
    Yab = a[1] - b[1]
    Xab = a[0] - b[0]
    Yac = a[1] - c[1]
    Xac = a[0] - c[0]
    d1 = Yac * Xab - Yab * Xac
    d2 = Xac * Yab - Xab * Yac
    if d1 == 0 or d2 == 0:
        return None
    x = (M * Yac - N * Yab) / (2 * d1)
    y = (M * Xac - N * Xab) / (2 * d2)
    return (x, y)


centers = []
for a, b, c in combinations(points, 3):
    cen = center(a, b, c)
    centers.append(cen)

for a, b in combinations(points, 2):
    cen = ((a[0]+b[0])/2,(a[1]+b[1])/2)
    centers.append(cen)

res = 1000
for cx, cy in centers:
    r = 0
    for x, y in points:
        tr = math.hypot(x - cx, y - cy)
        if tr > r:
            r = tr
    if r < res:
        res = r
print(res)


### FIXED CODE ###

from itertools import combinations
import math
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n = int(readline())
m = map(float,read().split())
points = [[x, y] for x, y in zip(m, m)]


def center(a, b, c):
    M = pow(a[0], 2) - pow(b[0], 2) + pow(a[1], 2) - pow(b[1], 2)
    N = pow(a[0], 2) - pow(c[0], 2) + pow(a[1], 2) - pow(c[1], 2)
    Yab = a[1] - b[1]
    Xab = a[0] - b[0]
    Yac = a[1] - c[1]
    Xac = a[0] - c[0]
    d1 = Yac * Xab - Yab * Xac
    d2 = Xac * Yab - Xab * Yac
    if d1 == 0 or d2 == 0:
        return None
    x = (M * Yac - N * Yab) / (2 * d1)
    y = (M * Xac - N * Xab) / (2 * d2)
    return (x, y)


centers = []
for a, b, c in combinations(points, 3):
    cen = center(a, b, c)
    if cen is None:
      continue
    centers.append(cen)

for a, b in combinations(points, 2):
    cen = ((a[0]+b[0])/2,(a[1]+b[1])/2)
    centers.append(cen)

res = 1000
for cx, cy in centers:
    r = 0
    for x, y in points:
        tr = math.hypot(x - cx, y - cy)
        if tr > r:
            r = tr
    if r < res:
        res = r
print(res)
n, u, v = map(int, input().split())

# nodeの値を-1しておく
u = u-1
v = v-1

# Making Adjacency list
Adj_dict = {}
for i in range(n):
    new = {i: []}
    Adj_dict.update(new)

for _ in range(n-1):
    a, b = map(int, input().split())
    Adj_dict[a-1].append(b-1)
    Adj_dict[b-1].append(a-1)

def tree_distance(Adj_dict, start, Visited, distance, Dist_list):
    
    if Visited[start] == True:
        return
    
    # 現在いる位置を Visited = True に変更する
    Visited[start] = True

    # 該当するnodeの距離を記録して、distanceを1加算する
    Dist_list[start] = distance
    distance += 1

    # 訪れていないnodeに対して、dfs
    for node in Adj_dict[start]:
        if Visited[node] == False:
            tree_distance(Adj_dict, node, Visited, distance, Dist_list)
    
    return


Dist_list = [0 for _ in range(n)]
Visited = [False for _ in range(n)]
distance = 0
tree_distance(Adj_dict, u, Visited, distance, Dist_list)
Taka = Dist_list

Dist_list = [0 for _ in range(n)]
Visited = [False for _ in range(n)]
distance = 0
tree_distance(Adj_dict, v, Visited, distance, Dist_list)
Aoki = Dist_list

Taka_num = 0
node = 0
for i in range(n):
    if Aoki[i] >= Taka[i]:
        if Taka[i] >= Taka_num:
            Taka_num = Taka[i]
            node = i

# TakahashiはTaka_numのnodeへ逃げる
ans = Aoki[node] -1

print(ans)

### FIXED CODE ###

import sys

sys.setrecursionlimit(200000)

n, u, v = map(int, input().split())

# nodeの値を-1しておく
u = u-1
v = v-1

# Making Adjacency list
Adj_dict = {}
for i in range(n):
    new = {i: []}
    Adj_dict.update(new)

for _ in range(n-1):
    a, b = map(int, input().split())
    Adj_dict[a-1].append(b-1)
    Adj_dict[b-1].append(a-1)

def tree_distance(Adj_dict, start, Visited, distance, Dist_list):
    
    # 現在いる位置を Visited = True に変更する
    Visited[start] = True

    # 該当するnodeの距離を記録して、distanceを1加算する
    Dist_list[start] = distance
    distance += 1

    # 訪れていないnodeに対して、dfs
    for node in Adj_dict[start]:
        if Visited[node] == False:
            tree_distance(Adj_dict, node, Visited, distance, Dist_list)
    
    return


Dist_list = [0 for _ in range(n)]
Visited = [False for _ in range(n)]
distance = 0
tree_distance(Adj_dict, u, Visited, distance, Dist_list)
Taka = Dist_list

Dist_list = [0 for _ in range(n)]
Visited = [False for _ in range(n)]
distance = 0
tree_distance(Adj_dict, v, Visited, distance, Dist_list)
Aoki = Dist_list

Taka_num = 0
node = 0
ans = 0
for i in range(n):
    if Aoki[i] > Taka[i]:
        ans = max(ans, Aoki[i]-1)


print(ans)
a,b,c=[int(x) for x in input().split()]
if  b−a==c−b:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

a,b,c=[int(x) for x in input().split()]
if  b-a==c-b:
    print("YES")
else:
    print("NO")
a = input()
b = input()
t = input()

print(int((t+0.5)/a)*b)

### FIXED CODE ###

a,b,t=map(int,input().split())

print(int((t+0.5)/a)*b)
import bisect
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
sum_L = sum(L)
N_neg = bisect.bisect_left(L, 0)
process = []
if N_neg == 0:  # minのみ-にする
    ans = sum_L-min(L)*2
    l = min(L)
    for r in L[1:-1]:
        process.append(str(l)+" "+str(r))
        l -= r
    process.append(str(L[-1])+" "+str(l))
elif N_neg == N:  # maxのみを+にする
    ans = -sum_L(L)+max(L)*2
    l = L[-1]
    for r in reversed(L[:-1]):
        process.append(str(l)+" "+str(r))
        l -= r
else:  # negのやつを-にする
    ans = sum([abs(v) for v in L])
    l = L[0]
    for r in L[N_neg:-1]:
        process.append(str(l)+" "+str(r))
        l -= r
    process.append(str(L[-1])+" "+str(l))
    l = L[-1]-l
    for r in L[1:N_neg]:
        process.append(str(l)+" "+str(r))
        l -= r
print(ans)
print("\n".join(process))


### FIXED CODE ###

import bisect
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
sum_L = sum(L)
N_neg = bisect.bisect_left(L, 0)
process = []
if N_neg == 0:  # minのみ-にする
    ans = sum_L-min(L)*2
    l = min(L)
    for r in L[1:-1]:
        process.append(str(l)+" "+str(r))
        l -= r
    process.append(str(L[-1])+" "+str(l))
elif N_neg == N:  # maxのみを+にする
    ans = -sum_L+max(L)*2
    l = L[-1]
    for r in reversed(L[:-1]):
        process.append(str(l)+" "+str(r))
        l -= r
else:  # negのやつを-にする
    ans = sum([abs(v) for v in L])
    l = L[0]
    for r in L[N_neg:-1]:
        process.append(str(l)+" "+str(r))
        l -= r
    process.append(str(L[-1])+" "+str(l))
    l = L[-1]-l
    for r in L[1:N_neg]:
        process.append(str(l)+" "+str(r))
        l -= r
print(ans)
print("\n".join(process))
a = int(input())
b = int(input())
c = int(input())
x = int(input())
nb = 0

for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      (x - 500*i - 100*j - 50*k) == 0:
      nb += 1
print(nb)
      

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
x = int(input())
nb = 0

for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if (x - 500*i - 100*j - 50*k) == 0:
        nb += 1
print(nb)
import array


n = int(input())
a=[]
f=0
f1=0
b=0
for i in range(0,n):
    i = int(input())
    a.append(i)
    if i == 0:
        print("0");
        f1=1
        

sum =1
if f1==0:
    for i in a:
        sum=sum*i;
        if sum>1e18:
            f=1
            print("-1");
    
if f==0:
    print(sum)

### FIXED CODE ###

import array


n = int(input())
a=[]
a=input().split(" ")
f=0
f1=0
b=0
for i in a:
    if int(i) == 0:
        print("0")
        f1=1
        break
        

sum =1
if f1==0:
    for i in a:
        sum=sum*int(i)
        if sum>1e18:
            f=1
            print("-1")
            break
    


if f==0 and f1==0:
    print(sum)
from collections import deque

n,m,*ab = map(int, open(0).read().split())
to = [[] for _ in range(m+1)]

for i in range(0, m*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].append(b)
    to[b].append(a)

ans = [None for _ in range(n+1)]
q = deque([1])
while q:
    p = q.pop()
    for i in to[p]:
        if ans[i] is None:
            ans[i] = p
            q.appendleft(i)

print("Yes")
print("\n".join(map(str, ans[2:])))


### FIXED CODE ###

from collections import deque
n,m,*ab = map(int, open(0).read().split())

to = [[] for _ in range(n+1)]
ans = [None] * (n+1)
for i in range(0, m*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].append(b)
    to[b].append(a)

q = deque([1])
while q:
    p = q.pop()
    children = to[p]
    for child in children:
        if ans[child] is None:
            ans[child] = p
            q.appendleft(child)

print("Yes")
print("\n".join(map(str, ans[2:])))
n=input()
sum=1
f=0
f2=0
for i in range(0,n):
	a=input()
	if  (a==0): 
		f2=1
	sum=sum*a
	if (sum>1000000000000000000):
		f=1;
}
if (f2==1): 
	print("0\n")
else if(f==1):
	print("-1\n")
else:
	print(sum)
	print("\n")

### FIXED CODE ###

N=int(input())
 
A=list(map(int,input().split()))
 
if 0 in A:
    print(0)
else:
    result=1
    for a in A:
        result=result*a
        if result>10**18:
            result=-1
            break
    print(result)
D = int(input())

if D = 25:
  print('Christmas')
elif D = 24:
  print('Christmas Eve')
elif D = 23:
  print('Christmas Eve Eve')
else:
  print('Christmas Eve Eve Eve')

### FIXED CODE ###

D = int(input())

if D == 25:
  print('Christmas')
elif D == 24:
  print('Christmas Eve')
elif D == 23:
  print('Christmas Eve Eve')
else:
  print('Christmas Eve Eve Eve')
def main():
  name = input()
  print name
	
  
  
  
if __name__ == '__main__'
	main()

### FIXED CODE ###

name = input('')
print(name[:3])
#!/usr/local/bin/python3
# coding: utf-8

ha = input()
kita = ha.split(" ")
x = int(kita[0])
y = int(kita[1])
ifAshi = False

for i in range(x):
    if(x = 1):
        if(y == 2 or y == 4):
            ifAshi = True
    if((y - 2*i)%4 == 0):
        if((x-i) == ((y - 2*i)/4)):
            ifAshi = True

if(ifAshi):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

#!/usr/local/bin/python3
# coding: utf-8

ha = input()
kita = ha.split(" ")
x = int(kita[0])
y = int(kita[1])
ifAshi = False

if(x == 1):
    if(y == 2 or y == 4):
        ifAshi = True
if(x*2 == y):
    ifAshi = True
for i in range(x):
        
    if((y - 2*i)%4 == 0):
        if((x-i) == ((y - 2*i)/4)):
            ifAshi = True

if(ifAshi):
    print("Yes")
else:
    print("No")
import sys

N , M = map(int , input().split())
voyages = []
for i in range(M):
    voyages.append(list(map(int , input().split())))

def search(goal, path):
    n = path[len(path) - 1]
    if n == goal - 1:
        if len(path) < 4:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")
        sys.exit()
        
    else:
        if n <= len(voyages):
            for x in voyages[n]:
                if x not in path:
                    path.append(x)
                    search(goal, path)
                    path.pop()
        else:
            print("IMPOSSIBLE")
            sys.exit()
            

if len(voyages) == 1:
    if not (N in voyages[0]):
        print("IMPOSSIBLE")
else:
    search(N, [0])

### FIXED CODE ###

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(M)]

toN = list(filter(lambda x: N in x, AB))
toN = set([flatten for inner in toN for flatten in inner])
frm_first = list(filter(lambda x: 1 in x, AB))
frm_first = set([flatten for inner in frm_first for flatten in inner])

if toN & frm_first:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
s=[]
s.append("".join("#" for _ in range(W+2)))
cnt=0
for i in range(H):
    ss=input().strip()
    s.append("#"+ss+"#")
    for w in range(W):
        if ss[w]==".":
            cnt+=1

s.append("".join("#" for _ in range(W+2)))
#print(s)

def solv(h,w,cnt):
    #print(h,w)
    #print(a)
    #print(s)
    if a[h][w]>cnt+1 and s[h][w]==".":
        a[h][w]=cnt+1
        solv(h-1,w,cnt+1)
        solv(h,w-1,cnt+1)
        solv(h+1,w,cnt+1)
        solv(h,w+1,cnt+1)

a=[[1000000]*(W+2) for _ in range(H+2)]
solv(1,1,0)
print(cnt-a[-2][-2] if a[-2][-2]!= 1000000 else -1)


### FIXED CODE ###

import sys
input = sys.stdin.readline
H,W=map(int,input().split())
s=[]
s.append("".join("#" for _ in range(W+2)))
cnt=0
for i in range(H):
    ss=input().strip()
    s.append("#"+ss+"#")
    for w in range(W):
        if ss[w]==".":
            cnt+=1

s.append("".join("#" for _ in range(W+2)))
#print(s)
import sys
sys.setrecursionlimit(300000)
def solv(h,w,cnt):
    #print(h,w)
    #print(a)
    #print(s)
    if a[h][w]>cnt+1 and s[h][w]==".":
        a[h][w]=cnt+1
        solv(h-1,w,cnt+1)
        solv(h,w-1,cnt+1)
        solv(h+1,w,cnt+1)
        solv(h,w+1,cnt+1)
    return

a=[[1000000]*(W+2) for _ in range(H+2)]
solv(1,1,0)
print(cnt-a[-2][-2] if a[-2][-2]!= 1000000 else -1)
s = input()

while s != []:
  if s=='erase':
    s = s[]
  elif len(s)>5 and s[0:5]=='erasee':
    s = s[5:]
  elif len(s)>5 and s[0:5]=='erased':
    s = s[5:]
  elif s=='eraser':
    s = s[]
  elif len(s)>6 and s[0:6]=='erasere':
	s = s[6:]
  elif len(s)>6 and s[0:6]=='eraserd':
	s = s[6:]
  elif s=='dreamer':
    s = []
  elif len(s)>7 and s[0:7]='dreamere':
    s = s[7:]
  elif len(s)>7 and s[0:7]='dreamerd':
    s = s[7:]
  elif s='dream':
    s = s[]
  elif len(s)>5 and s[0:5]='dreamd':
    s = s[6:]
  print(s)
    
# dream dreamer erase eraser


### FIXED CODE ###

s = input()

flag = 0
while s != []:
  ss=s
  if s=='erase':
    s = []
  elif len(s)>5 and s[0:6]=='erasee':
    s = s[5:]
  elif len(s)>5 and s[0:6]=='erased':
    s = s[5:]
  elif s=='eraser':
    s = []
  elif len(s)>6 and s[0:7]=='erasere':
    s = s[6:]
  elif len(s)>6 and s[0:7]=='eraserd':
    s = s[6:]
  elif s=='dreamer':
    s = []
  elif len(s)>7 and s[0:8]=='dreamere':
    s = s[7:]
  elif len(s)>7 and s[0:8]=='dreamerd':
    s = s[7:]
  elif s=='dream':
    s = []
  elif len(s)>5 and s[0:6]=='dreamd':
    s = s[5:]
  elif len(s)>5 and s[0:6]=='dreame':
    s = s[5:]

  if ss==s:
    flag=1
    break

if flag==0:
  print("YES")
else:
  print("NO")
    
# dream dreamer erase eraser