Harryxun/stf_run huggingface dataset:
a = input()
q = int(input())

fflag = 0
for i in range(q):
  qi = input()
  if( qi == "1"):
    fflag += 1 
  else:
    if( fflag%2 == 0 ):
      if( qi[2] == "2" ):
        a += qi[4]
      else:
        a = qi[4] + a
    else:
      if( qi[2] == "2" ):
        a = qi[4] + a
      else:
        a += qi[4]      
    
if( fflag%2==0 ):
  print( a )
else:
  print( a[::-1] )	

### FIXED CODE ###

bus = input()
if not( 'A' in bus):
  print( 'No')
elif not( 'B' in bus):
  print( 'No' )
else:
  print( 'Yes' )
n, x = map(int, input().split())


if (n%2 == 1):
    print((n-1)*3)
elif (n==2):
    print(3)
else:
    k=n/2
    if (x<k):
        if((n/2)%2==0):
            l = []
            for i in range(1,k-2):
                l.append(((n-1)*3)-3*(x-1))
            last = l[0]
            l.append(last)
            print(l[x-1])
        else:
            if (x%2==0):
                print((n-2)*3)
            else:
                print((n-1)*3)
    elif(x==k):
        print(int(k*3))
    else:
        p = n-x
        if (p<k):
            if((n/2)%2==0):
                l = []
                for i in range(1,k-2):
                    l.append(((n-1)*3)-3*(p-1))
                last = l[0]
                l.append(last)
                print(l[p-1])
            else:
                if (p%2==0):
                    print((n-2)*3)
                else:
                    print((n-1)*3)


### FIXED CODE ###

n, x = map(int, input().split())
a, b = max(n-x,x),min(n-x,x)
res = a+b
while b!=0:
    q = a//b
    r = a%b
    res += (b*2)*q
    if (r==0):
        res -= b
    a, b = b, r

print(res)
a = int(imput())
m = int(a / 3)
print(m)

### FIXED CODE ###

a = int(raw_input())
m = int(a / 3)
print(m)
N = int(input())

L0 = 2
L1 = 1

for i in range(N-1):
    L = L0 + L1
    L0 = L1
    L1 = L

print(L)

### FIXED CODE ###

N = int(input())

L0 = 2
L1 = L = 1

for i in range(N-1):
    L = L0 + L1
    L0 = L1
    L1 = L

print(L)
a, b, c = map(int, input().split())
if a + b + c > 0:
  print(a + b + c)
else:
  print(0)
  
  

### FIXED CODE ###

print(input().count('1'))
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()
A.sort()


def solve():
    i = N - 1
    j = 0
    big = A[i]
    small = A[j]
    i -= 1
    j += 1
    res = []
    while i <= j:
        if i == j:
            res.append((small, A[i]))
            small -= A[i]
            break
        res.append((big, A[j]))
        big -= A[j]
        res.append((small, A[i]))
        small -= A[i]
        i -= 1
        j += 1

    print(big - small)
    for x, y in res:
        print(x, y)
    print(big, small)


solve()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()
A.sort()


def solve():
    big = A[-1]
    small = A[0]
    res = []
    for i in range(1, N - 1):
        if A[i] > 0:
            res.append((small, A[i]))
            small -= A[i]
        else:
            res.append((big, A[i]))
            big -= A[i]
    res.append((big, small))
    print(big - small)
    for x, y in res:
        print(x, y)


solve()
a = input()

if a == "SUN":
  print(0)
elif a  == "MON":
  print(6)
elif a  == "TUE":
  print(5)
elif a  == "WED":
  print(4)
elif a  == "THU":
  print(3)
elif a  == "FRI":
  print(2)
else a  == "sat":
  print(1)

### FIXED CODE ###

a = input()


if  a  == "TUE":
  print(5)
elif a  == "WED":
  print(4)
elif a  == "THU":
  print(3)
elif a  == "FRI":
  print(2)
elif a  == "SAT":
  print(1)
elif a  == "SUN":
  print(7)
