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

from collections import deque
n=int(input())
blist=deque([int(input()) for a in range(n)])
vlist=deque([1])
while True:
    if 2 == vlist[-1]:
        print(len(vlist)-1)
        break
    a=blist[vlist[-1]-1]
    if a in deque([a for a in vlist]):
        print(-1)
        break
    else:
        vlist.append(a)

### FIXED CODE ###

from collections import deque
n=int(input())
blist=deque([int(input()) for a in range(n)])
vlist=1
count=0
while True:
    if count>n:
        print(-1)
        break
    if 2 == vlist:
        print(count)
        break
    vlist=blist[vlist-1]
    count+=1
### BUGGY CODE ###

import itertools
n,k=map(int,input().split())
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(k-1,n):
    ans=(ans+a[i]*(combination(i, k-1, mod=10**9+7)))%(10**9+7)
for i in range(0,n-k+1):
    ans=(ans-a[i]*(combination(n-i-1, k-1, mod=10**9+7)))%(10**9+7)
print(ans%(10**9+7))

### FIXED CODE ###

n,k=map(int,input().split())
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

mod=10**9+7
f=[1]
for i in range(n):f+=[f[-1]*(i+1)%mod]
def comb(a,b):
    return f[a]*pow(f[b],mod-2,mod)*pow(f[a-b],mod-2,mod)%mod

a=list(map(int,input().split()))
a.sort()
b=a[::-1]
#print(a,b)
ans=0
for i in range(k-1,n):
    ans+=((a[i]-b[i])*(comb(i,k-1)))%(10**9+7)
print(ans%(10**9+7))
### BUGGY CODE ###

# ?´???°?????°?????¨?????????????????°??????

import sys
import math

prim_no = {2: True}                    # ????????°????´???°??§??????????????????????????????

def is_prime(no):
    if no == 2:
        return True
    
    if no % 2 == 0:
        return False

    if prim_no.get(no) is not None:
        return prim_no.get(no)

    max_check = int(math.sqrt(no))
    for i in range(3, max_check+1, 2):
        if no % i == 0:
            prim_no[no] = False
            return False

    prim_no[no] = True
    return True

def main():
    while True:
        num = sys.stdin.readline()
        if num is None or num.strip() == '':
            break

        num = int(num.strip())
        if num == 1:
            cnt = 0
        else:
            cnt = 0
            for i in range(3, num + 1):
                if is_prime(i):
                    cnt += 1
            cnt += 1

        print(cnt)

if __name__ == '__main__':
    main()
    #print(prim_no)

### FIXED CODE ###

# ?´???°?????°?????¨?????????????????°??????

import sys
import math

prim_no = {2: True}                    # ????????°????´???°??§??????????????????????????????

def is_prime(no):
    if no == 2 or no == 1:
        return True
    
    if no % 2 == 0:
        return False

    if prim_no.get(no) is not None:
        return prim_no.get(no)

    max_check = int(math.sqrt(no))
    for i in range(3, max_check+1, 2):
        if no % i == 0:
            prim_no[no] = False
            return False

    prim_no[no] = True
    return True

def main():
    prim_vals = {}                         # ????????°?????§????´???°????????°
    num_data = []                          # ?????????????????????
    
    while True:
        num = sys.stdin.readline()
        if num is None or num.strip() == '':
            break

        num = int(num.strip())
        num_data.append(num)

    sorted_num_data = sorted(num_data)
    prim_num = {}
    
    for num in sorted_num_data:
        if prim_vals.get(num) is not None:
            cnt = prim_vals.get(num)
        else:
            if num == 1:
                cnt = 0
            else:
                cnt = 0

                if num % 2 == 0:
                    start_num = num -1
                else:
                    start_num = num
                    
                for i in range(start_num, 0, -2):
                    if prim_vals.get(i) is not None:
                        cnt += prim_vals.get(i)
                        break
                    
                    if is_prime(i):
                        cnt += 1
                        
                prim_vals[num] = cnt # ????????°?????§????´???°????????°????????????
        prim_num[num] = cnt

    for num in num_data:
        print(prim_num[num])

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

N, K = map(int, input().split())
while N > abs(N-K):
    N, K = abs(N-K), K
print(N)


### FIXED CODE ###

