Harryxun/stf_run huggingface dataset:
# -*- coding: utf-8 -*-
import math
import sys
import bisect

## input
a,b,q = map(int, sys.stdin.readline().rstrip().split())
s_s, t_s, x_s = [[], [], []]
for _ in range(a):
  s_s.append(int(sys.stdin.readline().rstrip()))
for _ in range(b):
  t_s.append(int(sys.stdin.readline().rstrip()))
for _ in range(q):
  x_s.append(int(sys.stdin.readline().rstrip()))


## solve
def get_otherlen(st_type, k):
  if st_type == 's':
    st_s = s_s
  else:
    st_s = t_s

  idx = bisect.bisect_right(st_s, k)
  if idx == 0:
    mn = abs(st_s[0]-k)
  elif idx == len(s_s):
    mn = abs(st_s[-1]-k)
  else:
    mn = min(abs(st_s[idx]-k), abs(st_s[idx-1]-k))
  return(mn)


def get_len(k):
  # s -> t
  idx = bisect.bisect_right(s_s, k)
  if idx == 0:
    mn = abs(s_s[0]-k) + get_otherlen('t', s_s[0])
  elif idx == len(s_s):
    mn = abs(s_s[-1]-k) + get_otherlen('t', s_s[-1])
  else:
    mn1 = abs(s_s[idx]-k) + get_otherlen('t', s_s[idx])
    mn2 = abs(s_s[idx-1]-k) + get_otherlen('t', s_s[idx-1])
    mn = min(mn1, mn2)

  # t -> s
  idx = bisect.bisect_right(t_s, k)
  if idx == 0:
    mn = min(mn, abs(t_s[0]-k) + get_otherlen('s', t_s[0]))
  elif idx == len(t_s):
    mn = min(mn, abs(t_s[-1]-k) + get_otherlen('s', t_s[-1]))
  else:
    mn1 = abs(t_s[idx]-k) + get_otherlen('s', t_s[idx])
    mn2 = abs(t_s[idx-1]-k) + get_otherlen('s', t_s[idx-1])
    mn = min(mn, mn1, mn2)
  return(mn)


if __name__ == "__main__":
  for x in x_s:
    print(get_len(x))

### FIXED CODE ###

# -*- coding: utf-8 -*-
import math
import sys
import bisect

## input
a,b,q = map(int, sys.stdin.readline().rstrip().split())
s_s, t_s, x_s = [[-10**11], [-10**11], []]
for _ in range(a):
  s_s.append(int(sys.stdin.readline().rstrip()))
for _ in range(b):
  t_s.append(int(sys.stdin.readline().rstrip()))
for _ in range(q):
  x_s.append(int(sys.stdin.readline().rstrip()))
s_s.append(10**11)
t_s.append(10**11)


def solve(k):
  s_pos = bisect.bisect_left(s_s, k)
  t_pos = bisect.bisect_left(t_s, k)
  mn = 10**11
  for i in [s_s[s_pos-1], s_s[s_pos]]:
    for j in [t_s[t_pos-1], t_s[t_pos]]:
      mn = min(mn,abs(i-k)+abs(i-j), abs(j-k)+abs(i-j))
  return(mn)

if __name__ == "__main__":
  for x in x_s:
    print(solve(x))
inf = 2019
L, R = map(int, input().split())
ans = 2018
L = L % 2019
R = R % 2019
if L > R:
    print(0)
    sys.exit
for i in range(L, L + 2018):
    if i > R:
      break
      
    for j in range(i + 1, R + 1):
        tmp = int((i * j) % inf)
        ans = min(ans, tmp)
        
print(ans)


### FIXED CODE ###

inf = 2019
L, R = map(int, input().split())
ans = 0
df = R - L
if df < 2019:
    L = L % inf
    R = L + df
    ans = 2019
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            tmp = int((i * j) % inf)
            ans = min(ans, tmp)

print(ans)
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def name_count(N):
    x = N%10
    if x in [2, 4, 5, 7, 9]: return "hon"
    elif x in [0, 1,6, 8]: return "pon"
    else return "bon"

