Harryxun/stf_run huggingface dataset:
N, M = map(int, input().split())
N_list = [0] * N
N_set_list = [False] * N

for i in range(M):
  s, c = map(int, input().split())
  s -= 1
  
  if s > N -1 or (s == 0 and c == 0):
    print(-1)
    exit()

  elif N_set_list[s] and (N_list[s] != c):
    print(-1)
    exit()

  else:
    N_list[s] = c
    N_set_list[s] = True

if N_list[0] == 0 and len(N_list) != 1
  N_list[0] = 1

print(''.join(map(str, N_list)))


### FIXED CODE ###

N, M = map(int, input().split())
N_list = [0] * N
N_set_list = [False] * N

for i in range(M):
  s, c = map(int, input().split())
  s -= 1
  
  if s > N -1 or (s == 0 and c == 0 and N != 1):
    print(-1)
    exit()

  elif N_set_list[s] and (N_list[s] != c):
    print(-1)
    exit()

  else:
    N_list[s] = c
    N_set_list[s] = True

if N_list[0] == 0 and N != 1:
  N_list[0] = 1

print(''.join(map(str, N_list)))
n, k = map(int, input().split())
s = set()
for _ in range(k):
    input()
    s.add(*list(map(int, input().split())))
print(n - len(s))

### FIXED CODE ###

n, k = map(int, input().split())
s = set()
for _ in range(k):
    input()
    a = list(map(int, input().split()))
    for i in a:
        s.add(i)
print(n - len(s))
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    a = [0] * 10005
    A_max = A[-1]

    for i in A:
        for j in range(1, A_max//i + 1):
            a[i * j] += 1

    ans = 0
    for i in A:
        if a[i] == 1:
            ans += 1
    print(ans)

if __name__ == "__main__":
    resolve()

### FIXED CODE ###

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    a = [0] * 1000005
    A_max = A[-1]

    for i in A:
        for j in range(1, A_max//i + 1):
            a[i * j] += 1

    ans = 0
    for i in A:
        if a[i] == 1:
            ans += 1
    print(ans)

if __name__ == "__main__":
    resolve()
I = input().split()
     
    K = int(I[0])
    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]
    print( A[K-1] )

### FIXED CODE ###

I = input().split()
         
K = int(I[0])
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]
print( A[K-1] )
MI = lambda :(map(int,input().split()))
x = II()
if x>1799:
	print(1)
elif x>1599:
	print(2)
elif x>1399:
	print(3)
elif x>1199:
	print(4)
elif x>999:
	print(5)
elif x>799:
	print(6)
elif x>599:
	print(7)
else:
	print(8)

### FIXED CODE ###

MI = lambda :(map(int,input().split()))
x = int(input())
if x>1799:
	print(1)
elif x>1599:
	print(2)
elif x>1399:
	print(3)
elif x>1199:
	print(4)
elif x>999:
	print(5)
elif x>799:
	print(6)
elif x>599:
	print(7)
else:
	print(8)
n=int(input())
dat = list(map(int, input().split()))
dan = []
for e in dat:
    e = str(bin(e))
    e=e[2:]
       
for e in dat:
     i = len(e)
                

         
           




### FIXED CODE ###

import sys

def main():
    N = int(input())
    A = [int(_) for _ in input().split()]

    t = 0
    while True:
        for i in range(N):
            if A[i] % 2 == 0:
                A[i] //= 2
            else:
                print(t)
                sys.exit()
        t += 1

main()
s = input()
s = s.replace("B0", "")
s = s.replace("B1", "")
s = s.replace("B", "")
print(r)

### FIXED CODE ###

s = input()

while(s.count('B')):
    if s.count('0B'):
        s = s.replace('0B','')
    elif s.count('1B'):
        s = s.replace('1B','')
    else:
        s = s.replace('B','')   
        