N, K = map(int, input().split())
r = N % K
print(min(r, K-r))
### BUGGY CODE ###

import collections
s = collections.deque(input())
q = int(input())

for i in range(q):
    t = tuple(input().split())
    if t[0] == "1":
        s.reverse()
    elif t[1] == "1":
        s.appendleft(t[2])
    else:
        s.append(t[2])

ans = ""

for i in s:
    ans += i

print(ans)

### FIXED CODE ###

s = input()
q = int(input())

rev = 0
head = []
tail = []

for i in range(q):
    t = input().split()
    if t[0] == "1":
        rev ^= 1
    else:
        if (int(t[1])-1)^rev == 0:
            head.append(t[2])
        else:
            tail.append(t[2])

h = "".join(head)
t = "".join(tail)

if rev == 0:
    print(h[::-1] + s + t)
else:
    s = s[::-1]
    print(t[::-1] + s + h)
### BUGGY CODE ###

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

MAX = 10**5 + 1
dp = [[10**13] * MAX for i in range(N + 1)]
dp[0][0] = 0

for i in range(1, N + 1):
    w, v = map(int, input().split())
    for j in range(MAX):
        if j < v:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-v] + w)

ans = 0
for j in range(1, MAX):
    if dp[-1][j] <= W:
        ans = j

print(ans)


### FIXED CODE ###

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

import numpy as np
MAX = 10**5 + 1
dp = [np.full(MAX, 10**13) for i in range(N + 1)]
dp[0][0] = 0

for i in range(1, N + 1):
    w, v = map(int, input().split())
    dp[i][:v] = dp[i-1][:v]
    dp[i][v:] = np.minimum(dp[i-1][v:], dp[i-1][:-v] + w)

ans = np.where(dp[N] <= W)[0].max()

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

from bisect import bisect
inpl = lambda: list(map(int, input().split()))

N = int(input())
X = inpl()
L = int(input())
Q = int(input())
R = [[0]*(N) for k in range(17)]

for i in range(N):
    R[0][i] = bisect(X, X[i]+L) - 1

for k in range(16):
    for i in range(N):
        R[k+1][i] = R[k][R[k][i]]


def reach(a, d):
    O = format(d, "b").zfill(17)[::-1]
    for k in range(16, -1, -1):
        if O[k] == "1":
            a = R[k][a]
    return a


def bisearch(a, b):
    a, b = a-1, b-1
    if b < a:
        a, b = b, a
    OK = b-a
    NG = 0

    while abs(OK - NG) > 1:
        mid = (OK+NG)//2
        if reach(a, mid) >= b:
            OK = mid
        else:
            NG = mid
    return OK

print(*[bisearch(*inpl()) for _ in range(Q)], sep="\n")


### FIXED CODE ###

from bisect import bisect
inpl = lambda: list(map(int, input().split()))

N = int(input())
X = inpl()
L = int(input())
Q = int(input())
R = [[0]*(N) for k in range(17)]

for i in range(N):
    R[0][i] = bisect(X, X[i]+L) - 1

for k in range(16):
    for i in range(N):
        R[k+1][i] = R[k][R[k][i]]


def reach(a, d):
    O = format(d, "b").zfill(17)[::-1]
    for k in range(16, -1, -1):
        if O[k] == "1":
            a = R[k][a]
    return a


def bisearch(a, b):
    a, b = a-1, b-1
    if b < a:
        a, b = b, a
    OK = b-a
    NG = 0

    while abs(OK - NG) > 1:
        mid = (OK+NG)//2
        if reach(a, mid) >= b:
            OK = mid
        else:
            NG = mid
    return OK

print(*[bisearch(*inpl()) for _ in range(Q)], sep="\n")
### BUGGY CODE ###

N = int(input())

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

# max_x = max(numbers) + 1
max_x = int(sum(numbers) / len(numbers))
res = []

for i in range(max_x + 1):
    c = 0
    for n in numbers:
        if n - 1 == i or n == i or n + 1 == i:
            c += 1
    res.append(c)

print(max(res))


### FIXED CODE ###

N = int(input())

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

# max_x = max(numbers) + 1
# max_x = int(sum(numbers) / len(numbers))
# res = 0
test = set()
for n in numbers:
    test.add(n)
    test.add(n - 1)
    test.add(n + 1)