def main():
    N = int(input())
    print(name_count(N))

if __name__ == "__main__":
    main()


### FIXED CODE ###

#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def name_count(N):
    x = N%10
    if x in [2, 4, 5, 7, 9]: return "hon"
    elif x in [0, 1,6, 8]: return "pon"
    else: return "bon"

def main():
    N = int(input())
    print(name_count(N))

if __name__ == "__main__":
    main()
N, M = list(map(int,input().split()))
A_li = list(map(int,input().split()))
CB_li = []

for i in range(M):
    B, C = list(map(int,input().split()))
    li = [C]*B
    CB_li.extend(li)

CB_li.sort()
CB_li.reverse()

A_li.sort()
A_li.reverse()

ans_li = []

for i in range(N):
    if A_li[i] < max(CB_li):
        s = sum(A_li[:i])+sum(CB_li[:N-i])
        ans_li.append(sum)
        
print(str(max(ans_li)))


### FIXED CODE ###

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

CB_li.sort()
CB_li.reverse()

counter = 0
for i in range(M):
    li = [CB_li[i][0]]*CB_li[i][1]
    A_li.extend(li)
    counter += CB_li[i][1]
    if counter > N:
        break

A_li.sort()
ans = sum(A_li[-N:])
    
print(str(ans))
N=list(input())

flag=0

for i in N:
    if N[i]==9:
        flag+=1
    
if flag==0:
    print('No')
else :
    print('Yes')

### FIXED CODE ###

N=list(input())
flag=0

for i in range(0,2):
    if int(N[i])==9:
        flag+=1
    
if flag==0:
    print('No')
else :
    print('Yes')
N, K = map(int, input().split())
Ls = map(int, input().split())

sorted_Ls = sorted(Ls, reverse=True)
length_sum = 0
for k in K:
    length_sum += sorted_Ls[k]
print(length_sum)

### FIXED CODE ###

N, K = map(int, input().split())
Ls = map(int, input().split())

sorted_Ls = sorted(Ls, reverse=True)
length_sum = 0
for k in range(K):
    length_sum += sorted_Ls[k]
print(length_sum)
answer=0
count=0
 
for i in range(1,N+1,2):
    for j in range(1,int(i**0.5)+1):
        if i%j==0:
            count+=1
    if count==4:
        answer+=1
    count=0
 
print(answer)

### FIXED CODE ###

N = int(input())

answer=0
count=0
 
for i in range(1,N+1,2):
    for j in range(1,int(i**0.5)+1):
        if i%j==0:
            count+=1
    if count==4:
        answer+=1
    count=0
 
print(answer)
n = int(input())

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

m = len(bin(max(a))) - 2

ans = 0
for i in range(60):
    k = 1 << i
    i_1 = sum([k & a for a in ass]) >> i
    ans += i_1 * (n - i_1) << i
    ans = ans % ((10**9) + 7)

print(ans)


### FIXED CODE ###

n = int(input())

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

ans = 0
for i in range(60):
    k = 1 << i
    i_1 = sum([k & a for a in ass]) >> i
    ans += i_1 * (n - i_1) << i
    ans = ans % ((10**9) + 7)

print(ans)
N=int(input())
A=[int(i) for i in input().split()]
A.sort()
miss=0
if N%2==0:
    for i in range(int(N/2)):
        if miss==1:
            break
        for j in range(2):
            if A[0]==2*i+1:
                A.pop(0)
            else:
                miss=1
                break
    if miss==1:
        print(0)
    else:
        print(int((2**int(N/2))%(10e9+7)))

if N%2==1:
    if A[0]!=0:
        miss=1
        A.pop(0)
    else:
        A.pop(0)
    for i in range(int((N-1)/2)):
        if miss==1:
            break
        for j in range(2):
            if A[0]==2*i+2:
                A.pop(0)
            else:
                miss=1
                break
    if miss==1:
        print(0)
    else:
        print(int((2**int((N-1)/2))%(10e9+7)))



### FIXED CODE ###

