Harryxun/stf_run huggingface dataset:
import numpy as np

N = int(input())
K = int(input())
h_i = list(map(int, input().split()))
h_i = np.array(h_i)

can_ride = h_i[h_i>=K]
print(len(can_ride))

### FIXED CODE ###

import numpy as np
 
N, K = map(int, input().split())
h_i = list(map(int, input().split()))
h_i = np.array(h_i)
can_ride = h_i[h_i>=K]
print(len(can_ride))
import sys

def solve(a, b, c):
    # Uncomment the following if you want to check the input.
    # print('a =', a)
    # print('b =', b)
    # print('c =', c)
    w=[a,b,c]
    if 5 and 7 not in w:
        return ('NO')
    e=w.count(5)
    if e==2:
        return ('YES')
    else:
        return ('NO')


def readQuestion():
    ws = sys.stdin.readline().strip().split()
    a = int(ws[0])
    b = int(ws[1])
    c = int(ws[2])
    return (a, b, c,)

def main():
    solve(*readQuestion())

# Uncomment before submission
	main()

### FIXED CODE ###

a,b,c=input().split()
w=[a,b,c]
e=w.count('5')
if '5' and '7' not in w:
    print ('NO')
elif e==2:
    print ('YES')
else:
    print ('NO')
N= int(input("N:"))
M= int(input("M:"))

if (N==M):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

from sys import stdin
n,m = map(int,stdin.readline().split())
print("Yes" if n==m else "No")
N, K = map(int, input().split())
menu = []

for i in range(N):
    t, d = map(int, input().split())
    menu.append((t, d))

menu = sorted(menu, key = lambda x:x[1], reverse=True)
neta = set()
duplicates = []

for m in menu[:K]:
    if m[0] in neta:
        duplicates.append(m[1])
    else:
        neta.add(m[0])

p = sum([d for (t, d) in menu[:K]]) + len(neta)**2
ans = p

for m in menu[K:]:
    if m[0] not in neta:
        neta.add(m[0])
        duplicate = duplicates.pop()
        
        p += (m[1] - duplicate) + 2 * len(neta) + 1 
        #print(ans, p)
        ans = max(ans, p)

print(ans)  

### FIXED CODE ###

N, K = map(int, input().split())
menu_ = []

for i in range(N):
    t, d = map(int, input().split())
    menu_.append((t, d))

menu = sorted(menu_, key = lambda x:x[1], reverse=True)
neta = set()
duplicates = []

for m in menu[:K]:
    if m[0] in neta:
        duplicates.append(m[1])
    else:
        neta.add(m[0])

p = sum([d for (t, d) in menu[:K]]) + len(neta)**2
ans = p

for m in menu[K:]:
    if m[0] not in neta and duplicates:
        neta.add(m[0])
        duplicate = duplicates.pop()
        
        p += (m[1] - duplicate) + 2 * len(neta) - 1 
        #print(ans, p)
        ans = max(ans, p)

print(ans)
N, X = map(int, input().split())
L = list(map(int,input().split()))
D=0

for i in range(N):
    D = D + L[i]
    if D > X:
        a = i
        break

print(str(a+1))

### FIXED CODE ###

n , x = map(int, input().split())
l = list(map(int, input().split()))
tmp = [0] * (n + 1)
sum = 0
for i in range(n):
    sum += l[i]
    tmp[i + 1] = sum 

cnt = 0
for i in range(len(tmp)):
    if tmp[i] <= x:
        cnt += 1