length = len(test)
res = {}
# print(test)
# for i in range(max_x + 1):
for n in numbers:
    c = 0
    sub = set([n - 1, n, n + 1]) & test
    # print(sub)
    for s in sub:
        if res.get(s) is None:
            res[s] = 1
        else:
            res[s] += 1
# for i in test:
#     c = 0
#     for n in numbers:
#         if n - 1 == i or n == i or n + 1 == i:
#             c += 1
#     if res < c:
#         res = c

# print(res)
res = max(res.values())
print(res)
### BUGGY CODE ###

from collections import defaultdict
from itertools import combinations
dic = defaultdict(lambda : 0)
n = int(input())
for _ in range(n):
    str = ''.join(sorted(input()))
    dic[str] += 1
count = 0
for key in dic.keys():
    count += len([i for i in combinations(range(dic[key]),2)])
print(count)

### FIXED CODE ###

from collections import defaultdict
dic = defaultdict(lambda : 0)
n = int(input())
for _ in range(n):
    str = ''.join(sorted(input()))
    dic[str] += 1
count = 0
memos = defaultdict(lambda : 0)
for key in dic.keys():
    value = dic[key]
    if not value in memos.keys():
        x = value*(value-1)/2
        memos[value] = int(x)
    else:
        x = memos[value]
    count += x
print(int(count))
### BUGGY CODE ###

n = int(input())
s = input()
R = [i for i in range(n) if s[i] == "R"]
G = [i for i in range(n) if s[i] == "G"]
B = [i for i in range(n) if s[i] == "B"]
count = 0
for r in R:
    for g in G:
        for b in B:
            pos = sorted([r, g, b])
            if pos[1] - pos[0] != pos[2] - pos[1]:
                count += 1
print(count)

### FIXED CODE ###

n = int(input())
s = input()

r = len([i for i in range(n) if s[i] == "R"])
g = len([i for i in range(n) if s[i] == "G"])
b = len([i for i in range(n) if s[i] == "B"])

count = 0
for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            count += 1

print(r * g * b - count)
### BUGGY CODE ###

n, m=map(int, input().split())
a=[0 for i in range(m)]
b=[0 for i in range(m)]
g=[list() for i in range(1+n)]
#print(g)
for i in range(m):
    a[i], b[i]=map(int, input().split())
    g[a[i]].append(b[i])
    g[b[i]].append(a[i])
    #print(g)

def Count_n(neighbor, start, search):
    visited = []
    queue = []
    queue.append(start)
    result = []
    while len(queue) > 0:
        next_city = queue.pop(0)
        if next_city in visited:
            continue
        result.append (next_city)
        visited.append(next_city)
        for nei in neighbor[next_city]:
            queue.append(nei)
    if search in result:
        return [[]]
    else:
        return [result]
'''
print(g)
#print(Count(1,4,0))
for l in range(1,n+1):
    print('l,Count_n(g,l,0),len(Count_n(g,l,0))',l,Count_n(g,l,0),len(Count_n(g,l,0)[0]))
'''

ans=0
for i in range(m):
    g[a[i]].remove(b[i])
    g[b[i]].remove(a[i])
    cnt_a=len(Count_n(g,a[i],b[i])[0])
    if cnt_a==0:
        0
    else:
        ans+=cnt_a*len(Count_n(g,b[i],0)[0])
    print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

n, m=map(int, input().split())
a=[0 for i in range(m)]
b=[0 for i in range(m)]
g=[list() for i in range(1+n)]
#print(g)

par=[i for i in range(n)]
cnt_con=[1 for i in range(n)]

def root(x):
    if x==par[x]:
        return x
    else:
        par[x]=root(par[x])
        return par[x]
def connect(x,y):
    #par[x]=root(x)
    #par[y]=root(y)
    if root(x)==root(y):
        0
    else:
        cnt_con[root(y)]+=cnt_con[root(x)]
        par[root(x)]=root(y)      
    return

for i in range(m):
    a[i], b[i]=map(int, input().split())
    a[i], b[i]=a[i]-1, b[i]-1


