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

from collections import deque

h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
slist = [input() for i in range(h)]

que = deque()
que.append([ch - 1, cw - 1, 0])
memo = {}
memo[(ch - 1, cw - 1)] = 0
ans = float("inf")
while len(que) != 0:
    sh, sw, count = que.popleft()
    #print(sh, sw, count)
    if sh == dh - 1 and sw == dw - 1:
        if ans > count:
            memo[(sh, sw)] = count
            ans = count
        continue
    for ph, pw in [[-1, 0], [1, 0], [0, 1], [0, -1]]:
        if 0 <= sh + ph < h and 0 <= sw + pw < w:
            if (sh + ph, sw + pw) in memo and memo[(sh + ph, sw + pw)] <= count:
                continue
            if slist[sh + ph][sw + pw] == ".":
                que.append([sh + ph, sw + pw, count])
                memo[(sh + ph, sw + pw)] = count

    for ph in range(-2, 3):
        for pw in range(-2, 3):
            if [ph, pw] not in [[-1, 0], [1, 0], [0, 1], [0, -1]]:
                if 0 <= sh + ph < h and 0 <= sw + pw < w:
                    if (sh + ph, sw + pw) in memo and memo[(sh + ph, sw + pw)] <= count + 1:
                        continue
                    if slist[sh + ph][sw + pw] == ".":
                        que.append([sh + ph, sw + pw, count + 1])
                        memo[(sh + ph, sw + pw)] = count + 1

if ans == float("inf"):
    print(-1)
else:
    print(ans)

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
slist = [input() for i in range(h)]

if ch == dh and dw == cw:
    print(0)
    exit()

que = deque()
memo_que = deque()
que.append([ch - 1, cw - 1, 0])
memo = [[False for i in range(w)] for j in range(h)]
memo[ch - 1][cw - 1] = True

while len(que) != 0:
    # 幅たん
    while len(que) != 0:
        sh, sw, count = que.popleft()
        memo_que.append([sh, sw, count])
        #print(sh, sw, count)
        for ph, pw in [[-1, 0], [1, 0], [0, 1], [0, -1]]:
            if 0 <= sh + ph < h and 0 <= sw + pw < w:
                if sh + ph == dh - 1 and sw + pw == dw - 1:
                    print(count)
                    exit()
                if memo[ph + sh][pw + sw]:
                    continue
                if slist[sh + ph][sw + pw] == ".":
                    que.append([sh + ph, sw + pw, count])
                    memo[ph + sh][pw + sw] = True
                    memo_que.append([sh + ph, sw + pw, count])

    for sh, sw, count in memo_que:
        #print("w", sh, sw, count)
        for ph in range(-2, 3):
            for pw in range(-2, 3):
                if 0 <= sh + ph < h and 0 <= sw + pw < w:
                    if sh + ph == dh - 1 and sw + pw == dw - 1:
                        print(count + 1)
                        exit()
                    if memo[ph + sh][pw + sw]:
                        continue
                    if slist[sh + ph][sw + pw] == ".":
                        que.append([sh + ph, sw + pw, count + 1])
                        memo[ph + sh][pw + sw] = True
    memo_que.clear()
print(-1)
### BUGGY CODE ###

N, Y = map(int, input().split())