print(cnt)
def main():
    a, b, c = map(int, input().split())

    b // a >= c ? print(c) : print(b // a)

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    a, b, c = map(int, input().split())

    if b // a >= c:
        print(c)
    else:
        print(b // a)
    
if __name__ == "__main__":
    main()
a, b = input().split()
b = b.replace('.', '')
int(a)
int(b)
print((a*b)//100)

### FIXED CODE ###

a, b = input().split()
b = b.replace('.', '')
a = int(a)
b = int(b)
print((a*b)//100)
a=int(input())
b=int(input())
print(max[a+b, a-b, a*b])

### FIXED CODE ###

A,B = map(int,input().split())
print(max(A+B,A-B,A*B))
def main(a,b,s):
  if len(s) != a+1+b :
    return 'No'
 
  for n,i in enumerate(s) :
    if n == a :
      
      if i != '-' :
        return 'No'
    else :
      try :
        int(i)
      except :
        return 'No'
  return 'Yes'
              
print(main(a,b,s))

### FIXED CODE ###

a,b =map(int, input().split())
s =input()
 
def main(a,b,s):
  if len(s) != a+1+b :
    return 'No'
 
  for n,i in enumerate(s) :
    if n == a :
      
      if i != '-' :
        return 'No'
    else :
      try :
        int(i)
      except :
        return 'No'
  return 'Yes'
              
print(main(a,b,s))
def solve(i, m, A, n):
  if m == 0:
    return 1
  if i >= n:
    return 0
  res = solve(i+1, m, A, n) or solve(i+1, m-A[i], A, n)
  return res


n = input()
A = map(int, raw_input().split())
p = input()
m = map(int, raw_input().split())
for i in range(q)
  if solve(0, m[q], A, n):
    print 'yes'
  else:
    print 'no'

### FIXED CODE ###

def solve(i, m):
  if dp[i][m] != -1:
    return dp[i][m]

  if m == 0:
    dp[i][m] = 1
  elif i >= n:
    dp[i][m] = 0
  elif solve(i+1, m):
    dp[i][m] = 1
  elif solve(i+1, m-A[i]):
    dp[i][m] = 1
  else:
    dp[i][m] = 0

  return dp[i][m]



n = input()
A = map(int, raw_input().split())
p = input()
m = map(int, raw_input().split())

dp = [[-1 for col in range(2000)] for row in range(n+1)]

for i in range(p):
  if solve(0, m[i]):
    print 'yes'
  else:
    print 'no'
from bisect import bisect_left
from collections import defaultdict

N = int(input())
S = input()
Q = int(input())
X = [input().split() for _ in range(Q)]

d = defaultdict(list)
for i in range(N):
    d[S[i]].append(i + 1)
    
ss = list(S)
for t, i, c in X:
    if t == "1":
        i = int(i)
        
        # Delete index
        d[ss[i - 1]].remove(i)
        ss[i - 1] = c

        # Insert index
        d[c].insert(bisect_left(d[c], i), i)
    else:
        l = int(i)
        r = int(c)
        
        res = 0
        for key in d:
            l_idx = bisect_left(d[key], l)
            r_idx = bisect_left(d[key], r)
            res += int((l_idx < r_idx) or (l_idx == 0 and l <= d[key][l_idx] <= r))

        print(res)



### FIXED CODE ###

N = int(input())
S = list(input())
Q = int(input())
X = [input().split() for _ in range(Q)]


class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        
    def sum(self, i):
        if i == 0:
            return 0
        
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


MAX = 5 * 10 ** 5 + 2
d = dict()

for c in range(ord("a"), ord("z") + 1):
    s = chr(c)
    d[s] = BIT(MAX)
    for i, v in enumerate(S):
        if v == s:
            d[s].add(i + 1, 1)


for t, i, c in X:
    if t == "1":
        i = int(i)
        
        if S[i - 1] != c:
            # Delete index
            d[S[i - 1]].add(i, -1)
            
            # Insert index
            d[c].add(i, 1)
            S[i - 1] = c
    else:
        l = int(i)
        r = int(c)
        
        res = 0
        for c in range(ord("a"), ord("z") + 1):
            s = chr(c)
            res += int(d[s].sum(r) - d[s].sum(l - 1) > 0)

        print(res)
import random
D=int(input())                                          #コンテの日数
c=list(map(int,input().split()))                        #26タイプ(AAC~AZC)のコンテストの満足度低下度
s=[list(map(int,input().split())) for _ in range(D)]    #s[d][i]...d(1<=d<=D)日目にi(1<=i<=26)番目のコンテストを行った時の満足度上昇
#types=[int(input()) for _ in range(D)]                  #コンテタイプ(1~26)
#満足度低下はΣ(1<=i<=26)ci*(d-last(d,i))                  #なおlast(d,i)=d日目以前に最後にタイプiのコンテストをやった日にち(ない場合0)
#よって満足度はs[d][i]-Σ(1<=i<=26)ci*(d-last(d,i))
#i日目のスコアはmax(10^6+s[d][i]-Σ(1<=i<=26)ci*(d-last(d,i)),0)
#last=[0]*26                                             #typeごとに、最後に使われた日にちを記録するよ
typ=0
ans=0
#greedyに最大とりまーす
#D=365
types=[(i%26)+1 for i in range(D)]
#print(l)
sc = [0] * D
last=[0]*26
for i in range(D):
    typ = types[i] - 1
    score = s[i][typ]
    dwn = 0
    last[typ] = (i + 1)
    for j in range(26):
        dwn = dwn + c[j] * ((i + 1) - last[j])
    ans = score - dwn
    # print(score,last)
    sc[i] = ans
all = sum(sc)
for _ in range(800):
    types2 = []
    mi=float("inf")
    ind=0
    for i in range(D):
        if mi>sc[i]:
            mi=sc[i]
            ind=i
    l=list(range(1,27))
    lab1=l.pop(types[ind])
    lab2=random.choice(l)
    spans=ind//26
    types2=types
    for i in range(spans*26,min((spans+1)*26,D)):
        if types[i]==lab2:
            types[i]=lab1
            types[ind]=lab2
            break
    sc2=[0]*D
    last=[0]*26
    for i in range(D):
        typ = types[i] - 1
        score = s[i][typ]
        dwn = 0
        last[typ] = (i + 1)
        for j in range(26):
            dwn = dwn + c[j] * ((i + 1) - last[j])
        ans = score - dwn
                # print(score,last)
        sc2[i] = ans
    all2 = sum(sc2)
    if all2<all:
        types=types2
    else:
        sc=sc2
        all=all2
    #print(max(all,all2))
for i in range(D):
    print(types[i])



### FIXED CODE ###

D=int(input())                                          #コンテの日数
c=list(map(int,input().split()))                        #26タイプ(AAC~AZC)のコンテストの満足度低下度
s=[list(map(int,input().split())) for _ in range(D)]    #s[d][i]...d(1<=d<=D)日目にi(1<=i<=26)番目のコンテストを行った時の満足度上昇
#types=[int(input()) for _ in range(D)]                  #コンテタイプ(1~26)
#満足度低下はΣ(1<=i<=26)ci*(d-last(d,i))                  #なおlast(d,i)=d日目以前に最後にタイプiのコンテストをやった日にち(ない場合0)
#よって満足度はs[d][i]-Σ(1<=i<=26)ci*(d-last(d,i))
#i日目のスコアはmax(10^6+s[d][i]-Σ(1<=i<=26)ci*(d-last(d,i)),0)
#last=[0]*26                                             #typeごとに、最後に使われた日にちを記録するよ
typ=0
ans=0
#greedyに最大とりまーす
for i in range(D):
    ma=0
    ind=0
    for j in range(26):
        if ma<=s[i][j]:
            ma=s[i][j]
            ind=j
    print(ind+1)
import random
import copy
 
H, W = map(int, input().split(" "))
A=[]
for i in range(H):
    A.append ([int(i) for i in input().split()])
 
B=np.zeros((H,W), int)
C=np.zeros((H,W), int)
B = copy.deepcopy(A)
N=0
 
cnt=0
ret=[]
def move_area(arr, cnt_odd):
    global A
    global B
    global C
    global N
    # print ("cnt_odd = " + str(cnt_odd))
    random.shuffle(arr)
    # print (arr)
    C=copy.deepcopy(A)
 
    i=int(cnt_odd/2)
    while i>0:
        a=random.randrange(len(arr))
        b=random.randrange(len(arr))
        if a != b:
            if abs(arr[a][0]-arr[b][0]) + abs(arr[a][1]-arr[b][1]) == 1:
                if C[arr[a][0]][arr[a][1]] % 2 != 0:
                    if C[arr[b][0]][arr[b][1]] % 2 != 0:
                        i -= 1
 
                    C[arr[a][0]][arr[a][1]] -= 1
                    C[arr[b][0]][arr[b][1]] += 1
                    # print (str(arr[a][0]) + " " + str(arr[a][1]) + " " + str(arr[b][0]) + " " + str(arr[b][1]))
                    ret.append(str(arr[a][0]+1) + " " + str(arr[a][1]+1) + " " + str(arr[b][0]+1) + " " + str(arr[b][1]+1))
                    N += 1
 
#    random.shuffle(arr)
#    print ("Move")
#    print (arr)
#    print ("")
def conn(arr, cnt, cnt_odd, depth):
    global A
    global B
    flg=0
    for y,x in arr:
        for yd, xd in [[0,0],[-1,0],[1,0],[0,-1],[0,1]]:
            if y+yd >= 0 and y+yd < H and x+xd >= 0 and x+xd < W:
                if B[y+yd][x+xd] != 0:
                    if [y+yd,x+xd] not in arr:
                        arr.append([y+yd,x+xd])
                    # print (str(y+yd) + " " + str(x+xd))
                    flg = 1
                    cnt += 1
                    if B[y+yd][x+xd] % 2 != 0:
                        cnt_odd += 1
                    B[y+yd][x+xd] = 0
    
    if flg > 0:
        conn(arr, cnt, cnt_odd, depth + 1)
    
    if depth ==0:
        move_area(arr, cnt_odd)
    
    return cnt % 2
    
y = random.randrange(H) 
x = random.randrange(W) 
tmp = 0
for yy in range(H):
    for xx in range(W):
        if A[yy][xx] != 0:
            cnt_odd=0
            tmp += conn([[yy,xx]], cnt, 0, 0)
            # print ("tmp = " + str(tmp))
 
# print (tmp)
 
# print (A[1][2])
# print (B[1][1])
 
print (N)
for r in ret:
    print (r)

### FIXED CODE ###

H, W = map(int, input().split(" "))
A=[]
for i in range(H):
    A.append ([int(i) for i in input().split()])

ret=[]
temp=0
N=0

for y in range(H):
    for x in range(W-1):
        if A[y][x] % 2 != 0:
            A[y][x] -= 1
            A[y][x+1] += 1
            ret.append(str(y+1) + " " + str(x+1) + " " + str(y+1) + " " + str(x+1+1))
            N+=1

for y in range(H-1):
    if A[y][W-1] % 2 != 0:
        A[y][W-1] -= 1
        A[y+1][W-1] += 1
        ret.append(str(y+1) + " " + str(W) + " " + str(y+1+1) + " " + str(W))
        N+=1
        
print (N)
for r in ret:
    print (r)
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2,
     1, 5, 1, 2, 1, 14, 1, 5, 1, 5,
     2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())
print(a[n])

### FIXED CODE ###

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2,
     1, 5, 1, 2, 1, 14, 1, 5, 1, 5,
     2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())
print(a[n-1])
N, M = map(int, input().split())
ans = [0]*N
for _ in range(M):
    s, c = map(int, input().split())
    if ans[s-1]==c:
        continue
    if ans[s-1]!=0 or (s==0 and c==0):
        ans = -1
        break
    else:
        ans[s-1] = c
print("".join(map(str, ans)))

### FIXED CODE ###

N, M = map(int, input().split())
ans = ["?" for _ in range(N)]
for _ in range(M):
    s, c = map(int, input().split())
    if N>1 and s==1 and c==0:
        ans = [-1]
        break
    if ans[s-1]!="?" and ans[s-1]!=str(c):
        ans = [-1]
        break
    ans[s-1] = str(c)
if ans==[-1]:
    print(-1)
else:
    if ans[0]=="?" and N>1:
        ans[0] = "1"
    ans = "".join(ans)
    ans = ans.replace("?", "0")
    print(ans)
n, m = map(int, input().split())
ab = []
for _ in range(m):
    a, b = map(int, input().split())
    ab.append((a-1, b-1))

class UnionFind():
    def __init__(self, li):
        self.li = li
        self.cnt = [1]*len(li)
        self.ans = 0
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return self.ans
        self.li[ry] = rx
        self.ans -= self.cnt[rx]*(self.cnt[rx]-1)//2
        self.ans -= self.cnt[ry]*(self.cnt[ry]-1)//2
        self.cnt[rx] += self.cnt[ry]
        self.ans += self.cnt[rx]*(self.cnt[rx]-1)//2
        return self.ans
uf = UnionFind(list(range(n)))
ans = [n*(n-1)//2]
for a, b in ab[::-1][:-1]:
    ans.append(n*(n-1)//2-uf.unite(a, b))
for i in reversed(ans):
    print(i)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())
ab = []
for _ in range(m):
    a, b = map(int, input().split())
    ab.append((a-1, b-1))

class UnionFind():
    def __init__(self, li):
        self.li = li
        self.cnt = [1]*len(li)
        self.ans = 0
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return self.ans
        self.li[ry] = rx
        self.ans -= self.cnt[rx]*(self.cnt[rx]-1)//2
        self.ans -= self.cnt[ry]*(self.cnt[ry]-1)//2
        self.cnt[rx] += self.cnt[ry]
        self.ans += self.cnt[rx]*(self.cnt[rx]-1)//2
        return self.ans
uf = UnionFind(list(range(n)))
ans = [n*(n-1)//2]
for a, b in ab[::-1][:-1]:
    ans.append(n*(n-1)//2-uf.unite(a, b))
for i in reversed(ans):
    print(i)
k = int(input())
l = [1,1,1,2,1,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,51]
print(l[k-1])

### FIXED CODE ###

k = int(input())
l = [1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51]
print(l[k-1])
N, M = map(int, input().split())

_a, _b = map(int, input().split())
dict_paths = {}
dict_paths[_a] = _b

for i in range(M - 1) :
    a, b = map(int, input().split())
    
    interleave_flg = False

    for k in dict_paths.keys() :
        k_tmp, k_val_tmp = k, dict_paths[k]
        
        # complete intersect
        if a >= k and b <= dict_paths[k] :
            dict_paths.pop(k)
            dict_paths[a] = b
            interleave_flg = True
            
        # nothing required
        elif a <= k and b >= dict_paths[k] :
            interleave_flg = True
            
        # left partial
        elif a < k and b > k and b <= dict_paths[k] :
            dict_paths.pop(k)
            dict_paths[a] = k_val_tmp
            interleave_flg = True
            
        # right partial
        elif a > k and a < dict_paths[k] and b >= dict_paths[k] :
            dict_paths.pop(k)
            dict_paths[k] = b
            interleave_flg = True
    
    if interleave_flg == False :
        dict_paths[a] = b
            
print(len(dict_paths))
        
    

### FIXED CODE ###

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

paths = []

for i in range(M) :
    _a, _b = map(int, input().split())
    paths.append((_a, _b))

st = sorted(paths, key = lambda x : x[1])
cnt = 0
prev_b = -1

for i in st :
    if cnt == 0 :
        cnt += 1
        prev_b = i[1]
    else :
        if i[0] >= prev_b :
            cnt += 1
            prev_b = i[1]
    
print(cnt)
x,y=map(int,input().split())
ans=0
dic={1:300000,2:200000,3:100000}
ans+=dic[x]+dic[y]
if x==1 and y==1:
  ans+=400000
print(ans)

### FIXED CODE ###

x,y=map(int,input().split())
ans=0
if x==1:
  ans+=300000
if x==2:
  ans+=200000
if x==3:
  ans+=100000
if y==1:
  ans+=300000
if y==2:
  ans+=200000
if y==3:
  ans+=100000
if x==1 and y==1:
  ans+=400000
print(ans)
import sys
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))
D.sort()
T.sort()
for i in range(M-1,-1,-1):
  while True:
    q=D.pop()
    if T[i]==q:
      #print(i)
      break
    elif T[i]>q:
      #print(i,"NO")
      sys.exit()
print("YES")

### FIXED CODE ###

import sys
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))
D.sort()
T.sort()
for i in range(M-1,-1,-1):
  while D:
    q=D.pop()
    if T[i]==q:
      #print(i)
      break
    elif T[i]>q:
      print("NO")
      sys.exit()
  else:
    print("NO")
    sys.exit()