N=int(input())
A=[int(i) for i in input().split()]
A.sort()
miss=0

if N%2==0:
    for i in range(int(N/2)):    
        if miss==1:
            break
        for j in range(2):
            if A[0]==2*i+1:
                A.pop(0)
            else:
                miss=1
                break
                
    if miss==1:
        print(0)
    else:
        print(int((2**int(N/2))%(10**9+7)))

else:
    if A[0]!=0:
        miss=1
        A.pop(0)
    else:
        A.pop(0)
    for i in range(int((N-1)/2)):
        if miss==1:
            break
        for j in range(2):
            if A[0]==2*i+2:
                A.pop(0)
            else:
                miss=1
                break
                
    if miss==1:
        print(0)
    else:
        print(int((2**int((N-1)/2))%(10**9+7)))
# input
N = int(input())
A = list(map(int, input().split()))

cnt = [0 for i in range(N)]
ans = 1

if N % 2 == 0:
    for i in range(N):
        if A[i] % 2 == 0:
            print(0)
            exit()
        cnt[A[i]] += 1
        if cnt[A[i]] > 2:
            print(0)
            exit()
        if cnt[A[i]] == 1:
            ans = (ans * 2) % (10 ** 9 + 7)
    print(ans)
else:
    for i in range(N):
        if A[i] % 2 == 1:
            print(0)
            exit()
        if A[i] > 0:
            cnt[A[i]] += 1
            if cnt[A[i]] > 2:
                print(0)
                exit()
            if cnt[A[i]] == 1:
                ans = (ans * 2) % (10 ** 9 + 7)
        if A[i] == 0:
            cnt[0] += 1
            if cnt[0] > 1:
                print(0)
                exit()
    print(ans)


ans = 1

if N % 2 == 0:
    for i in range(1, N, 2):
        if A.count(i) > 2:
            print(0)
            exit()
    for i in range(N / 2):
        ans = (ans * 2) % (10 ** 9 + 7)
    print(ans)