print(s)
o = input()
e = input()
ans = ""
for i in o:
  ans += o[i]
  if len(e) > i:
    ans += e[i]
print(ans)

### FIXED CODE ###

o = input()
e = input()
ans = ""
for i in range(len(o)):
  ans += o[i]
  if len(e) > i:
    ans += e[i]
print(ans)
S = input()
snx = S.replace('x', '')
ls = len(S)
if ls == 1:
    print(0)
    exit(0)
l = 0
r = ls-1

ans = 0
while l < r:

    lxc = 0
    while S[l] == 'x':
        l += 1
        lxc += 1
    
    rxc = 0
    while S[r] == 'x':
        r -= 1
        rxc += 1

    ans += abs(lxc-rxc)

    if S[l] == S[r]:
        l += 1
        r -= 1
    else:
        print(-1)
        break
else:
    print(ans)


### FIXED CODE ###

S = input()
snx = S.replace('x', '')
ls = len(S)
if ls == 1 or len(snx) == 0:
    print(0)
    exit(0)
l = 0
r = ls-1

ans = 0
while l < r:
    lxc = 0
    while S[l] == 'x':
        l += 1
        lxc += 1
    rxc = 0
    while S[r] == 'x':
        r -= 1
        rxc += 1
    ans += abs(lxc-rxc)

    if S[l] == S[r]:
        l += 1
        r -= 1
    else:
        print(-1)
        break
else:
    print(ans)
palindrom = input()
if palindrom != palindrom[::-1]:
	return "No"
n = (len(palindrom)-1)/2
if palindrom[:n] != palindrom[:n:-1]:
	return "No"
n2 = (len(palindrom)+3)/2
if palindrom[:n2] != palindrom[:n2:-1]:
	return "No"
else
	return "Yes"

### FIXED CODE ###

s=list(input())
N=len(s)
s2=s[:(N-1)//2]
s3=s[((N+3)-1)//2:N+1]
if s==list(reversed(s)) and s2==list(reversed(s2)) and s3==list(reversed(s3)):
  print("Yes")
else:
  print("No")
t = map(int, input().split())
if t[0]＊t[1] % 2 == 0:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

s, t = map(int, input().split())
if s * t % 2 == 0:
  print("No")
else:
  print("Yes")
N=int(input())
ans=0
for i in range(1,N + 1,2):
    cnt=0
    for j in range(1,i+1):
        if not i%j:
          cnt+=1
    if cnt==8:
      ans += 1
print(ans)


### FIXED CODE ###

A,B=map(int,input().split())
print(A*B-A-B+ 1)
import cmath
import numpy as np
import sys

INF=10**18
MOD=10**9+7
MAX=10**5+7

def main():
    N=int(input())
    dp=[0, 0, 0]
    for line in sys.stdin.readlines():
        a,b,c=map(int, line.split())
        ndp=[0, 0, 0]
        ndp[0]=max(dp[1], dp[2])+a
        ndp[1]=max(dp[2], dp[0])+b
        ndp[2]=max(dp[0], dp[1])+c
        dp=ndp
    print(max(dp))

main()


### FIXED CODE ###

import cmath
import numpy as np
import sys

INF=10**18
MOD=10**9+7
MAX=10**5+7

def main():
    N=int(input())
    dp=[0, 0, 0]
    for _ in range(N):
        a,b,c=map(int, input().split())
        ndp=[0, 0, 0]
        ndp[0]=max(dp[1], dp[2])+a
        ndp[1]=max(dp[2], dp[0])+b
        ndp[2]=max(dp[0], dp[1])+c
        dp=ndp
    print(max(dp))

if __name__=='__main__':
    main()
import Queue
import sys

class Proc:
    def __init__(self, name, time):
        self.time = time
        self.name = name

def main():
    array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))
    p_num = array[0]
    q_time = array[1]
    p_queue = Queue.Queue()
    for i in range(0, p_num):
        array = sys.readline().strip().split()
        p_queue.put(Proc(array[0], int(array[1])))
    t = 0
    while not p_queue.empty():
        p = p_queue.get()
        if p.time > q_time:
            p.time = p.time - q_time
            p_queue.put(p)
            t += q_time
        else:
            t += p.time
            print p.name + " " + str(t)
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