print("YES")
n, k = map(int, input().split())
x = list(map(int, input().split()))

neg_x = []
for i in range(n):
    if x[i] < 0:
        neg_x.append(x[i])
    if x[i] >= 0:
        break
pos_x = x[len(neg_x):]
neg_x = neg_x[::-1]

if len(neg_x) == 0:
    print(pos_x[k - 1])
elif len(pos_x) == 0:
    print(-1 * neg_x[k - 1])
else:
    total_all = []
    for i in range(max(0, k - len(pos_x)), min(k, len(neg_x))):
        if i == 0:
            total1 = 0
        else:
            total1 = -1 * neg_x[i - 1]
        if k - i == 0:
            total2 = 0
        else:
            total2 = pos_x[k - i - 1]
        total = min(total1 * 2 + total2, total2 * 2 + total1)
        total_all.append(total)
    print(min(total_all))


### FIXED CODE ###

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

x_neg = []
x_pos = []
for xx in x:
    if xx < 0:
        x_neg.append(-xx)
    else:
        x_pos.append(xx)
x_neg = x_neg[::-1]

ans = float('inf')
if k <= len(x_neg):
    ans = min(ans, x_neg[k-1])
if k <= len(x_pos):
    ans = min(ans, x_pos[k-1])

for i in range(1, k):
    j = k - i
    if i <= len(x_pos) and 1 <= j <= len(x_neg):
        d1 = x_pos[i - 1]
        d2 = x_neg[j - 1]
        d = min(d1, d2) * 2 + max(d1, d2)
        ans = min(ans, d)