tmp=int(n*(n-1)/2)
ans=[0]*m
ans[-1]=tmp
#ans[0]=0
#print('a,b=',a,b)
for i in range(m-1,-1,-1):
    ans[i]=tmp
    if root(a[i])==root(b[i]):
        0
    else:
        tmp-=cnt_con[root(a[i])]*cnt_con[root(b[i])]
    connect(a[i],b[i])
    #print('i,tmp',i,(a[i],b[i]),ans[i],tmp,par,cnt_con)
    

    
for i in range(m):
    print(ans[i])
### BUGGY CODE ###

N,K = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")]*(10**5+1000)
dp[0] = 0

for i in range(N):
    for j in range(1,K+1):
        if 1 <= i+j <= N-1:
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))

print(dp[N-1])


### FIXED CODE ###

N,K = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")]*(10**5+10)
dp[0] = 0

for i in range(N-1):
    Mi = min(K+1,N-i)
    for j in range(1,Mi):
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))

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

from sys import stdin
import math
import bisect
import heapq
import numpy as np
from math import factorial

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))
c = list(map(int,stdin.readline().rstrip().split()))

a.sort()
b.sort()
c.sort()

total = 0
for i in range(n):
    l= bisect.bisect_left(b,c[i])
    point = 0
    for j in range(l):
        point += bisect.bisect_left(a,b[j])
    total += point
print(total)

### FIXED CODE ###

from sys import stdin
import math
import bisect
import heapq
import numpy as np
from math import factorial

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))
c = list(map(int,stdin.readline().rstrip().split()))

a.sort()
b.sort()
c.sort()

total = 0
for i in range(n):
    l = bisect.bisect(a,b[i]-1)
    r = n -bisect.bisect_left(c,b[i]+1)
    total += l*r

print(total)
### BUGGY CODE ###

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

from collections import deque

N = int(input())
A = [[-1] + [int(x)-1 for x in row.split()][::-1] for row in sys.stdin.readlines()]

A.append([-1])

def f():
    can_use = [n for n in range(N) if A[A[n][-1]][-1] == n]
    for n in can_use:
        A[n].pop()
    return len(can_use)

answer = 0
rest = N*(N-1)
while True:
    answer += 1
    x = f()
    if x == 0:
        answer = -1
        break
    rest -= x
    if rest == 0:
        break

print(answer)

### FIXED CODE ###

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

N = int(input())
A = [[-1] + [int(x)-1 for x in row.split()][::-1] for row in sys.stdin.readlines()]

A.append([-1])

def f(cand):
    cand1 = set()
    can_use = []
    for n in cand:
        if A[A[n][-1]][-1] == n:
            can_use.append(n)
    for n in can_use:
        A[n].pop()
        cand1.add(n)
        if A[n][-1] != -1:
            cand1.add(A[n][-1])
    return len(can_use),cand1

answer = 0
rest = N*(N-1)
cand = set(range(N))
while True:
    answer += 1
    x,cand = f(cand)
    if x == 0:
        answer = -1
        break
    rest -= x
    if rest == 0:
        break

print(answer)
### BUGGY CODE ###

# 初期入力
A,B = (int(x) for x in input().split())

#公約数を求める
def kouyakusu(x1,x2):
    cf=[1]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

#約数 #商と割る数をタプルで返す
def yakusu_tapulu(n):# 商と割る数 両方を返す
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            syou,amari =divmod(n,i)
            divisors.append((syou,i))
    return divisors

#公約数の約数をタプルで作る。互いに素だから要素数は「１」
x_yakusu =[]
x_kouyaku = kouyakusu(A,B) #A,Bの公約数＿リスト
count =0
for i in x_kouyaku:
    a_yakusu = yakusu_tapulu(i)
    if len(a_yakusu) ==1:
        count +=1
        #x_yakusu.append(yakusu_tapulu(i))
print(count)

### FIXED CODE ###

# 初期入力
A,B = (int(x) for x in input().split())

#素因数分解
def soinsu_bunkai(m):
    pf={}

    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:
        pf[m]=1
    return pf
# 入力値A,Bを素因数分解
A_soinsu =soinsu_bunkai(A)
B_soinsu =soinsu_bunkai(B)

#共通の素数を探す
kyotu_soinsu ={}
a_sosu ={i for i in A_soinsu.keys()}
b_sosu ={i for i in B_soinsu.keys()}
kotae = a_sosu & b_sosu

print(len(kotae)+1) # 素数「１」を足す
### BUGGY CODE ###