else:
  print(6)
def solve():
  from itertools import accumulate
  from sys import stdin
  
  f_i = stdin
  N, K = map(int, f_i.readline().split())
  A = map(int, f_i.readline().split())
  A = (a % K for a in A)
  S = [0] + list(accumulate(A))
  rec = [0] * K
  rec[0] = 1
  
  ans = 0
  for j, S_j in enumerate(S[1:], start=1):
    d = (S_j - j) % K
    ans += rec[d]
    rec[d] += 1
    i = j - K + 1
    if i >= 0:
      d = (S[i] - i) % K
      rec[d] -= 1
  
  print(ans)

solve()  

### FIXED CODE ###

def solve():
  from itertools import accumulate
  from sys import stdin
  
  f_i = stdin
  N, K = map(int, f_i.readline().split())
  A = map(int, f_i.readline().split())
  S = accumulate(a - 1 for a in A)
  S = (0, ) + tuple(s % K for s in S)
  
  rec = {}
  ans = 0
  for j, S_j in enumerate(S):
    if j >= K:
      rec[S[j-K]] -= 1
    if S_j in rec:
      ans += rec[S_j]
      rec[S_j] += 1
    else:
      rec[S_j] =1
  
  print(ans)

solve()
n=int(input())
end=n**(1/2)
for i in range(end,0,-1):
  if n%i==0:
    j=n//i
    print(i+j-2)
    break

### FIXED CODE ###

n=int(input())
end=int(n**(1/2))
for i in range(end,0,-1):
  if n%i==0:
    j=n//i
    print(i+j-2)
    break
def main():
    n, m = [int(e) for e in input().split()]
    S, C = zip(*[[int(e) for e in input().split()] for i in range(m)])

    ans = 0
    D = {}
    for si, ci in zip(S, C):
        if D.get(si) == ci:
            continue

        if D.get(si) is not None:
            print(-1)
            exit()

        ans += 10**(n - si) * ci
        D[si] = ci

    if len(str(ans)) != n:
        print(-1)
        exit()

    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n = int(input())

    ans = n//2 + n%2
    print(ans)

if __name__ == "__main__":
    main()
n = int(input())
a = input().split()
b = input().split()
c = input().split()
a = [int(i) for i in a] 
b = [int(i) for i in b] 
c = [int(i) for i in c] 

sut = 0
for i,ind in enumerate(a):
    sut += b[ind-1]
    if i>=1:
        if a[i-1]+1 == a[i]:
            sut += c[i]
print(sut)

### FIXED CODE ###

n = int(input())
a = input().split()
b = input().split()
c = input().split()
a = [int(i) for i in a] 
b = [int(i) for i in b] 
c = [int(i) for i in c] 

sut = 0
for i,ind in enumerate(a):
    sut += b[ind-1]
    if i>=1:
        if a[i-1]+1 == a[i]:
            sut += c[a[i]-2]
print(sut)
# -*- coding: utf-8 -*-

import numpy as np

def combinations(iterable, r):
    # combinations('ABCD', 2) --> AB AC AD BC BD CD
    # combinations(range(4), 3) --> 012 013 023 123
    pool = tuple(iterable)
    n = len(pool)
    if r > n:
        return
    indices = list(range(r))
    yield tuple(pool[i] for i in indices)
    while True:
        for i in reversed(range(r)):
            if indices[i] != i + n - r:
                break
        else:
            return
        indices[i] += 1
        for j in range(i+1, r):
            indices[j] = indices[j-1] + 1
        yield tuple(pool[i] for i in indices)

def main():

    n, m, x= map(int, input().split())
    matrix = [list(map(int, input().split())) for t in range(n)]

    l= []

    for i in range(n):
        for pair in combinations(matrix, i+1):
            row_sum = np.sum(pair, axis=0)
            for j in range(len(row_sum)):
                if j == 0:
                    continue
                if row_sum[j] < x:
                    break
                l.append(row_sum[0])
    if len(l) == 0:
        print('-1')
    else:
        print(min(l))


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-