for i in range(Y // 10000 + 1):
    for j in range(Y // 5000 + 1):
        for k in range(Y // 1000 + 1):
            if i+j+k == N:
                if i*10000 + j*5000 + k*1000 == Y:
                    print(i, j, k)
                    exit()
                
print(-1, -1, -1)

### FIXED CODE ###

N, Y = map(int, input().split())

for i in range(Y // 10000 + 1):
    for j in range((Y - i*10000) // 5000 + 1):
        remain_money = (Y - i*10000 - j*5000)
        k = remain_money // 1000
        if remain_money % 1000 == 0 and i+j+k == N:
            print(i, j, k)
            exit()
        else:
            pass
                
print(-1, -1, -1)
### BUGGY CODE ###

N = int(input())
P = list(map(float, input().split()))

dp = [[0] * (N+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(1, N+1):
  for j in range(i+1):
    dp[i][j] = dp[i-1][j] * (1 - P[i-1]) + (dp[i-1][j-1] if j > 0 else 0) * P[i-1]
print(sum(dp[N][N//2+1:]))

### FIXED CODE ###

N = int(input())
P = list(map(float, input().split()))

dp = [[0] * (N+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(1, N+1):
  for j in range(i+1):
    dp[i][j] = dp[i-1][j] * (1 - P[i-1]) + (dp[i-1][j-1] if j > 0 else 0) * P[i-1]
print(sum(dp[N][N//2+1:]))
### BUGGY CODE ###

from collections import deque
n = int(input())
Ps = list(map(lambda x: int(x)-1, input().split()))
cost = [min(i, n-1-i, j, n-1-j) for i in range(n) for j in range(n)]
exist = [1]*(n**2)


def to_idx(p):
    return divmod(p, n)


def to_v(i, j):
    return i*n+j


def generate_v2(v, i, j):
    if 0 < i:
        yield v-n
    if i < n-1:
        yield v+n
    if 0 < j:
        yield v-1
    if j < n-1:
        yield v+1


def bfs(init_v):
    next_v = deque([init_v])
    exist[init_v] = 0
    while next_v:
        v = next_v.popleft()
        i, j = to_idx(v)
        for v2 in generate_v2(v, i, j):
            if cost[v2] <= cost[v]+exist[v]:
                continue
            cost[v2] = cost[v]+exist[v]
            next_v.append(v2)

ans = 0
for p in Ps:
    ans += cost[p]
    bfs(p)
print(ans)

### FIXED CODE ###

from collections import deque
n = int(input())
Ps = list(map(lambda x: int(x)-1, input().split()))
cost = [min(i, n-1-i, j, n-1-j) for i in range(n) for j in range(n)]
exist = [1]*(n**2)


def to_idx(p):
    return divmod(p, n)


def to_v(i, j):
    return i*n+j


def bfs(init_v):
    next_v = deque([init_v])
    exist[init_v] = 0
    while next_v:
        v = next_v.popleft()
        i, j = to_idx(v)
        if 0 < i:
            v2 = v-n
            if cost[v2] > cost[v]+exist[v]:
                cost[v2] = cost[v]+exist[v]
                next_v.append(v2)

        if i < n-1:
            v2 = v+n
            if cost[v2] > cost[v]+exist[v]:
                cost[v2] = cost[v]+exist[v]
                next_v.append(v2)

        if 0 < j:
            v2 = v-1
            if cost[v2] > cost[v]+exist[v]:
                cost[v2] = cost[v]+exist[v]
                next_v.append(v2)

        if j < n-1:
            v2 = v+1
            if cost[v2] > cost[v]+exist[v]:
                cost[v2] = cost[v]+exist[v]
                next_v.append(v2)

ans = 0
for p in Ps:
    ans += cost[p]
    bfs(p)
print(ans)
### BUGGY CODE ###

from collections import Counter
from itertools import product

N = int(input())
S = input().strip()
dic = Counter(S)
mod = 10**9 + 7

ans = 0
ls =list(product([0, 1], repeat=len(dic)))
ls.pop(0)

for x in ls:
    num = 1
    for z, y in zip(dic, x):
        if y == 1:
            num = (dic[z]*num)%mod
    ans = (ans+num)%mod
print(ans)

### FIXED CODE ###

from collections import Counter
from itertools import product
 
N = int(input())
S = input().strip()
dic = Counter(S)
mod = 10**9 + 7

ans = 1
for x in dic:
    ans = ans*(dic[x]+1)%mod
print(ans-1)
### BUGGY CODE ###

N = int(input())
#S = [input() for i in range(N)]
S=[]
firstalpha=[]
ans_list = []
temp_ans = 1
ans = 0

for i in range(N):
    temp = sorted(list(input()))
    S.append(''.join(temp))
    #firstalpha.append(temp[0])
    
set_S = set(S)

for s in set_S:
    ans_list.append(S.count(s))

for a in ans_list:
    ans += a*(a-1)/2

print(round(ans))

### FIXED CODE ###

N = int(input())
#S = [input() for i in range(N)]
S=[]
ans_dic={}
temp_ans = 1
ans = 0

for i in range(N):
    temp = sorted(list(input()))
    temp = ''.join(temp)
    #S.append(''.join(temp))
    #alpha_dic[temp[0]].append(i) 
    if temp in ans_dic:
        ans_dic[temp] += 1
    else:
        ans_dic[temp] = 1
    
for key,value in ans_dic.items():
    ans += value*(value-1)/2

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

from sys import stdin
import numpy as np

n,w = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
li = np.array(li)

def knapsack(n,w,li):
    #li[i][0]が重さ,li[i][1]が価値
    dp = np.zeros((n+1,w+1))
    #dp[i][total_w]はi-1回目までの商品を加えた時に重さがtotal_wを超えないような値の最大値
    for i in range(n):
        for total_w in range(li[i][0]-1,w+1):
            if total_w - li[i][0] >= 0:
                dp[i+1][total_w] = max(dp[i][total_w],dp[i][total_w-li[i][0]]+li[i][1])
            else:
                dp[i+1][total_w] = dp[i][total_w]
    return int(dp[-1][-1])
print(knapsack(n,w,li))

### FIXED CODE ###

from sys import stdin
n,w = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
def knapsack(n,w,li):
    #li[i][0]が重さ,li[i][1]が価値
    dp = [[0 for i in range(w+1)]for j in range(n+1)]
    #dp[i][total_w]はi-1回目までの商品を加えた時に重さがtotal_wを超えないような値の最大値
    for i in range(n):
        for total_w in range(w+1):
            if total_w - li[i][0] >= 0:
                dp[i+1][total_w] = max(dp[i][total_w],dp[i][total_w-li[i][0]]+li[i][1])
            else:
                dp[i+1][total_w] = dp[i][total_w]
    return max(dp[-1])
print(knapsack(n,w,li))
### BUGGY CODE ###

a,b,x = map(int,input().split())
n = 0
for i in range(a,b+1):
  if i % x == 0:
    n += 1
  else:
    pass
print(n)

### FIXED CODE ###

import math
a,b,x = map(int,input().split())
def f(p):
  if p >= 0:
    return p//x + 1
  else:
    return 0
print(f(b)-f(a-1))
### BUGGY CODE ###

N,M = map(int,input().split())
ans = 0
while N > 0 and M > 0:
  N -= 1
  M -= 2
  ans += 1
print(ans + M // 4)

### FIXED CODE ###

N,M = map(int,input().split())
ans = 0
if N > M // 2:
  print(M // 2)
  exit()
print(N + (M - N * 2) // 4)
### BUGGY CODE ###

import sys
from collections import Counter

input = sys.stdin.readline

N = int(input())
l = []
for _ in range(N):
    l.append(input().strip())

c = Counter(l)

for k, v in sorted(c.items(), key=lambda x: x[0]):
    if v == max(c.values()):
        print(k)


### FIXED CODE ###

import sys
from collections import Counter

input = sys.stdin.readline

N = int(input())
l = []
for _ in range(N):
    l.append(input().strip())

c = Counter(l)
m = max(c.values())
c2 = [k for k, v in c.items() if v == m]

for x in sorted(c2):
    print(x)
### BUGGY CODE ###

S = list(input())
N = int(input())
for i in range(N):
    A = list(input().split())
    if int(A[0]) == 1:
        S.reverse()
    elif int(A[1]) == 1:
        S.insert(0,A[2])
    else:
        S.append(A[2])
print(''.join(S))

### FIXED CODE ###

S = input()
Q = int(input())
flg = 0
senntou = ''
ushiro = ''
for i in range(Q):
    A = list(input().split())
    if int(A[0]) == 1 and flg == 0:
        flg = 1
        continue
    elif int(A[0]) == 1 and flg == 1:
        flg = 0
        continue
    if (int(A[1]) == 1 and flg == 0) or (int(A[1]) == 2 and flg == 1):
        senntou = A[2] + senntou
    else:
        ushiro = ushiro + A[2]
if flg == 0:
    print(senntou + S + ushiro)
if flg == 1:
    print(ushiro[::-1] + S[::-1] + senntou[::-1])
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline
N = int(input())
D = [deque([]) for _ in range(N)]
MAP = [[0] * N for n in range(N)]
maxi = -1
AB = [0] * (N-1)
for n in range(N-1):
    a, b = [int(x) for x in input().strip().split()]
    AB[n] = (a, b)
    D[a-1].append(b-1)
    D[b-1].append(a-1)

maxc = 0

for i, d in enumerate(D):
    c = len(d)
    if c > maxc:
        maxc = c
        maxi = i

C = [[0] * maxc for _ in range(N)]
for n in D[maxi]:
    #print('max index = {}, next node = {}'.format(maxi, n))
    MAP[maxi][n] = c
    MAP[n][maxi] = c
    C[maxi][c-1] = 1
    C[n][c-1] = 1
    c += 1

print(maxc)
for a, b in AB:
    if a-1 == maxi or b-1 == maxi:
        print(MAP[a-1][b-1])
    for i in range(maxc):
        if C[a-1][i] == 0 and C[b-1][i] == 0:
            print(i+1)
            C[a-1][i] = 1
            C[b-1][i] = 1
            break

### FIXED CODE ###

import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(100000)
N = int(input())
D = [deque([]) for _ in range(N)]
cnt = 0
AB = [0] * (N-1)
dic = {}
for n in range(N-1):
    a, b = [int(x) for x in input().strip().split()]
    AB[n] = (a-1, b-1)
    dic[(a, b)] = 0
    D[a-1].append(b-1)
    D[b-1].append(a-1)

print(max([len(d) for d in D]))

def dp(pp, p, c):
    global dic
    nc = 1
    for np in D[p]:
        if np == pp:
            continue
        if nc == c:
            nc += 1
        dic[(p, np)] = nc
        dp(p, np, nc)
        nc += 1
    return 0

dp(-1, 0, 0)
for ab in AB:
    print(dic[ab])
### BUGGY CODE ###

a=int(input())
print(sum(range(1,a+1))-a)



### FIXED CODE ###

a=int(input())
print(a*(a+1)//2-a)
### BUGGY CODE ###

S = input()
L = len(S)
ans = 0
C = [0] * (L+1)
A = [0] * 2020
A[0] = 1
for i in range(L-1, -1, -1):
    C[i] = (int(S[i]) * 10**(L-1-i) % 2019 + C[i+1])%2019
    A[C[i]] += 1

for i in A:
    ans += int(i * (i-1) / 2)

print(ans)

### FIXED CODE ###

p=d=2019
z=[0]*p
for i,j in enumerate(input()[::-1]):
	d=d+int(j)*pow(10,i,p)
	z[d%p]+=1
r=z[0]
for i in z:
	r+=i*(i-1)//2
print(r)
### BUGGY CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))
ans=0
for i in range(n):
    p[i] = (p[i]+1)*(p[i]/2)/p[i]
for j in range(n-k+1):
    ans = max(ans,sum(p[j:j+k]))
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))
s=[(1+i)/2 for i in range(1,1001)]
l=[0,s[p[0]-1]]
for i in range(1,n):
    l.append(l[-1]+s[p[i]-1])
ans=0
for j in range(n-k+1):
    ans=max(ans,l[j+k]-l[j])
print(ans)
### BUGGY CODE ###

import sys

input = sys.stdin.readline

n = int(input())
sl = input()
q = int(input())
kl = tuple(map(int,input().split()))

for k in kl:
    # i文字目までのdとmとdmの数

    d = m = dm = ans = 0
    for i in range(n):
        if i - k >= 0:
            if sl[i-k] == "D":
                d -= 1
                dm -= m
            if sl[i-k] == "M":
                m -= 1
        if sl[i] == "D":
            d += 1
        if sl[i] == "M":
            m += 1
            dm += d
        if sl[i] == "C":
            ans += dm

    print(ans)









### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = input()
    Q = int(input())
    x = tuple(map(int,input().split()))
    for k in x:
        d,m,dm,dmc = 0,0,0,0
        for i in range(N):
            if S[i] == "D":
                d += 1
            elif S[i] == "M":
                m += 1
                dm += d
            elif S[i] == "C":
                dmc += dm
            if i >= k-1:
                if S[i-k+1] == "D":
                    dm -= m
                    d -= 1
                elif S[i-k+1] == "M":
                    m -= 1
        print(dmc)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

def main():
    from sys import stdin
    import numpy as np
    input = stdin.readline
    k, q = map(int, input().split())
    d = np.array(list(map(int, input().split())), dtype=np.int64)
    nxm = [list(map(int, input().split())) for _ in [0]*q]
    for n, x, m in nxm:
        d2 = (d-1) % m+1
        print(n-1-(x % m+sum(d2)*((n-2)//k)+sum(d2[:(n-2) % k+1]))//m)


main()

### FIXED CODE ###

def main():
    k, q = map(int, input().split())
    d = list(map(int, input().split()))
    nxm = [list(map(int, input().split())) for _ in [0]*q]
    for n, x, m in nxm:
        d2 = sum([(i-1) % m+1 for i in d[:(n-2) % k+1]])
        d3 = sum([(i-1) % m+1 for i in d[(n-2) % k+1:]])
        print(n-1-(x % m+(d2+d3)*((n-2)//k)+d2)//m)


main()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
def find_root(edges, edges_root, root, group, before, now):
    group.add(now)
    edges_root[now] = root
    children = set(edges[now]) - group
    for child in children:
        if child != before:
            root, edges_root, group = find_root(edges, edges_root, root, group, now, child)
    return root, edges_root, group
    
if __name__ == '__main__':
    N, K, L = map(int, input().split())
    roads = [[] for _ in range(N)]
    rails = [[] for _ in range(N)]
    road_roots = [None]*N
    rail_roots = [None]*N
    answer = [1]*N
        
    for i in range(K):
        p, q = map(int, input().split())
        p -= 1
        q -= 1
        roads[p].append(q)
        roads[q].append(p)
    
    for i in range(L):
        r, s = map(int, input().split())
        r -= 1
        s -= 1
        rails[r].append(s)
        rails[s].append(r)
    
    for i, r in enumerate(road_roots):
        if r is None:
            root, road_roots, group = find_root(roads,road_roots, i, set(), -1, i)


    for i, r in enumerate(rail_roots):
        if r is None:
            root, rail_roots, group = find_root(rails,rail_roots, i, set(), -1, i)

                
    railroads=[[rail, road] for rail, road in zip(road_roots, rail_roots)]

    for n in range(N):
        for d in range(1, N-n):
            if railroads[n] == railroads[n+d]:
                answer[n] += 1 
                answer[n+d] += 1
                
    print(' '.join(list(map(str, answer))))

### FIXED CODE ###

from collections import defaultdict
def build_tree(N, edges):
    root_list = [i for i in range(N)]
    for p, q in edges:
        p -= 1
        q -= 1
        root_p = get_root(root_list, p)
        root_q = get_root(root_list, q)
        root_now = min(root_p, root_q, p)
        root_list[p] = root_now
        root_list[q] = root_now
        root_list[root_p] = root_now
        root_list[root_q] = root_now
    return root_list

def get_root(root_list, city):
    if root_list[city] == city:
        return city
    else: 
        root_list[city] = get_root(root_list, root_list[city])
        return root_list[city]

if __name__ == '__main__':
    N, K, L = map(int, input().split())
    roads = [None]*K
    rails = [None]*L
    for k in range(K):
        roads[k] = list(map(int, input().split()))
    for l in range(L):
        rails[l] = list(map(int, input().split()))
    
    
    '''N = 2*10**5
    L = int(N/2)
    K = int(N/2)
    roads = [None]*K
    rails = [None]*L
    for i in range(L):
        roads[i] = [2*i, 2*i+1]
    for i in range(K):
        rails[i] = [2*i, 2*i+1]'''
    
    road_roots = build_tree(N, roads)
    rail_roots = build_tree(N, rails)
    
    railroads = defaultdict(int)
    RR = []
    for n in range(N):
        rr = (get_root(road_roots, n), get_root(rail_roots, n))
        RR.append(rr)
        railroads[rr] += 1
    answer = [railroads[key] for key in RR]
    print(' '.join(map(str, answer)))
### BUGGY CODE ###


n, m = map(int, input().split())
ai = list(map(int, input().split()))

#print(ai)
#ais = sorted(ai, reverse=True)
ais = sorted(ai)
#print(ais)

bc = []
for i in range(m):
    bc.append(list(map(int, input().split())))

#print(bc)
bcs = sorted(bc, reverse=True, key=lambda x:x[1])
#print(bcs)

pt = 0
for i in range(m):
    tn, tv =bcs[i]
    for j in range(pt,n):
        if ais[j] < tv and 0<tn:
            ais[j]=tv
            tn=tn-1
            pt=j

#print(ais)
print(sum(ais))

### FIXED CODE ###


n, m = map(int, input().split())
ai = list(map(int, input().split()))

#print(ai)
#ais = sorted(ai, reverse=True)
ais = sorted(ai)
#print(ais)
dica={}
for i in range(len(ais)):
    dica.setdefault(i,ais[i])
#print(dica)

bc = []
for i in range(m):
    bc.append(list(map(int, input().split())))

#print(bc)
bcs = sorted(bc, reverse=True, key=lambda x:x[1])
#print(bcs)

pt = 0
for i in range(m):
    tn, tv =bcs[i]
    #print(pt, n)
    #print(dica)
    for j in range(pt,n):
        if dica[j] < tv and 0 < tn:
            dica[j]=tv
            tn=tn-1
            pt=j+1
        else:
            break

#print(ais)
print(sum(dica.values()))
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
for i in a:
    for j in a:
        ans += i ^ j
print(ans // 2 % mod)

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
mod = (10 ** 9) + 7
max_a = max(a)
ans = 0
for j in range(len(bin(max(a))) - 2):
    t = sum([1 & i for i in a]) 
    ans += (2 ** j) * t * (n - t)
    a = [i >> 1 for i in a]
    ans = ans % mod
print(ans)
### BUGGY CODE ###

s = str( input() )
q = int( input() )
query = []
rev_flag_k = 0
for _ in range( q ):
    query_i = list( input().split() )
    query.append( query_i )
    if query_i[ 0 ] == "1":
        rev_flag_k += 1

rev_flag = 0
for query_i in query:
    t = query_i[ 0 ]
    if t == "1":
        rev_flag += 1
    else:
        f = query_i[ 1 ]
        c = query_i[ 2 ]
        if f == "1" and rev_flag % 2 == 1:
            s = s + str( c )
        elif f == "2" and rev_flag % 2 == 0:
            s = s + str( c )
        else:
            s = str( c ) + s
if rev_flag_k % 2 == 1:
    s = s[::-1]

print( s )

### FIXED CODE ###

s = [ str( input() ) ]
q = int( input() )
query = []
rev_flag_k = 0
for _ in range( q ):
    query_i = list( input().split() )
    query.append( query_i )
    if query_i[ 0 ] == "1":
        rev_flag_k += 1

top = []
rev_flag = 0
for query_i in query:
    t = query_i[ 0 ]
    if t == "1":
        rev_flag += 1
    else:
        f = query_i[ 1 ]
        c = query_i[ 2 ]
        if f == "1" and rev_flag % 2 == 1:
            s.append( str( c ) )
        elif f == "2" and rev_flag % 2 == 0:
            s.append( str( c ) )
        else:
            top.append( str( c ) )
s = "".join( top )[::-1] + "".join( s )
if rev_flag_k % 2 == 1:
    s = s[::-1]

print( s )
### BUGGY CODE ###

n = int(input())
h = list(map(int, input().split()))
temp = 0
for i in range(n-1):
    a = 0
    while i+a+1 < n and h[i+a]>=h[i+a+1]:
        a += 1
        temp = max(temp, a)
print(temp)

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
temp = 0
i = 0
while i<n:
    a = 0
    while i+a+1 < n and h[i+a]>=h[i+a+1]:
        a += 1
        temp = max(temp, a)
    if a == 0: i+=1
    else: i+=a
print(temp)
### BUGGY CODE ###

S = input()
S = S[::-1]

words = ['dreamer', 'eraser', 'dream', 'erase']
for i in range(4):
    K = words[i]
    words[i] = K[::-1]

T = ''
T_next = ''

while len(T) < len(S):
    if len(T) + 5 > len(S):
        break
    for i in range(4):
        S_next = S[len(T):len(T + words[i])]
        T_next = words[i]
        #print(S_next)
        #print(T_next)
        #print()
        if S_next == T_next:
            T += T_next
            if T == S:
                print('YES')
                exit()
            break

print('NO')



### FIXED CODE ###

S = input()
S = S[::-1]

words = ['dreamer', 'eraser', 'dream', 'erase']
for i in range(4):
    K = words[i]
    words[i] = K[::-1]

T = ''
T_next = ''

while True:
    if len(T) + 5 > len(S):
        break
    for i in range(4):
        S_next = S[len(T):len(T + words[i])]
        T_next = words[i]
        flag = False
        #print(S_next)
        #print(T_next)
        #print()
        if S_next == T_next:
            flag = True
            T += T_next
            #print(T)
            #print()
            #input()
            if T == S:
                print('YES')
                exit()
            break
    if flag == False:
        break
    #input()

print('NO')