n = int(input())
s = input()

dict_x = {"R":0, "G":1, "B":2}
s = [dict_x[s] for s in s]

result = 0

for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            continue
        sum_ij = s[i] + s[j]
        for k in range(j + 1, n):
            if (j - i) != (k - j):
                if sum_ij + s[k] == 3:
                    result += 1

print(result)

### FIXED CODE ###

n = int(input())
s = input()
 
r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')
 
ans = r_cnt * g_cnt * b_cnt
 
for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1
 
print(ans)
### BUGGY CODE ###

def main():
    n,m =map(int, input().split())
    #idxへの行き方の通りをリスト化
    num_list = [0]*(n+1)
    num_list[0] = 1
    a_list =[int(input()) for _ in range(m)]
    if 1 not in a_list:
        num_list[1] = 1
    
    for i in range(2,n+1):
        if i not in a_list:
            num_list[i] = num_list[i-1] + num_list[i-2]
    #print(num_list)
    return num_list[n]

if __name__=='__main__':
    print(main()%(10**9+7))

### FIXED CODE ###

n,m =map(int, input().split())
    #idxへの行き方の通りをリスト化
num_list = [0]*(n+1)
num_list[0] = 1
a_list =set([int(input()) for _ in range(m)])
if 1 not in a_list:
    num_list[1] = 1
for i in range(2,n+1):
    if i not in a_list:
        num_list[i] = num_list[i-1] + num_list[i-2]
print(num_list[n]%(10**9+7))
### BUGGY CODE ###

from bisect import insort
def main():
	(_, M) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	for i in range(M):
		b = A[-1] // 2
		insort(A, b)
		A = A[:-1]
	print(sum(A))
main()

### FIXED CODE ###

from heapq import heappush, heappop
def main():
	(N, M) = map(int, input().split())
	hq =  list(map(lambda x:-x, map(int, input().split())))
	hq.sort()
	for i in range(M):
		b = - heappop(hq) // 2
		heappush(hq, -b)
	print(-sum(hq))
main()
### BUGGY CODE ###

from functools import reduce
from itertools import product
N, M = map(int, input().split())
x, y, z = zip(*(map(int, input().split()) for _ in range(N)))


def f(a, b, c):
    dp = [(0, 0, 0) for _ in range(M + 1)]
    for t in zip(a, b, c):
        for i in range(M, 0, -1):
            if sum(dp[i - 1]) + sum(t) > sum(dp[i]):
                dp[i] = (dp[i - 1][0] + t[0], dp[i - 1][1] + t[1], dp[i - 1][2] + t[2])
    return sum(map(abs, dp[M]))


def g(k, a):
    return [k * e for e in a]


ans = max(
    f(g(p, x), g(q, y), g(r, z))
    for p, q, r in product((-1, 1), repeat=3)
)
print(ans)


### FIXED CODE ###

from itertools import product
N, M = map(int, input().split())
x, y, z = zip(*(map(int, input().split()) for _ in range(N)))


def f(a, b, c):
    return sum(sorted(map(sum, zip(a, b, c)), reverse=True)[:M])


def g(k, a):
    return [k * e for e in a]


ans = max(
    f(g(p, x), g(q, y), g(r, z))
    for p, q, r in product((-1, 1), repeat=3)
)
print(ans)
### BUGGY CODE ###

N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
t = set(s)

def tousa(n):
    return n*(n-1)//2

ans = 0
for t_i in t:
    ans += tousa(s.count(t_i))
print(ans)

### FIXED CODE ###

from collections import defaultdict
N = int(input())
d = defaultdict(int)
for _ in range(N):
    d[''.join(sorted(input()))] += 1

def tousa(n):
    return n*(n-1)//2

ans = 0
for i in d.values():
    ans += tousa(i)
print(ans)
### BUGGY CODE ###

s = list(str(input()))

for i in range(len(s)- 5):
    if s[i] == 'e' and s[i+1] == 'r' and s[i + 2] == 'a' and s[i + 3] == 's' and s[i + 4] == 'e' and s[i+5] == 'r':
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''
        s[i + 5] = ''
        
while '' in s:
    s.remove('')
    
for i in range(len(s)- 4):
    if s[i] == 'e' and s[i+1] == 'r' and s[i + 2] == 'a' and s[i + 3] == 's' and s[i + 4] == 'e' :
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''
        