import itertools
import numpy as np


def main():

    n, m, x= map(int, input().split())
    matrix = np.array([list(map(int, input().split())) for _ in range(n)], dtype=np.int32)

    out = 10**18
    for i in itertools.product([False,True], repeat=n):
        row_sum = np.sum(matrix[np.where(i)], axis=0)
        if m == np.count_nonzero(row_sum[1:] >= x):
            out = min(out, row_sum[0])

    if out == 10**18:
        print('-1')
    else:
        print(out)


if __name__ == '__main__':
    main()
N, M = map(int, input().split())
g = []
for i in range(1,M):
  if i>=M**0.5:
    break
  if M%i==0:
    j = M//i
    if i<=M//N:
      g += [i]
    if j<=M//N:
      g += [i]
print(max(g))

### FIXED CODE ###

N, M = map(int, input().split())
ls = []
for i in range(1,M+1):
  if M%i==0:
    j = M//i
    if i<=M//N:
      ls += [i]
    if j<=M//N:
      ls += [j]
  if M**0.5<i:
    break
print(max(ls))
import numpy as np
N = int(input())
A = []
i = 2
a = int()
b = int()
ans = 10**12+1
for i in range(2,int(np.sqrt(N))):
    if N%i ==0:
        A.append(i)

if len(A) == 0:
    print(N-1)
else:
    for j in range(len(A)):
        a = A[j]-1
        b = (N/A[j])-1
        if a+b <= ans:
            ans = a+b
    print(int(ans))

### FIXED CODE ###

import numpy as np
N = int(input())
A = []
i = 2
a = int()
b = int()
ans = 10**12+1
for i in range(2,int(np.sqrt(N))+1):
    if N%i ==0:
        A.append(i)

if len(A) == 0:
    print(N-1)
else:
    for j in range(len(A)):
        a = A[j]-1
        b = (N/A[j])-1
        if a+b <= ans:
            ans = a+b
    print(int(ans))
S=input()
T=input()
c=0
for i in S
 if S[i]==T[i]:
   c+=1
print(c)

### FIXED CODE ###

S=input()
T=input()
m=0
for i in range(3):
    if S[i]==T[i]:
        m+=1
print(m)
N = int(input())
S = input()
count = 0
bunki = N
countb = 0
l = N-1
for i in range(0, N):
	if(S[i] == '#'):
		bunki = i
		break
if(bunki != N):
	for j in range(bunki, N):
		if(S[j] == '.'):
			count += 1
		else:
			countb += 1 
	while(0 < l):
		if(S[l] == '#'):
			countb -= 1
		else:
			break
		l -= 1
if(countb < count):
	print(countb)
else:
	print(count)

### FIXED CODE ###

A, B, C = map(int, input().split())

if((C > A and C < B) or (C < A and C > B)):
	print('Yes')
else:
	print('No')
import sys

x = sys.stdin.readline()
a1,b1,c1 = x.split(" ")

a = int(a1)
b = int(b1)
c = int(c1)

max = a
mid = a
min = a

if max < b:
  max = b
elif min > b:
  min = b
if max < c:
  mid = max
  max = c
elif min > c:
  mid = min
  min = c

print("%d %d %d"), %(max,mid,min)

### FIXED CODE ###

x = raw_input()
x_list = x.split(" ")

x_list = map(int, x_list)

max = min = mid = 0
for i in range(1,3):
    if x_list[max] < x_list[i]:
        mid = max
        max = i
    elif x_list[min] > x_list[i]:
        mid = min
        min = i
    else:
        mid = i

print("%d %d %d" %(x_list[min], x_list[mid], x_list[max]))
if x == 0:
  print(1)
elif x == 1:
  print(0)

### FIXED CODE ###

x = int(input())
if x == 1:
  print(0)
if x == 0:
  print(1)
A,B=map(int,input().split())
import math
a=[]
for i in range(13,1010):
    if math.floor(i*0.08)==A and math.floor(i*0.10)==B:
        a.append(i)