else:
    if A.count(0) > 1:
        print(0)
        exit()
    for i in range(2, N, 2):
        if A.count(i) > 2:
            print(0)
            exit()
    for i in range(N // 2):
        ans = (ans * 2) % (10 ** 9 + 7)
    print(ans)

### FIXED CODE ###

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

cnt = [0 for i in range(N)]
ans = 1

if N % 2 == 0:
    for i in range(N):
        if A[i] % 2 == 0:
            print(0)
            exit()
        cnt[A[i]] += 1
        if cnt[A[i]] > 2:
            print(0)
            exit()
        if cnt[A[i]] == 1:
            ans = (ans * 2) % (10 ** 9 + 7)
    print(ans)
else:
    for i in range(N):
        if A[i] % 2 == 1:
            print(0)
            exit()
        if A[i] > 0:
            cnt[A[i]] += 1
            if cnt[A[i]] > 2:
                print(0)
                exit()
            if cnt[A[i]] == 1:
                ans = (ans * 2) % (10 ** 9 + 7)
        if A[i] == 0:
            cnt[0] += 1
            if cnt[0] > 1:
                print(0)
                exit()
    print(ans)
a=int(X,16)
b=int(Y,16)

if a>b:
    print('>')
elif a<b:
    print('<')
elif a == b:
    print('=')

### FIXED CODE ###

X,Y =input().split()
a=int(X,16)
b=int(Y,16)

if a>b:
    print('>')
elif a<b:
    print('<')
elif a == b:
    print('=')
import itertools
import numpy as np
n,m,q=map(int, input().split())  
a=[list(map(int, input().split())) for i in range(m)]
b=[list(map(int, input().split())) for i in range(q)]

x=[[0]*(501) for i in range(501)]

for i in range(m):
    x[a[i][0]][a[i][1]]+=1



for i in range(501):
    x[i] = list(itertools.accumulate(x[i]))
  
x=np.array(x)
for i in range(501):
    x[:,i] = list(itertools.accumulate(x[:,i]))



for i in range(q):
    v1=b[i][0]
    v2=b[i][1]
    
    a1=x[v2,v2]
    a2=x[v2-1,v1-1]
    a3=x[v1-1,v2-1]
    a4=x[v1-1,v1-1]
    print(a1-a2-a3+a4)


 







### FIXED CODE ###

import itertools
import numpy as np
n,m,q=map(int, input().split())  
a=[list(map(int, input().split())) for i in range(m)]
b=[list(map(int, input().split())) for i in range(q)]

x=[[0]*(501) for i in range(501)]

for i in range(m):
    x[a[i][0]][a[i][1]]+=1



for i in range(501):
    x[i] = list(itertools.accumulate(x[i]))
  
x=np.array(x)
for i in range(501):
    x[:,i] = list(itertools.accumulate(x[:,i]))



for i in range(q):
    v1=b[i][0]
    v2=b[i][1]
    
    a1=x[v2,v2]
    a2=x[v2,v1-1]
    a3=x[v1-1,v2]
    a4=x[v1-1,v1-1]
    print(a1-a2-a3+a4)
N, M = map(int, input().split())
like_set = {}
for i in range(1, M+1):
    like_set.add(i)
for i in range(N):
    like = input().split()
    like = set(like[1:])
    like_set = like_set & like
print(len(like_set))


### FIXED CODE ###

N, M = map(int, input().split())
like_set = {0}
for i in range(1, M+1):
    like_set.add(i)
for i in range(N):
    like = list(map(int,input().split()))
    like = set(like[1:])
    like_set = like_set & like
print(len(like_set))
s = input()
print("no" if len(s) - set(s) == 0 else "yes")

### FIXED CODE ###

s = input()
print("no" if len(s) - len(set(s)) else "yes")
N, i = map(int(x), input().split())
print(i - N + 1)

### FIXED CODE ###

N, i = map(int, input().split())
print(N - i + 1)
a, b = int(input())
x = (a+b)/2
print(x)

### FIXED CODE ###

import math
a, b = map(int,input().split())
x = (a + b)/2
print(math.ceil(x))
import sys
sys.setrecursionlimit(2*10**5)

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

adj_list = [[] for _ in range(N)]
counter = [0 for _ in range(N)]
reached = [0 for _ in range(N)]

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

def df(current, score):
    next_nodes = adj_list[current]
    reached[current]=1
    for node in next_nodes:
        if reached[node]==0:
            counter[node]+=score
            df(node, counter[node])

for _ in range(Q):
    p,x=map(int, input().split())
    counter[p-1]+=x
df(0, counter[0])
print(*counter)


### FIXED CODE ###

import sys
sys.setrecursionlimit(2*10**9)

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

adj_list = [[] for _ in range(N)]
counter = [0 for _ in range(N)]
reached = [0 for _ in range(N)]

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

def df(current, score):
    next_nodes = adj_list[current]
    reached[current]=1
    for node in next_nodes:
        if reached[node]==0:
            counter[node]+=score
            df(node, counter[node])

for _ in range(Q):
    p,x=map(int, input().split())
    counter[p-1]+=x
df(0, counter[0])
print(*counter)
#frog
n=int(input())
h=[10**10]+list(map(int,input().split()))+[10**10]*10
def dp(i):
    if i<=1:
        return 0
    else:
        return min([dp(i-1)+abs(h[i]-h[i-1]),dp(i-2)+abs(h[i]-h[i-2])])
print(dp(n))

### FIXED CODE ###

#frog
H=10**10
n=int(input())
h=list(map(int,input().split()))+[H]*10
dp=[0]*(n+10)
for i in range(1,n+1):
    dp[i]=min([dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])])
print(dp[n-1])
def main():
  n=int(input())
  a=sorted(map(int,input().split()))
  tf=[1]*n
  n=n-1
#r=[]
#print(n)
#print(a)
  #notdiv=True
  #firstyn=0
  for i in range(n,-1,-1):
  #print(i)
  #notdiv=True
    if tf[i] ==0:
      continue
    for j in range(i):
    #print(a[j])
      if a[i]%a[j] == 0:
        tf[i]=0
        if a[i]==a[j]:
          for k in range(j,i):
            a[k]=0
        break
  print(sum(tf))