print(ans)
r = int(input())
pi = 3.14159265
a = r * r * pi
l = r * 2 * pi
print('{:0.8} {:0.8}'.format(a, l))


### FIXED CODE ###

r = float(input())
pi = 3.14159265359
a = r * r * pi
l = r * 2 * pi
print('{:f} {:f}'.format(a, l))
# 正の整数aとb

# aとbの積が偶数か奇数か判別する
a = int( input() )
b = int( input() )

# 積が奇数なら'Odd'、偶数なら'Even'と出力する
if int(a * b / 2) == int(a * b / 2 - 0.5):
    print('Odd')
else:
    print('even')

### FIXED CODE ###

# 正の整数aとb
a, b = map(int, input().split())
# aとbの積が偶数か奇数か判別する

# 積が奇数なら'Odd'、偶数なら'Even'と出力する
if int(a * b / 2) < int(a * b / 2 + 0.5):
    print('Odd')
else:
    print('Even')
n, k = map(int, input().split())
a = list(map(int, input().split()))
rec = [0]
i = 0
flag = [0 for _ in range(n + 1)]
while True:
    if flag[rec[i]] == 0:
        flag[rec[i]] = 1
        rec.append(a[rec[i]] - 1)
    else:
        start = rec.index(a[rec[i]] - 1)
        loop = rec[start:]
        pre = rec[:start]
        break
    i += 1