print(a[0])

### FIXED CODE ###

A,B=map(int,input().split())
import math
a=[]
for i in range(13,1010):
    if math.floor(i*0.08)==A and math.floor(i*0.10)==B:
        a.append(i)
if len(a)>=1:
    print(a[0])
else:
    print('-1')
import sys  
input = sys.stdin.readline
 
N, M = list(map(int, input().split()))
 
A = list(map(int, input().split()))

def count_sort(arr):
    max_num = max(arr)
    min_num = min(arr)
    count = [0] * (max_num - min_num + 1)
    for ele in arr:
        count[ele - min_num] += 1

    return [ele for ele, cnt in enumerate(count, start=min_num) for __ in range(cnt)]


for i in range(M):
    b, c = list(map(int, input().split()))
    x = [c]*b
    A.extend(x)
 
A_ = count_sort(A)

    
 
print(sum(A_[-N:]))

### FIXED CODE ###

import sys  
input = sys.stdin.readline
 
N, M = list(map(int, input().split()))
 
A = list(map(int, input().split()))



BC = []
for i in range(M):
    b, c = list(map(int, input().split()))
    BC.append([b, c])

BC=sorted(BC, reverse=True, key=lambda x:x[1])

cnt = 0
com = []
for b, c in BC:
    cnt += b
    if cnt > N:
        add = N-cnt+b
        com.extend([c]*add)
        break
    else:
        x = [c]*b 
        com.extend(x)
A.sort()   
num = -1
for k in range(N):
    if k == len(com):
        num = k
        break
    if A[k] > com[k]:
        num = k
        break

if num == -1:
    print(sum(com))
else:
    print(sum(com[:num])+sum(A[num:]))
n,q = map(int,input().split())

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

counter = [0]*n 
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x

def dfs(now,prev):
    for next in edges[now]:
        if next == prev:
            continue
        counter[next] += counter[now]
        dfs(next,now)

dfs(0,-1)
print(*counter)



### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

n,q = map(int,input().split())

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

counter = [0]*n
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x

def dfs(now,prev):
    for next in edges[now]:
        if next == prev:
            continue
        counter[next] += counter[now]
        dfs(next,now)

dfs(0,-1)
print(*counter)
L, R = map(int, input().split())
from itertools import combinations

mod = 2019
l, r = L % mod, R % mod
if l > r:
    l, r = r, l

mini = l*r % mod
for i, j in combinations(range(l, r+1), 2):
    mini = min(mini, i*j % mod)
    if mini == 0:
        break
print(mini)

### FIXED CODE ###

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

if N*A <= B:
    print(N*A)
else:
    print(B)
N, S = [int(_) for _ in input().split()]
#dp[i][j] S[i-x:i+1]==S[j-x:j+1]となる最大のx
dp = [[0] * (N + 1) for _ in range(N + 1)]
ans = 0
for i in range(N - 1):
    for j in range(i+1,N):
        if S[i]==S[j]:
            dp[i][j] = min(j - i, dp[i - 1][j - 1] + 1)
            ans = max(ans, dp[i])
print(ans)


### FIXED CODE ###

import itertools
N = int(input())
S = input()
dp = [[0] * N for _ in range(N)]
ans = 0
for i, j in itertools.combinations(range(N), 2):
    if S[i] == S[j]:
        dp[i][j] = dp[i - 1][j - 1] + 1
    else:
        dp[i][j] = 0
    ans = max(ans, min(j - i, dp[i][j]))
print(ans)
N, Q = map(int, input().split())
S = input()
l, r = [0]*Q, [0]*Q
for i in range(Q):
    l[i], r[i] = map(int,input().split())
    l[i] -= 1
    r[i] -= 1
lr = zip(l,r)

R = [0]*(N+1)
for i in range(1,N+1):
    if S[i-1]=='A' and S[i]=='C':
        R[i] = R[i-1]+1
    else:
        R[i] = R[i-1]