while '' in s:
    s.remove('')
    
    
    
for i in range(len(s)- 6):
    if s[i] == 'd' and s[i+1] == 'r' and s[i + 2] == 'e' and s[i + 3] == 'a' and s[i + 4] == 'm' and s[i + 5] == 'e' and s[i + 6] == 'r':
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''
        s[i + 5] = ''
        s[i+6] = ''
        
while '' in s:
    s.remove('')
    
for i in range(len(s)- 4):
    if s[i] == 'd' and s[i+1] == 'r' and s[i + 2] == 'e' and s[i + 3] == 'a' and s[i + 4] == 'm' :
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''

        
while '' in s:
    s.remove('')
    
if s == []:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

s = list(str(input()))



for i in range(len(s)- 5):
    if s[i] == 'e' and s[i+1] == 'r' and s[i + 2] == 'a' and s[i + 3] == 's' and s[i + 4] == 'e' and s[i+5] == 'r':
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''
        s[i + 5] = ''
        
        
for i in range(len(s)- 4):
    if s[i] == 'e' and s[i+1] == 'r' and s[i + 2] == 'a' and s[i + 3] == 's' and s[i + 4] == 'e' :
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''
        

    
    
    
for i in range(len(s)- 6):
    if s[i] == 'd' and s[i+1] == 'r' and s[i + 2] == 'e' and s[i + 3] == 'a' and s[i + 4] == 'm' and s[i + 5] == 'e' and s[i + 6] == 'r':
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''
        s[i + 5] = ''
        s[i+6] = ''
        

    
for i in range(len(s)- 4):
    if s[i] == 'd' and s[i+1] == 'r' and s[i + 2] == 'e' and s[i + 3] == 'a' and s[i + 4] == 'm' :
        s[i] = ''
        s[i+1] = ''
        s[i + 2] = ''
        s[i + 3] = ''
        s[i + 4] = ''

        
while '' in s:
    s.remove('')
    
if s == []:
    print('YES')
else:
    print('NO')
### BUGGY CODE ###

n=int(input())
a=[0]+list(map(int,input().split()))+[0]

for i in range(n):
  temp=a[:i+1]+a[i+2:]
  s =0
  for j in range(n):
    s+=abs(temp[j+1]-temp[j])
  print(s)

### FIXED CODE ###

n=int(input())
a=[0]+list(map(int,input().split()))+[0]
s = sum([abs(a[i+1]-a[i]) for i in range(n+1)])
for i in range(1,n+1):
  ans = s+abs(a[i-1]-a[i+1])-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))
  print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))

s=1
r=[1]
for i in range(k):
  s=l[s-1]
  if s not in r:
    r.append(s)
    if i==k-1:
      print(s)
  else:
    x=r.index(s)
    mod=len(r)-x
    t=(k-i-1)%mod
    print(r[x+t])
    break

### FIXED CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))

s=1
q=[0]*n
q[0]=1
r=[1]
for i in range(k):
  s=l[s-1]
  if q[s-1]==0:
    q[s-1]+=1
    r.append(s)
    if i==k-1:
      print(s)
  else:
    x=r.index(s)
    mod=len(r)-x
    t=(k-i-1)%mod
    print(r[x+t])
    break
### BUGGY CODE ###

k=int(input())
s=len(input())
mod=10**9+7
fact=[1]*(2*10**6+4+1)
inv=[1]*(2*10**6+4+1)
for i in range(2,2*10**6+4+1):
    fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(2*10**6+4,1,-1):
    inv[i-1]=inv[i]*i%mod
def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod if x>=y>=0 else 0
print((pow(26,k+s,mod)-sum(25**(k+s-i)*comb(k+s,i) for i in range(s))%mod)%mod)

### FIXED CODE ###

k=int(input())
s=len(input())
mod=10**9+7
fact=[1]*(k+s+1)
inv=[1]*(k+s+1)
for i in range(2,k+s+1):
    fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(k+s,1,-1):
    inv[i-1]=inv[i]*i%mod
def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod if x>=y>=0 else 0
ans=pow(26,k+s,mod)
for i in range(s):
    ans=(ans-pow(25,k+s-i,mod)*comb(k+s,i)%mod)%mod
print(ans)