count = (k - len(pre)) % len(loop)
if k < len(pre):
    print(loop[k])
else:
    print(loop[count] + 1)


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
rec = [0]
i = 0
flag = [0 for _ in range(n + 1)]
while True:
    if flag[rec[i]] == 0:
        flag[rec[i]] = 1
        rec.append(a[rec[i]] - 1)
    else:
        start = rec.index(a[rec[i]] - 1)
        loop = rec[start:]
        pre = rec[:start]
        break
    i += 1
count = (k - len(pre)) % len(loop)
if k <= len(pre):
    print(pre[k] + 1)
else:
    print(loop[count] + 1)
from fractions import*
N＝int(input())
a  = list(map(int,input().split()))
B=[0]
a=range(N)
for x in a:B+=[gcd(B[-1],A[x])]
w=M=0
for x in a[::-1]:M=max(M,gcd(w,B[x]));w=gcd(w,A[x])
print(M)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
L=[0]
R=[0]
def gcd(x,y):
    if x==0:return y
    else:return gcd(y%x,x)
for i in range(n-1):
    L.append(gcd(L[i],a[i]))
    R.append(gcd(R[i],a[-1-i]))
MAX=0
for i in range(n):
    MAX=max(MAX,gcd(L[i],R[-1-i]))
print(MAX)
n = int(input())
S=input()
c=0
for i in range(n):
    if S[i]=="A":
        if S[i+1]=="B":
            if S[i+2]=="C":
                c+=1