for i,j in lr:
    print(R[j] - R[i])

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
l, r = [0]*Q, [0]*Q
for i in range(Q):
    l[i], r[i] = map(int,input().split())
    l[i] -= 1
    r[i] -= 1
lr = zip(l,r)

R = [0]*(N+1)
for i in range(1,N):
    if S[i-1]=='A' and S[i]=='C':
        R[i] = R[i-1]+1
    else:
        R[i] = R[i-1]

for i,j in lr:
    print(R[j] - R[i])
ソースコード 

Copy
Copy
def divisible(n):
    ans = 0
    while n%2 == 0:
        n /=2
        ans +=1
    return ans
 
N = int(input())
 
b = 0
 
for i in range(N):
    if(divisible(i) > b):
      b = divisible(i)
      ans = i
    
print(max(ans))

### FIXED CODE ###

def divisible(n):
 ans = 0
 while n%2 == 0:
  n /= 2
  ans += 1
 return ans
 
N = int(input())
 
b = 0

c = 1
 
for i in range(1,N+1):
    if(divisible(i) > b):
      b = divisible(i)
      c = i
    
print(c)
from fractions import gcd as g
def l(a,b):
  x=a*b/g(a,b)
  return int(x)
n=int(input())
t=[0]*n
for _ in range(n):
  t[_]=int(input())
if n==1:
  print(t[0])
else:
  m=l(t[0],t[1])
  for i in range(1,n):
    m=l(t[i],m)
  print(m)


### FIXED CODE ###

from fractions import gcd as g
def l(a,b):
  x=a*b//g(a,b)
  return x
n=int(input())
m=int(input())
for _ in range(n-1):
  t=int(input())
  m=l(m,t)
print(m)
import sys
sys.setrecursionlimit(3000)
from math import factorial

inf = input().split()
N = int(inf[0])
K = int(inf[1])
M = N-K
for i in range(1,K+1):
  red = factorial(M+1)//(factorial(i)*factorial(M+1-i))
  blue = factorial(K-1)//(factorial(i-1)*factorial(K-i))
  print(red*blue%(10**9+7))

### FIXED CODE ###

from operator import mul
from functools import reduce
 
def cmb(n,r):
    r = min(n-r,r)
    if r==0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

inf = input().split()
N = int(inf[0])
K = int(inf[1])
M = N-K
for i in range(1,K+1):
  if M+1<i:
    red = 0
  else:
    red = cmb(M+1,i)
  blue = cmb(K-1,i-1)
  print(red*blue%(10**9+7))
import bisect

def dfs(v):
  for u in g[v]:
    if checked[u]==0:
      checked[u]=1
      pos=bisect.bisect_left(dp,arr[u])
      changes.append((pos,dp[pos]))
      dp[pos]=arr[u]
      dfs(u)
  ans[v]=bisect.bisect_left(dp,10**18)
  pos,val=changes.pop()
  dp[pos]=val

n=int(input())
arr=[0]+list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for _ in range(n-1):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
ans=[0]*(n+1)
checked=[0]*(n+1)
checked[1]=1
dp=[10**18 for _ in range(n+1)]
dp[0]=1
changes=[(0,1)]
dfs(1)
for i in range(1,n+1):
  print(ans[i])

### FIXED CODE ###

import bisect
import sys
sys.setrecursionlimit(10**7)

def dfs(v):
  pos=bisect.bisect_left(dp,arr[v])
  changes.append((pos,dp[pos]))
  dp[pos]=arr[v]
  ans[v]=bisect.bisect_left(dp,10**18)
  for u in g[v]:
    if checked[u]==0:
      checked[u]=1
      dfs(u)
  pos,val=changes.pop()
  dp[pos]=val

n=int(input())
arr=[0]+list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for _ in range(n-1):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
ans=[0]*(n+1)
checked=[0]*(n+1)
checked[1]=1
dp=[10**18 for _ in range(n+1)]
changes=[]
dfs(1)
for i in range(1,n+1):
  print(ans[i])