main()

### FIXED CODE ###

def main():
  n=int(input())
  a=sorted(map(int,input().split()))
  maxa=a[-1]+1
  tf=[False]*maxa
  r=0
  n-=1
  for i in range(n):
    a_i=a[i]
    if tf[a_i] ==False:
      for j in range(a_i,maxa,a_i):
        tf[j]=True
      if a_i < a[i+1]:
        #print(a_i)
        r+=1
  if tf[-1] ==False:
    r+=1
  print(r)
main()
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
c = 0
while K >=0:
    c +=1
    if not A:
        K -= B.pop(0)
    elif not B:
        K -= A.pop(0)
    elif A[0] >=B[0]:
        K -= B.pop(0)
    else:
        K -= A.pop(0)
if K == 0:
    print(c)
else:
    print(c-1)

### FIXED CODE ###

from itertools import accumulate
from bisect import bisect_right

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

a = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

result = 0
for i in range(N + 1):
    if a[i] > K:
        break
    j = bisect_right(b, K - a[i])
    result = max(result, i + j - 1)
print(result)
f = list(input())
s = list(input())
for i in range(1,4):
  if f[i] != s[4-i]:
    print("NO")
    exit()
print("YES")

### FIXED CODE ###

f = list(input())
s = list(input())
for i in range(3):
  if f[i] != s[2-i]:
    print("NO")
    exit()
print("YES")
s = raw_input().rstrip.split(" ")
a = int(s[0])
b = int(s[1])
print a*b,a*2+b*2

### FIXED CODE ###

s = raw_input().rstrip().split(" ")
a = int(s[0])
b = int(s[1])
print a*b,a*2+b*2
S=input()
if S='Sunny':
    print('Cloudy')
elif S='Cloudy':
    print('Rainy')
elif S='Rainy':
    print('Sunny')

### FIXED CODE ###

S=input()
if S=='Sunny':
    print('Cloudy')
elif S=='Cloudy':
    print('Rainy')
elif S=='Rainy':
    print('Sunny')
A, B = map(int, input().split())
if A == B:
  print(A　+　B)
elif A > B:
  print(A　*　2　-　1)
else:
  print(B　*　2　-　1)

### FIXED CODE ###

A, B = map(int, input().split())
if A == B:
  print(A+B)
elif A > B:
  print(A*2-1)
else:
  print(B*2-1)
n,k=map(int,input().split())
g=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
mod=10**9+7
pk2=[0]*(k-1)
pk2[0]=1
for i in range(k-2):
    pk2[i+1]=pk2[i]*(k-2-i)%mod
def p(n,r):
    if n<r:
        return 0
    return pk2[r]
ans=k
q=[0]
v=[0]*n
v[0]=1
while len(q)>0:
    s=q.pop(0)
    c=0
    for es in g[s]:
        if v[es]==0:
            v[es]=1
            c+=1
            q.append(es)
    if s==0:
        for i in range(k-c,k):
            ans*=i
            ans%=mod
        ans%=mod
    else:
        ans*=p(k-2,c)
        ans%=mod
print(ans%mod)

### FIXED CODE ###

from collections import deque
n,k=map(int,input().split())
if n==1 and k==1:
    print(1)
    exit()
if k==1:
    print(0)
    exit()
g=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
mod=10**9+7
ans=k
q=deque([0])
v=[0]*n
v[0]=1
vc=1
while q and vc<n:
    s=q.popleft()
    c=0
    if s==0:
        kai=k-1
    else:
        kai=k-2
    for es in g[s]:
        if v[es]==0:
            v[es]=1
            vc+=1
            c+=1
            q.append(es)
            ans*=kai
            ans%=mod
            kai-=1
print(ans%mod)
a=input()
b=input()
c=input()
d=input()
fast=max(int(a),int(c))
last=min(int(b),int(d))
print max(0,int(last-fast))

### FIXED CODE ###