import Queue
import sys

class Proc:
    def __init__(self, name, time):
        self.time = time
        self.name = name

def main():
    array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))
    p_num = array[0]
    q_time = array[1]
    p_queue = Queue.Queue()
    for i in range(0, p_num):
        array = sys.stdin.readline().strip().split(" ")
        p_queue.put(Proc(array[0], int(array[1])))
    t = 0
    while not p_queue.empty():
        p = p_queue.get()
        if p.time > q_time:
            p.time = p.time - q_time
            p_queue.put(p)
            t += q_time
        else:
            t += p.time
            print p.name + " " + str(t)
    
if __name__ == "__main__":
    main()
from collections import Counter
    
n = int(input())
v = list(map(int, input().split()))
odd = v[::2]
even = v[1::2]
    
c_even = Counter(even).most_common(2)
c_odd = Counter(odd).most_common(2)

print(c_even, c_odd)
    
if(c_even[0][0] != c_odd[0][0]):
    print(n - c_even[0][1] - c_odd[0][1])
elif(len(c_even) >= 2 and len(c_odd) >= 2):
    second = max[c_even[1][1], c_odd[1][1]]
    print(n - c_even[0][1] - second)
else:
    print(n//2)

### FIXED CODE ###

from collections import Counter
    
n = int(input())
v = list(map(int, input().split()))
odd = v[::2]
even = v[1::2]
    
c_even = Counter(even).most_common(2)
c_odd = Counter(odd).most_common(2)

    
if(c_even[0][0] != c_odd[0][0]):
    print(n - c_even[0][1] - c_odd[0][1])
else:
    if(len(c_even) == 1):
        print(n//2)
    else:
        # second = max[c_even[1][1], c_odd[1][1]]
        # print(n - c_even[0][1] - second)
        print(n - max(c_even[0][1] + c_odd[1][1], c_even[1][1] + c_odd[0][1]))
import math
import sympy
S = int(input())
x = int(math.ceil(math.sqrt(S)))
Z = x * x - S

if Z == 0:
    z = 0
    oz = 0
else:
    fs = sympy.factorint(Z)
    z = 1
    oz = 1
    for k in fs:
        c = fs[k]
        while c >= 2:
            z *= k
            oz *= k
            c -= 2
        if c > 0:
            if z < oz:
                z *= k
            else:
                oz *= k




print("0 0 {} {} {} {}".format(x, z, oz, x))


### FIXED CODE ###

import math
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

S = int(input())
x = int(math.ceil(math.sqrt(S)))
Z = x * x - S

if Z == 0:
    z = 0
    oz = 0
else:
    fs = factorize(Z)
    z = 1
    oz = 1
    for k, c in fs:
        while c >= 2:
            z *= k
            oz *= k
            c -= 2
        if c > 0:
            if z < oz:
                z *= k
            else:
                oz *= k




print("0 0 {} {} {} {}".format(x, z, oz, x))
s = str(raw_input())
w = ['Sunny', 'cloudy', 'Rainy', 'Sunny']
print(w[w.index(s)+1])

### FIXED CODE ###

s = str(raw_input())
w = ['Sunny', 'Cloudy', 'Rainy']
i = w.index(s)
if i < 2:
    print(w[i+1])
else:
    print(w[0])
r = int(input)

print(int(r**2))


### FIXED CODE ###

r = int(input())

print(int(r**2))
# AGC015A - A+...+B Problem
from itertools import product


def main():
    n, a, b = tuple(map(int, input().rstrip().split()))
    if a > b or (n == 1 and abs(a - b) > 1):
        print(0)
        return
    if (n == 1 and a == b) or n == 2:
        print(1)
        return
    ans = {sum(i) for i in product(range(a, b + 1), repeat=n - 2)}
    print(len(ans))


if __name__ == "__main__":
    main()

### FIXED CODE ###

# AGC015A - A+...+B Problem
def main():
    n, a, b = tuple(map(int, input().rstrip().split()))
    if a > b or (n == 1 and a != b):
        print(0)
    elif n == 1 and a == b:
        print(1)
    else:
        print((n - 2) * (b - a) + 1)


if __name__ == "__main__":
    main()
n,m=map(int, input().split())

roads=[]

for _ in range(m):
  a,b=map(int, input().split())
  if a<b:
  	roads.append([a,b].sort())
  else:
    roads.append([b,a].sort())
  
group=[i for i in range(n)]

group2=[]

while group2!=group:
  group2=group
  for road in roads:
    group[road[1]-1]=group[road[0]-1]

counter=1
for i in range(n-1):
  if group[i]!=group[i+1]:
    counter+=1

print(counter-1) 
      

### FIXED CODE ###

class UnionFind:
    from typing import List, Set

    def __init__(self, n):
        self.n = n
        self.parent = [-1] * n

    def merge(self, x, y) -> int:
        x = self.leader(x)
        y = self.leader(y)

        if x == y:
            return 0

        if self.parent[x] > self.parent[y]:
            x, y = y, x

        self.parent[x] += self.parent[y]
        self.parent[y] = x

        return self.parent[x]

    def same(self, x, y) -> bool:
        return self.leader(x) == self.leader(y)

    def leader(self, x) -> int:
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.leader(self.parent[x])
            return self.parent[x]

    def size(self, x) -> int:
        return -self.parent[self.leader(x)]

    def groups(self) -> List[Set[int]]:
        groups = dict()

        for i in range(self.n):
            p = self.leader(i)
            if not groups.get(p):
                groups[p] = set()
            groups[p].add(i)

        return list(groups.values())


def main():
    N, M = map(int, input().split())

    uf = UnionFind(N)

    for _ in range(M):
        # UnionFindを0スタートで実装しているので、入力から1引きます
        A, B = map(lambda x: int(x) - 1, input().split())  
        uf.merge(A, B)  # AとBをmergeします。union, uniteとも呼ばれます。

    print(len(uf.groups()) - 1)


if __name__ == '__main__':
    main()
from math import *

def trycut(val):
	ret = 0
	for i in range(n):
		ret += ceil(a[i]/val)-1
	return ret 

n,k=map(int,input().split())
a = [int(i) for i in input().split()]

low = 0
high = 1000000000
ans  =-1

while low <= high:
	mid = (low + high)//2
	cut = trycut(mid)
	if cut <= k:
		high = mid-1
		ans = mid
	else:
		low =  mid+1
print(ans)




### FIXED CODE ###

from math import *

def trycut(val):
	ret = 0
	for i in range(n):
		ret += ceil(a[i]/val)-1
	return ret 

n,k=map(int,input().split())
a = [int(i) for i in input().split()]

low = 0
high = 1000000000
ans  =-1

while low <= high:
	mid = (low + high)/2
	cut = trycut(mid)
	# ~ print("low=",low, "high=", high,"val = ",mid,"ret = ",cut)
	if cut <= k:
		high = mid-0.0000001
		ans = mid
	else:
		low =  mid+0.0000001
	# ~ if low < high: print(low, high, "je reviens")
ans = int(ans*1000000)/1000000
# ~ print(ans)
print(int(ceil(ans)))
N,R = map(int,input().split())

num1=M*(M-1)*0.5
num2=N*(N-1)*0.5

print(num1+num2)

### FIXED CODE ###

n, m = map(int, input().split())
ans = n*(n-1)//2 + m*(m-1)//2
print(ans)
list = input().split()
print(list[0]*list[1], list[0]*2+list[1]*2)

### FIXED CODE ###

list = input().split()
x = int(list[0])
y = int(list[1])
print(x*y, x*2+y*2)
a,b,c = map(int,input().split())

if ((a+b+c)%3 == 0):
    print("Yes")
else
    print("No")

    

### FIXED CODE ###


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

#list 並び替え→最初と最後足して == 真ん中　ならばYES!!!

can.sort()

if can[0]+can[1] == can[2]:
    print("Yes")
else:
    print("No")
num = int(input())
char=[] #appendのために宣言が必要
while True:
    try:
        char.append(list(input()))

    except:
        break
new_char=[]
cnt=0
for i in range(num):
	new_char.append(sorted(char[i]))
for x in range(num):
    for y in range(num):
        if new_char[x]==new_char[y] and x!=y:
            cnt = cnt+1
print(cnt)

### FIXED CODE ###

x,y = map(int,input().split())

ans = [x*y,x+y,x-y]

print(max(ans))
import math
from decimal import Decimal, getcontext
getcontext().prec = 0
a,b,c = map(int,input().split())

if Decimal(c**0.5 - a**0.5 - b**0.5) < 0:
  print("No")
else:
  print("Yes")

### FIXED CODE ###


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

if 4*a*b - (c - a - b) ** 2 < 0 and c - a - b > 0:
  print("Yes")
  
else:
  print("No")
import numpy as np

N = int(input())
a = []
x = []
y = []
count = 0

def factorial(n):
    if n<2:
        return 1
    else:
        return(n*factorial(n-1))

for i in range(N):
    a.append(list(map(int,input().split())))    
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        count += np.sqrt((a[i][0] - a[j][0])**2 + (a[i][1] - a[j][1])**2)
b = factorial(N)
#print(count/b)
print(count/N)


### FIXED CODE ###

r = int(input())
print(r**2)
import sys
def MI(): return map(int, sys.stdin.readline().split())

H,W = MI()
s = [list(input()) for _ in range(H)]
dp = [[0 for _ in range(W)] for _ in range(H)]

if s[0][0]=='#':
	dp[0][0] = 1

for i in range(W-1):
	if s[0][i+1]=='#' and s[0][i]=='.':
		dp[0][i+1] = dp[0][i] + 1
	else:
		dp[0][i+1] = dp[0][i]

for i in range(H-1):
	if s[i+1][0]=='#' and s[i][0]=='.':
		dp[i+1][0] = dp[i][0] + 1
	else:
		dp[i+1][0] = dp[i][0]

# print(dp)

def next(start, goal, start_value):
	if start=='.' and goal=='#':
		start_value += 1
	return start_value

for i in range(1,W):
	for j in range(1,W):
		# print(next(s[i][j-1],s[i][j],dp[i][j-1]),next(s[i-1][j],s[i][j],dp[i-1][j]))
		dp[i][j] = min(next(s[i][j-1],s[i][j],dp[i][j-1]),next(s[i-1][j],s[i][j],dp[i-1][j]))
print(dp[W-1][H-1])



### FIXED CODE ###

import sys
def MI(): return map(int, sys.stdin.readline().split())

H,W = MI()
s = [list(input()) for _ in range(H)]
dp = [[0 for _ in range(W)] for _ in range(H)]

if s[0][0]=='#':
	dp[0][0] = 1

for i in range(W-1):
	if s[0][i+1]=='#' and s[0][i]=='.':
		dp[0][i+1] = dp[0][i] + 1
	else:
		dp[0][i+1] = dp[0][i]

for i in range(H-1):
	if s[i+1][0]=='#' and s[i][0]=='.':
		dp[i+1][0] = dp[i][0] + 1
	else:
		dp[i+1][0] = dp[i][0]

def next(start, goal, start_value):
	if start=='.' and goal=='#':
		start_value += 1
	return start_value

for i in range(1,H):
	for j in range(1,W):
		# print(next(s[i][j-1],s[i][j],dp[i][j-1]),next(s[i-1][j],s[i][j],dp[i-1][j]))
		dp[i][j] = min(next(s[i][j-1],s[i][j],dp[i][j-1]), next(s[i-1][j],s[i][j],dp[i-1][j]))

print(dp[H-1][W-1])
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()


N=int(input())
X=input()
C=X.count("1")

lst=[]
lstcount=[]
for x in [C-1,C+1]:
    flg=0
    if x<=0:
        lst.append(0)
        lstcount.append(0)
    else:
        Z=0
        p=1
        for i in range(N):
            if X[-i-1]=="1":
                Z+=p
            p*=2
            if Z>=x:
                Z%=x
                flg=1
            if flg:
                p%=x
        lst.append(Z)
        lstcount.append(flg)
#print(lst)
fac1=[1]
fac2=[1]
C1=C-1
C2=C+1
for i in range(N):
    fac1.append(fac1[-1]*2%C1)
    fac2.append(fac2[-1]*2%C2)

for i in range(N):

    _C=C+(1 if X[i]=="0"  else -1 )
    if _C==0:
        print(0)
        continue
    if  X[i]=="0":
        lstidx=1
    else:
        lstidx=0

    idx=(N-1-i)

    value=lst[lstidx]+(fac2[idx] if  X[i]=="0" else fac1[idx])
    bit=value
    count=0
    while value:
        count+=1
        value%=_C
        _C=0
        bit=value
        while bit:
            _C+=bit&1
            bit>>=1
        if _C==0:
            break
    print(max(count,1))


### FIXED CODE ###

from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()


N=int(input())
X=input()
C=X.count("1")

lst=[]
lstcount=[]
for x in [C-1,C+1]:
    flg=0
    if x<=0:
        lst.append(0)
        lstcount.append(0)
    else:
        Z=0
        p=1
        for i in range(N):
            if X[-i-1]=="1":
                Z+=p
            p*=2
            if Z>=x:
                Z%=x
                flg=1
            if flg:
                p%=x
        lst.append(Z)
        lstcount.append(flg)
#print(lst)
fac1=[1]
fac2=[1]
C1=max(C-1,1)
C2=max(C+1,1)
for i in range(N):
    fac1.append(fac1[-1]*2%C1)
    fac2.append(fac2[-1]*2%C2)

for i in range(N):

    _C=C+(1 if X[i]=="0"  else -1 )
    if _C==0:
        print(0)
        continue
    if  X[i]=="0":
        lstidx=1
    else:
        lstidx=0

    idx=(N-1-i)

    value=lst[lstidx]+(fac2[idx] if  X[i]=="0" else -fac1[idx])
    #print(value,X[i]=="0",lst,C-1,C+1)
    bit=value
    count=0
    while value and _C:
        count+=1
        value%=_C
        _C=0
        bit=value
        while bit:
            _C+=bit&1
            bit>>=1
    print(max(count,1))
N = int(input())
S = []
for _ in range(N):
    D = list(map(int, input().split()))
    S.append(D)

import numpy as np
dp=np.zeros((N+1,3))

for i in range(1,N+1):
    for j in range(3):
        for k in range(3):
            if j != k:

                dp[i][j] = max(dp[i-1][k] + S[i-1][j],dp[i][j])
                #happy =  dp[i-1][k] + S[i-1][j]
                #if dp[i][j] < happy:
                #    dp[i][j] = happy

print(int(max(dp[N])))

### FIXED CODE ###

N = int(input())
S = []
for _ in range(N):
    D = list(map(int, input().split()))
    S.append(D)

import numpy as np
#dp=np.zeros((N+1,3))

dp = [[0 for _ in range(3)] for _ in range(N+1)]

for i in range(1,N+1):
    for j in range(3):
        for k in range(3):
            if j != k:
                happy =  dp[i-1][k] + S[i-1][j]
                if dp[i][j] < happy:
                    dp[i][j] = happy

print(int(max(dp[N])))
Nstr = input()
SN = 0
for i in N:
    SN += int(i)
if int(N) % SN == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

Nstr = input()
SN = 0
for i in Nstr:
    SN += int(i)
if int(Nstr) % SN == 0:
    print('Yes')
else:
    print('No')
i = 0
ans = 0
while True:
    if i >= len(S):
        #print('終わり！')
        break
    for j in range(i+1,len(S)+1):
        #print(S[i:j])
        a = max(S[i:j])
        if j >= len(S):
            #print(1,S[i:j],i,j,ans)
            ans += max(S[i:j])
            i += j
            break
        elif a <= S[j]:
            #print(2,i,j,ans)
            continue
        else:
            #print(3,S[i:j],i,j,ans)
            ans += max(S[i:j])
            ans -= S[j]
            i = j
            break
print(ans)

### FIXED CODE ###

input()
S = list(map(int,input().split()))
i = 0
ans = 0
while True:
    if i >= len(S):
        #print('終わり！')
        break
    for j in range(i+1,len(S)+1):
        #print(S[i:j])
        a = max(S[i:j])
        if j >= len(S):
            #print(1,S[i:j],i,j,ans)
            ans += max(S[i:j])
            i += j
            break
        elif a <= S[j]:
            #print(2,i,j,ans)
            continue
        else:
            #print(3,S[i:j],i,j,ans)
            ans += max(S[i:j])
            ans -= S[j]
            i = j
            break
print(ans)
n = int(input())

s = 0
for i in range(1, int(n**(1/2)+1) ):
    ans = (n-i) // i
    if n//ans == n%ans:
        s+=ans
print(s)

### FIXED CODE ###

n = int(input())

if n==1:
    print(0)
    exit()
    
s = 0
for i in range(1, int(n**(1/2)+1) ):
    ans = (n-i) // i
    if n//ans == n%ans:
        s+=ans
print(s)
n = int(input())
a = list(map(int,input().split()))
if a[-1] >= a[-2]:
    a.append(float('inf'))
else:
    a.append(-float('inf'))
ans = 1
i = 0
while i < n-1:
    if a[i] < a[i+1] > a[i+2]:
        ans += 1
        i += 2
    elif a[i] > a[i+1] < a[i+2]:
        ans += 1
        i += 2
    else:
        i += 1
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

ans = 1
status = 0
prev = a[0]

for i in a:
    diff = i - prev

    if diff == 0:
        pass
    elif diff > 0:
        if status >= 0:
            status = diff
        else:
            ans += 1
            status = 0
    else:
        if status <= 0:
            status = diff
        else:
            ans += 1
            status = 0

    prev = i

print(ans)
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    print(max(A) - min(B))


### FIXED CODE ###

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    print(max(A) - min(A))
a,b = map(int,intput().split())
ans = max(a-2*b,0)
print(ans)

### FIXED CODE ###

a,b = map(int,input().split())
ans = max(a-2*b,0)
print(ans)
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = []
order = {}
x = 1
T = -1
while T < 0:
  x = a[x-1] #添字に直す
  if x not in visited:
    visited.append(x)
    order[x] = len(visited)
  else:
    T = len(visited) - order[x]
    s = order[x]
if k < s:
  print(visited[k])
else:
  mod = (k-s) % T
  print(visited[s+mod])


### FIXED CODE ###

n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] # 訪れていたら訪れたときの添字を格納する。
points = []
p = 1
while visited[p] == -1:
  visited[p] = len(points)
  points.append(p)
  p = a[p-1] #添字に直す

T = len(points) - visited[p]
s = visited[p]

if k < s:
  print(points[k])
else:
  mod = (k - s) % T
  print(points[s+mod])