A,B,C,D = input().split()
count = 0
start = int(A)
finish = int(B)
ite = 10000000000
for i in range(ite):
  if i == ite-1:
    nums = list(range(start *i, finish ))
    else:
      nums = list(range(start *i, start*(i+1) ))
  tmp = [x for x in nums if not x%int(C) == 0 and not x%int(D) == 0]
  count += len(tmp)
print(count)


### FIXED CODE ###

import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
A,B,C,D = input().split()
A = int(A)-1
s = lcm(int(C),int(D))
#s = int(C)*int(D)
#numac = int(A)//int(C)#10//6 = 1
#numad = int(A)//int(D)#10//8 = 1
#numacd = int(A)//s#10//24 = 0
numa = int(A)//int(C) + int(A)//int(D) - int(A)//s
#numa = 1
#numbc = int(B)//int(C)#40//6 = 6
#numbd = int(B)//int(D)#40//8 = 5
#numbcd = int(B)//s#40//24= 1
numb = int(B)//int(C) + int(B)//int(D) - int(B)//s
#numb = 1
print(int(B)-int(A)-(numb - numa))
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
h,w = map(int,readline().split())
lst1 = [list(map(int,readline().split())) for i in range(10)]

#まず、数字をiから１に変える時の最小コストを計算する。
from scipy.sparse.csgraph import shortest_path,floyd_warshall
from scipy.sparse import csr_matrix
lc = csr_matrix(lst1)
cost_lst = shortest_path(lc,method="FW")

#全探索でコストを求める。
ans = 0
for i in range(h):
    lst2 = list(map(int,readline().split()))
    for j in lst2:
        if j != -1:
            ans += cost_lst[j][1]

print(int(ans))


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
h,w = map(int,readline().split())
lst1 = [list(map(int,readline().split())) for i in range(10)]

#まず、数字をiから１に変える時の最小コストを計算する。
from scipy.sparse.csgraph import shortest_path,floyd_warshall
from scipy.sparse import csr_matrix
lc = csr_matrix(lst1)
cost_lst = shortest_path(lc,method="FW")

#全探索でコストを求める。
ans = 0
for i in range(h):
    lst2 = list(map(int,readline().split()))
    for j in lst2:
        if j != -1:
            ans += cost_lst[j][1]

print(int(ans))
N = int(input())
Ts=list(map(int,input().split()))
M = int(input())
for i in range(M):
    p,x = map(int,input().split())
    anslist = copy.deepcopy(Ts)
    anslist[p-1]=x
    print(sum(anslist))

### FIXED CODE ###

import copy
N = int(input())
Ts=list(map(int,input().split()))
M = int(input())
for i in range(M):
    p,x = map(int,input().split())
    anslist = copy.deepcopy(Ts)
    anslist[p-1]=x
    print(sum(anslist))
n, Y = map(int, input().split())
for x in range(n):
    for y in range(n-x):
        z = n-x-y
        if (x*10000 + y*5000 + z*1000) == Y:
            print(x, y, z)
            a = 1
            exit()
if a != 1:
    print(-1, -1, -1)

### FIXED CODE ###

n, Y = map(int, input().split())
a = 0
for x in range(n+1):
    for y in range(n-x+1):
        z = n-x-y
        if (x*10000 + y*5000 + z*1000) == Y:
            print(x, y, z)
            a = 1
            break
    if a == 1:
        break
if a != 1:
    print(-1, -1, -1)
N, K = [int(v) for v in input().split(" ")]
Ai = [int(v) for v in input().split(" ")]
assert len(Ai) == N


path = [0]
while True:
  next_city = Ai[path[len(path) - 1]] - 1
  if next_city in path:
    break
  path.append(next_city)

for i, city in enumerate(path):
  if city == next_city:
    start = path[:i]
    circle = path[i:]

if K <= len(start):
  print(start[K] + 1)
else:
  K -= len(start)
  print(circle[K % len(circle)] + 1)


### FIXED CODE ###

S = input()
T = input()