print(c)

### FIXED CODE ###

n = int(input())
S=input()
c=0
for i in range(n-2):
    if S[i]=="A":
        if S[i+1]=="B":
            if S[i+2]=="C":
                c+=1
print(c)
x1,y1,x2,y2 = map(int, input().split())
len = abs(x1 - x2)

x4 = x1 - len
x3 = x2 - len
y4 = y1 - len
y3 = y2 - len

print(x3 + " " + y3 + " " + x4 + " " + y4) 

### FIXED CODE ###

x1,y1,x2,y2 = map(int, input().split())
ylen = y2 - y1
xlen = x2 - x1

x3 = x2 - ylen
y3 = y2 + xlen
x4 = x3 - xlen
y4 = y3 - ylen

print(str(x3) + " " + str(y3) + " " + str(x4) + " " + str(y4))
n = input()
inf = 1000000000
M = [[inf for i in range(n)] for i in range(n)]
str = []
for i in range(n):
  str = map(int, raw_input().split())
  u = str[0]
  k = str[1]
  for j in range(k):
    v = str[2+j]
    c = str[3+j]
    M[u][v] = c
d = [inf for i in range(n)]
color = [0 for i in range(n)]
 
d[0] = 0
color[0] = 1
 
while 1:
  minv = inf
  u = -1
  for i in range(n):
    if minv>d[i] and color[i]!=2:
      u = i
      minv = d[i]
    print minv
  if u == -1:
    break
  color[u] = 2
  for v in range(n):
    if color[v]!=2 and M[u][v]!=inf:
      if d[v]>d[u]+M[u][v]:
        d[v] = d[u] + M[u][v]
        color[v] = 1