str=input()
if str[0]==str[2]:
    print("Yes")
else:
    print("No")
N = input()
n = [ int(x) for x in list(N)]

K = int(input())
nl = len(N)
cnt = 0

if K == 1:
    cnt += n[0]   + (nl-1) * 9
elif K == 2 and nl >= 2:
    if nl == 2:
        cnt += (n[0]-1) * 9 + n[1]
    if nl > 2:
        cnt += (nl-1) * (nl-2) * 9 * 9 // 2
        cnt += (n[0]-1) * 9 * (nl-1)
        for i in range(1,nl+1):
            if n[i] > 0:
                cnt += n[i] + (nl - i -1) * 9
                break
elif K == 3 and  nl >= 3:
    if nl == 3:
        cnt += (n[0]-1) * 9 * 9
        cnt += (n[1]-1) * 9 + n[2]
    elif nl > 3:
        cnt += (nl-1) * (nl-2) * (nl-3) // 6 * 9 * 9 * 9
        cnt += (n[0]-1) * (nl-1) * (nl-2) //2 * 9 * 9
        for i in range(1,nl):
            if n[i] > 0:
                cnt += (nl-i-1) * (nl-i-2) // 2 * 9 * 9
                cnt += (n[i]-1) * (nl-i-1) * 9
                for j in range(i+1,nl):
                    if n[j] > 0:
                        cnt += (nl-j-1) * 9
                        cnt += n[j]
                        break
                break
print (cnt)


### FIXED CODE ###

N = input()
n = [ int(x) for x in list(N)]

K = int(input())
nl = len(N)
cnt = 0

if K == 1:
    cnt += n[0]   + (nl-1) * 9
elif K == 2 and nl >= 2:
    if nl == 2:
        cnt += (n[0]-1) * 9 + n[1]
    if nl > 2:
        cnt += (nl-1) * (nl-2) * 9 * 9 // 2
        cnt += (n[0]-1) * 9 * (nl-1)
        for i in range(1,nl):
            if n[i] > 0:
                cnt += n[i] + (nl - i -1) * 9
                break
elif K == 3 and  nl >= 3:
    if nl == 3:
        cnt += (n[0]-1) * 9 * 9
        cnt += (n[1]-1) * 9 + n[2]
    elif nl > 3:
        cnt += (nl-1) * (nl-2) * (nl-3) // 6 * 9 * 9 * 9
        cnt += (n[0]-1) * (nl-1) * (nl-2) //2 * 9 * 9
        for i in range(1,nl):
            if n[i] > 0:
                cnt += (nl-i-1) * (nl-i-2) // 2 * 9 * 9
                cnt += (n[i]-1) * (nl-i-1) * 9
                for j in range(i+1,nl):
                    if n[j] > 0:
                        cnt += (nl-j-1) * 9
                        cnt += n[j]
                        break
                break
print (cnt)
n = input()
h2 = list(map(int, input().split()))
j2 = -2
count2 = 0


def maax(count, j, h):
    if max(h) == 0:
        print(count)
        return
    k = max(h)
    
    for i in range(len(h)):
        if h[i] == k:
            if j+1 != i:
                count = count+1
    
            j = i
            h[i] = k-1
            maax(count, j, h)
    


maax(count2, j2, h2)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)


n = input()
h2 = list(map(int, input().split()))
j2 = -2
count2 = 0


def maax(count, j, h):
    if max(h) == 0:
        print(count)
        return
    k = max(h)
    
    for i in range(len(h)):
        if h[i] == k:
            if j+1 != i:
                count = count+1
    
            j = i
            h[i] = k-1
            maax(count, j, h)
    

maax(count2, j2, h2)
n = int(input())
A = [int(input()) for i in range(n)]
max = A[1]-A[0]
min = A[0]

for i in range(1,n-1):
    if(min > A[i]):
        for j in range(j,n-1):
            if(max < A[j+1]-A[i]):
                max = A[j+1]-A[i]
print(max)


### FIXED CODE ###

n = int(input())
A = [int(input()) for i in range(n)]
max = A[1]-A[0]
min = A[0]