if len(T) != len(S) + 1:
  print("Yes")
else:
  if T.startswith(S):
    print("Yes")
  else:
    print("No")
L, R = map(int, input().split())
if (R - L + 1) >= 2019:
    print(0)
else:
    ans = 5000
    for i in range(L, R):
        for j in range(L + 1, R + 1):
            ans = min(ans, i * j % 2019)
print(ans)

### FIXED CODE ###

L, R = map(int, input().split())
mod = 2019
ans = mod
for l in range(L, L + mod + 2):
    for r in reversed(range(R - mod - 2, R + 1)):
        if l >= r:
            break
        ans = min(ans, (l * r) % mod)
print(ans)
s=sorted(str(input()))
t=sorted(str(input()),reverse=True)
if s<=t:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

a,b = map(int, input().split())
print(int((a+b+2-1)/2))
H, N = int(input())
PP = sum(map(int, input().split()))
print("Yes" if PP>=H else(No))

### FIXED CODE ###

H, N = map(int, input().split())
PP = list(map(int, input().split()))
print("Yes" if sum(PP) >= H else "No")
import numpy as np

N, W = map(int, input().split())
w = np.empty(N)
v = np.empty(N)
for i in range(N):
	w[i], v[i] = map(int, input().split())

dp = np.zeros(W + 1, dtype = np.int64)
dp[w[0]] = v[0]

for i in range(1, N):
	dp[w[i]:] = np.maximum(dp[w[i]:], dp[:W - w[i] + 1] + v[i])

print(dp.max())

### FIXED CODE ###

N,W=map(int,input().split())
wv=[[0,0]]+[list(map(int,input().split())) for _ in range(N)]

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

for i in range(1,N+1):
    for j in range(W+1):
        dp[i][j]=dp[i-1][j]
        if j - wv[i][0] >= 0:
            dp[i][j]=max(dp[i][j],dp[i-1][j-wv[i][0]]+wv[i][1])

            
print(max(dp[N]))
n = int(input())
v = [int(input()) for _ in range(n)]
c = [int(input()) for _ in range(n)]

a=0
b=0

for _ in range(n):
	if v[_] > c[_]:
		a += v[_]
		b += c[_]
		
print(a-b)

### FIXED CODE ###

n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))


a=0
b=0

for _ in range(n):
	if v[_] > c[_]:
		a += v[_]
		b += c[_]
		
print(a-b)
N,M = map(int, input().split())
a = []
for _ in range(M):
    a.append(int(input()))

ans = [a[0]]

for i in range(M-1):
    ans.append(a[i+1]-a[i]-1)
        
def fibonacci(n):
    listf = [0]+[1]*n
    a, b = 1, 0
    for i in range(n-1):
        a, b = (a+b)%1000000007 , a
        listf[i+2] = a
    return listf

fib = fibonacci(N)

result = 1
for j in range(len(ans)):
    result = result * fib[ans[j]] % 1000000007

result = result * fib[(N - a[-1])] % 1000000007
    
print(result)


### FIXED CODE ###

N,M = map(int, input().split())
a = []
for _ in range(M):
    a.append(int(input()))
    
def fibonacci(n):
    listf = [0]+[1]*n
    a, b = 1, 0
    for i in range(n-1):
        a, b = (a+b)%1000000007 , a
        listf[i+2] = a
    return listf 

fib = fibonacci(N+1)
if a:
    ans = [a[0]]
    
    for i in range(M-1):
        ans.append(a[i+1]-a[i]-1)
            

    result = 1
    for j in range(len(ans)):
        result = result * fib[ans[j]] % 1000000007
    
    result = result * fib[(N - a[-1])] % 1000000007
    
    print(result)
else:
    ans = fib[-1]
    print(ans)
a, b, c = map(int, input().split(""))
if a < b and b < c:
 print ("Yes")
else:
 print ("No")

### FIXED CODE ###

a, b, c = map(int, raw_input().split())
if a < b and b < c:
 print "Yes"
else:
 print "No"