for i in range(n):
  if d[i]==inf:
    print '%d -1' % i
  else:
    print '%d %d' % (i, d[i])

### FIXED CODE ###

n = input()
inf = 1000000000
M = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
  str = map(int, raw_input().split())
  u = str[0]
  k = str[1]
  for j in range(k):
    v = str[2+2*j]
    c = str[3+2*j]
    M[u][v] = c
d = [inf for i in range(n)]
color = [0 for i in range(n)]
 
d[0] = 0
color[0] = 1
 
while 1:
  minv = inf
  u = -1
  for i in range(n):
    if minv>d[i] and color[i]!=2:
      u = i
      minv = d[i]
  if u == -1:
    break
  color[u] = 2
  for v in range(n):
    if color[v]!=2 and M[u][v]!=inf:
      if d[v]>d[u]+M[u][v]:
        d[v] = d[u] + M[u][v]
        color[v] = 1
for i in range(n):
  if d[i]==inf:
    print '%d -1' % i
  else:
    print '%d %d' % (i, d[i])
n, m = map(int, input().split())

a = [list(sorted(map(int, input().split()))) for i in range(m)]
a.sort()

x = 0
li_a = []

while a[x][0]== 1 and x < n:
    li_a.append(a[x][1])
    x += 1

a.sort(reverse=True, key=lambda x: x[1])

x = 0
li_b = []

while a[x][1] == n and x < n:
    li_b.append(a[x][0])
    x += 1

print("POSSIBLE" if set(li_a) & set(li_b) else "IMPOSSIBLE")

### FIXED CODE ###

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

a = [list(sorted(map(int, input().split()))) for i in range(m)]
a.sort()

x = 0
li_a = []

while x < m and a[x][0]== 1:
    li_a.append(a[x][1])
    x += 1

a.sort(reverse=True, key=lambda x: x[1])

x = 0
li_b = []

while x < m and a[x][1] == n:
    li_b.append(a[x][0])
    x += 1

print("POSSIBLE" if set(li_a) & set(li_b) else "IMPOSSIBLE")