for i in range(1,n):
    if(max < A[i]-min):
        max = A[i]-min
    if(min > A[i]):
        min = A[i]

print(max)
S=input()
print(min([abs(int(S[i:i+3])-753) for i in range(len(S)-2)]))

### FIXED CODE ###

X=int(input())
if X==3 or X==5 or X==7:
    print('YES')
else:
    print('NO')
S = input()
K = int(input())
for i in range(min(len(S), K)):
    if S[i] > 1:
        print(S[i])
        exit()
print(1)

### FIXED CODE ###

S = input()
K = int(input())
for i in range(min(len(S), K)):
    if int(S[i]) > 1:
        print(S[i])
        exit()
print(1)
# https://atcoder.jp/contests/abc075/tasks/abc075_c
class UnionFind():
    def __init__(self, N):
        self._root = [-1 for _ in range(N)]

    def find(self, x):
        if self._root[x] < 0: return x
        self._root[x] == self.find(self._root[x])
        return self._root[x]

    def unite(self, x, y):
        gx = self.find(x)
        gy = self.find(y)
        if gx == gy: return False
        if self._root[gx] > self._root[gy]:
            gx, gy = gy, gx
        self._root[gx] += self._root[gy]
        self._root[gy] = gx
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -(self._root[self.find(x)])

    def roots(self):
        return [i for i, x in emurate(self._root) if x < 0]


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

nodes = []
for _ in range(m):
    a, b = map(int, input().split())
    nodes.append((a, b))

cnt = 0
for i in range(m):
    uf = UnionFind(n)
    for j in range(m):
        if i != j:
           uf.unite(nodes[j][0]-1, nodes[j][1]-1)
    cnt += (len(uf.roots()) != 1)
print(cnt)

### FIXED CODE ###

# https://atcoder.jp/contests/abc075/tasks/abc075_c
class UnionFind():
    def __init__(self, N):
        self._root = [-1 for _ in range(N)]

    def find(self, x):
        if self._root[x] < 0: return x
        self._root[x] = self.find(self._root[x])
        return self._root[x]

    def unite(self, x, y):
        gx = self.find(x)
        gy = self.find(y)
        if gx == gy: return False
        if self._root[gx] > self._root[gy]:
            gx, gy = gy, gx
        self._root[gx] += self._root[gy]
        self._root[gy] = gx
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -(self._root[self.find(x)])

    def roots(self):
        return [i for i in self._root if i < 0]


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

nodes = []
for _ in range(m):
    a, b = map(int, input().split())
    nodes.append((a, b))

cnt = 0
for i in range(m):
    uf = UnionFind(n)
    for j in range(m):
        if i != j:
          uf.unite(nodes[j][0]-1, nodes[j][1]-1)
    cnt += (len(uf.roots()) != 1)
print(cnt)
N, K = map(int, input().split())
A = list(map(int, input().split()))

vis = set()
vis.add(1)
cnt = 0
cnt2town = {}
town2cnt = {}
cnt2town[0] = 1
town2cnt[1] = 0

for a in A:
    if a in vis:
        c = town2cnt[a]
        rem = K - cnt
        num_loop = cnt - c

        k = rem % num_loop
        print(cnt2town[c + k + 1])
        exit()

    if cnt == K:
        print(a)
        exit()

    cnt += 1
    cnt2town[cnt] = a
    town2cnt[a] = cnt
    vis.add(a)




### FIXED CODE ###

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

vis = set()
vis.add(1)
cnt = 0
cnt2town = {}
town2cnt = {}
cnt2town[0] = 1
town2cnt[1] = 0

cnt = 1
prev = 1
while cnt <= K:
    a = A[prev - 1]

    if a in vis:
        c = town2cnt[a]

        rem = K - cnt
        num_loop = cnt - c

        r = rem % num_loop
        print(cnt2town[c + r])

        exit()

    cnt2town[cnt] = a
    town2cnt[a] = cnt
    vis.add(a)

    prev = a
    cnt += 1


print(a)