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

#!/usr/bin/env python3
#ABC61 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def Bellman_Ford(edges,start):
    #start → iの最短距離
    #start:始点, num_v:頂点数, edges:[辺の始点, 辺の終点, 辺のコスト]
    dist = [-inf for _ in range(n)]
    #dist[i] := s→iの最短距離
    dist[start] = 0
    cnt = 0
    while 1:
        cnt += 1
        update = False
        for i in range(n):
            for edge in edges:
                e_from, e_to, e_cost = edge
                if e_from != inf and dist[e_to] < dist[e_from] + e_cost:
                    dist[e_to] = dist[e_from] + e_cost
                    update = True
        if not update:
            break
        if cnt == n - 1:
            d = dist[:]
        elif cnt > n - 1:
            if d[-1] < dist[-1]:
                print('inf')
                quit()
                return
            else:
                return d[-1]
    return dist[-1]

n,m = LI()
edges = []
for _ in range(m):
    a,b,c = LI()
    edges.append([a-1,b-1,c])

ans = Bellman_Ford(edges,0)
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#ABC61 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def Bellman_Ford(edges,start):
    dist = [-inf for _ in range(n)]
    dist[start] = 0
    for cnt in range(n+1):
        for edge in edges:
            e_from, e_to, e_cost = edge
            if dist[e_to] < dist[e_from] + e_cost:
                dist[e_to] = dist[e_from] + e_cost
        if cnt == n - 1:
            d = dist[:]
    if d[-1] < dist[-1]:
        print('inf')
        quit()
    else:
        return d[-1]

n,m = LI()
edges = []
for _ in range(m):
    a,b,c = LI()
    edges.append([a-1,b-1,c])

ans = Bellman_Ford(edges,0)
print(ans)
### BUGGY CODE ###

n = int(input())
 
l = []
for i in range(n) :
    a = int(input())
    l.append(a)

l.sort(reverse=False)
count_sum = 0   
for j in set(l):
    count = 0
    for  k in  range(l.index(j),len(l)):
        if l[k] == j :
            count += 1
        else :
            break
    count_sum += count%2

print(count_sum)

### FIXED CODE ###

n = int(input())

answer = {}
for i in range(n):
  ai = int(input())
  if answer.get(ai):
    answer.pop(ai)
  else:
    answer[ai] = 1
    
print(len(answer))
### BUGGY CODE ###

n=int(input())
if n<=2:
  while True:
    w=1
  
  exit()
a=1
while ((a+1)*(a+2))//2<=n:
  if n==((a+1)*(a+2))//2:
    print('Yes')
    x=a+2
    print(x)
    break
  a+=1
else:
  print('No')
  exit()
b=[]
for i in range(1,n+1):
  b+=[i]
b=b+b

l=[[] for i in range(x)]
for i in range(x):
  if i==0:
    for j in range(x-1):
      l[i].append(b.pop())
    print(x-1,*l[i])
  else:
    for j in range(i):
      l[i].append(l[j].pop())
    for j in range(x-1-i):
      l[i].append(b.pop())
    print(x-1,*l[i])

### FIXED CODE ###

n=int(input())
if n==1:
  print('Yes')
  print('2')
  print('1 1')
  print('1 1')
  exit()
a=1
while ((a+1)*(a+2))//2<=n:
  if n==((a+1)*(a+2))//2:
    print('Yes')
    x=a+2
    print(x)
    break
  a+=1
else:
  print('No')
  exit()
b=[]
for i in range(1,n+1):
  b+=[i]
b=b+b

l=[[] for i in range(x)]
for i in range(x):
  if i==0:
    for j in range(x-1):
      l[i].append(b.pop())
    print(x-1,*l[i])
  else:
    for j in range(i):
      l[i].append(l[j].pop())
    for j in range(x-1-i):
      l[i].append(b.pop())
    print(x-1,*l[i])
### BUGGY CODE ###

def resolve():
    '''
    code here
    '''
    H, W, M = [int(item) for item in input().split()]
    targets = [[int(item) -1 for item in input().split()] for _ in range(M)]

    col = [0 for _ in range(H)]
    row = [0 for _ in range(W)]

    grid = [[0 for _ in range(W+1)] for _ in range(H+1)]



    for i,j in targets:
        col[i] += 1
        row[j] += 1
        grid[i][j] = 1

    max_col = max(col)
    max_row = max(row)
    max_col_index = []
    max_row_index = []

    for i in range(H):
        if col[i] == max_col:
            max_col_index.append(i)

    for i in range(W):
        if row[i] == max_row:
            max_row_index.append(i)

    res = 0
    for item in max_col_index:
        for jtem in max_row_index:
            if grid[item][jtem] == 1:
                res = max(res, max_col + max_row -1)
            else:
                res = max(res, max_col + max_row)
    print(res)

if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
    '''
    code here
    '''
    H, W, M = [int(item) for item in input().split()]
    targets = [[int(item) -1 for item in input().split()] for _ in range(M)]

    col = [0 for _ in range(H)]
    row = [0 for _ in range(W)]

    bomb_set = set()
    # 配列で要素を作ると要素数が$10^8$超える場合、setで要素の座標を持っておく


    for i,j in targets:
        col[i] += 1
        row[j] += 1
        bomb_set.add((i,j))

    max_col = max(col)
    max_row = max(row)
    max_col_index = []
    max_row_index = []

    for i in range(H):
        if col[i] == max_col:
            max_col_index.append(i)

    for i in range(W):
        if row[i] == max_row:
            max_row_index.append(i)

    res = 0
    for item in max_col_index:
        for jtem in max_row_index:
            if (item,jtem) not in bomb_set:
                res =max_col + max_row
                break
        else:
            res = max(res, max_col + max_row -1 )
    print(res)

if __name__ == "__main__":
    resolve()
### BUGGY CODE ###

N,Q = map(int,input().split())
S = list(input())
count = 0
ans = []
for i in range(Q):
  r,l = map(int,input().split())
  S_parted = S[r-1:l]
  for k in range(len(S_parted)-1):
    if S_parted[k] == 'A' and S_parted[k+1] == 'C':
      count += 1
  ans.append(count)
  count = 0
for j in range(len(ans)):
  print(ans[j])

### FIXED CODE ###

N,Q = map(int,input().split())
S = list(input())
R = [0]*N
ans = []
temp = 0
for i in range(1,N):
  if S[i-1] == 'A' and S[i] == 'C':
    temp += 1
  R[i] = temp
for k in range(Q):
  l,r = map(int,input().split())
  ans.append(R[r-1]-R[l-1])
for j in range(len(ans)):
  print(ans[j])
### BUGGY CODE ###

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

ret = 1
MOD = 10 ** 9 + 7

from collections import Counter
import sys

ca = Counter(A)
cb = Counter(B)

if ca.most_common(1)[0][1] >= 2 or cb.most_common(1)[0][1] >= 2:
    print(0)
    sys.exit(0)

A.sort()
B.sort()

import bisect


def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1


for n in range(N * M, 0, -1):
    a = index(A, n)
    b = index(B, n)
    cntA = len(A) - bisect.bisect_right(A, n)
    cntB = len(B) - bisect.bisect_right(B, n)

    # 両方みつけた
    if a != -1 and b != -1:
        pass

    # Bの方だけ見つけた
    elif a == -1 and b != -1:
        ret *= cntA

    # Aの方だけ見つけた
    elif a != -1 and b == -1:
        ret *= cntB

    # 両方なかった
    else:
        ret *= (cntA * cntB - (N * M - n))
    ret = ret % MOD

print(ret)


### FIXED CODE ###

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

ret = 1
MOD = 10 ** 9 + 7

from collections import Counter
import sys

ca = Counter(A)
cb = Counter(B)

if ca.most_common(1)[0][1] >= 2 or cb.most_common(1)[0][1] >= 2:
    print(0)
    sys.exit(0)

A.sort()
B.sort()

import bisect


def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1


for n in range(N * M, 0, -1):
    a = index(A, n)
    b = index(B, n)
    cntA = len(A) - bisect.bisect_right(A, n)
    cntB = len(B) - bisect.bisect_right(B, n)

    # 両方みつけた
    if a != -1 and b != -1:
        pass

    # Bの方だけ見つけた
    elif a == -1 and b != -1:
        ret *= cntA

    # Aの方だけ見つけた
    elif a != -1 and b == -1:
        ret *= cntB

    # 両方なかった
    else:
        ret *= (cntA * cntB - (N * M - n))
    ret = ret % MOD

print(ret)
### BUGGY CODE ###

import itertools
n=input()
print(sum(a^b for a,b in list(itertools.combinations(map(int,input().split()),2)))%(10**9+7))

### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(60):
    c0 = 0
    c1 = 0
    c1 = sum([1 for a in l if (a>>i) & 1])
    c0 = n - c1
    ans += (c1*c0)*(2**i)
print(ans%((10**9)+7))
### BUGGY CODE ###

S = input()

while len(S) > 0:
  if "dreameraser" in S:
    S = S.replace("dreameraser","")
  elif "dream" in S:
    S = S.replace("dreamer","")
  elif "dreamer" in S:
    S = S.replace("dream","")
  elif "erase" in S:
    S = S.replace("eraser","")
  elif "eraser" in S:
    S = S.replace("erase","")
  else:
    break
    
if len(S) == 0:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

S = input()
 
while len(S) > 0:
  if "dreameraser" in S:
    S = S.replace("dreameraser","")
  elif "dreamerase" in S:
    S = S.replace("dreamerase","")
  elif "dreamer" in S:
    S = S.replace("dreamer","")
  elif "dream" in S:
    S = S.replace("dream","")
  elif "eraser" in S:
    S = S.replace("eraser","")
  elif "erase" in S:
    S = S.replace("erase","")
  else:
    break
    
if len(S) == 0:
  print("YES")
else:
  print("NO")
### BUGGY CODE ###

m,n = map(int,input().split())
print(m**n % 1000000007)

### FIXED CODE ###

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

def amari(m,n):
    if n == 0:
        return 1
    
    if n % 2 == 0:
        return amari(m,n/2)**2%1000000007 
    else:
        return  m*amari(m,n-1)%1000000007 
print(amari(m,n))
### BUGGY CODE ###

N=int(input())
S=list(map(int, input().split()))

SS=[]
n=0
ans=0
while n<=N:
  SS.append(S[n])
  if min(SS)>int(SS[n]):
    n+=1
    ans+=1
print(ans)

### FIXED CODE ###

N=int(input())
S=list(map(int, input().split()))
Min=2*(10**5)
ans=0
for i in S:
  if Min>=i:
    Min=i
    ans+=1
    
print(ans)
### BUGGY CODE ###

import functools


#@functools.lru_cache(maxsize=None)
def rec(i):
    if i <= 0:
        return i == 0
    return rec(i-1) + rec(i-2) + rec(i-3)

while True:
    N = int(input())
    if not N:
        break
    print(((rec(N)-1)//10)//365+1)

### FIXED CODE ###

import functools, math


@functools.lru_cache(maxsize=None)
def rec(i):
    if i <= 0:
        return i == 0
    return rec(i-1) + rec(i-2) + rec(i-3)

while True:
    N = int(input())
    if not N:
        break
    print(int(math.ceil(rec(N)/3650)))
### BUGGY CODE ###

from collections import defaultdict


N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

primes_total = defaultdict(int)

for a in A:
    tmp = a
    primes_a = defaultdict(int)
    p = 2
    while p * p <= tmp:
        while tmp % p == 0:
            primes_a[p] += 1
            tmp //= p
        p += 1
    if tmp != 1:
        primes_a[tmp] += 1

    for k in primes_a.keys():
        primes_total[k] = max(primes_total[k], primes_a[k])

lcm = 1
for k in primes_total.keys():
    lcm *= pow(k, primes_total[k], MOD)
    lcm %= MOD

ans = 0

for a in A:
    # フェルマーの小定理より
    ans += lcm * pow(a, MOD - 2, MOD)
    ans %= MOD

print(ans)

### FIXED CODE ###

from fractions import gcd


def main():
        
    N = int(input())
    A = list(map(int, input().split())) 
    MOD = 10**9 + 7


    l = 1

    for a in A:
        l = l * a // gcd(l, a)


    ans = 0
    for a in A:
        ans += (l // a)
    ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

import numpy as np
import math

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

dp = np.zeros(N+1, dtype=int)

dp[N] = 0

total = 0
mods = dict()
mods[0] = 1

for i in reversed(range(N)):
    newdic = dict()
    for mod, count in mods.items():
        newm = (A[i] + mod) % M
        if newm == 0:
            total += count
        newdic[newm] = count

    if 0 in newdic.keys():
        newdic[0] += 1
    else:
        newdic[0] = 1
    mods = newdic
        # print(mods)
    
print(total)


### FIXED CODE ###

import numpy as np
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

S = []
total = 0
S.append(0)
for i in range(N):
    total = (total + A[i]) % M
    S.append(total)

oS = sorted(S)

count = 0

# print(oS)

cur_val = 0
number = 0
for i in range(0, N+1):
    if oS[i] == cur_val:
        number += 1
    if oS[i] > cur_val or i == N:
        if number >= 2:
            count += int(number * (number - 1) / 2)
        # print(cur_val, number)
        number = 1
        cur_val = oS[i]

print(count)
### BUGGY CODE ###

n,q = map(int,input().split())
s = list(input())
a = [0]*n
l=1
while l<n:
    if s[l-1]=="A" and s[l]=="C":
        a[l-1]=1
        l+=2
    else:
        a[l-1]=0
        l+=1
for i in range(q):
    x,y=map(int,input().split())
    print(sum(a[x-1:y-1]))

### FIXED CODE ###

n,q = map(int,input().split())
s = list(input())
a = [0]*n
c = 0
for i in range(1,n):
    if s[i-1]=="A" and s[i]=="C":
        c+=1
    a[i]=c
for i in range(q):
    l,r = map(int,input().split())
    print(a[r-1]-a[l-1])
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
c=[0]*len(a)
all=0
for i in range(len(a)-1):
  for j in range(i+1,len(a)):
    if a[i]==a[j] and i!=j:
      c[i]+=1
      c[j]+=1
      all+=1
for i in range(len(a)):
  print(int(all-c[i]))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
c=[0]*n
#a[i]は1以上n以下で、cの要素番号は0~n-1(acは1ずれている。)
all=0
for i in range(n):
  c[a[i]-1]+=1
for i in range(n):
  if c[i]>=2:
    d=c[i]*(c[i]-1)/2
    all+=d
for i in range(n):
  print(int(all-(c[a[i]-1]-1)))
### BUGGY CODE ###

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,k = inpl()
value = [[0 for _ in range(m)] for i in range(n)]
for _ in range(k):
    a,b,c = inpl()
    value[a-1][b-1] = c
dp = [[[0 for _ in range(4)] for i in range(m)] for j in range(n)]
q = deque()
q.append((0,0))
dp[0][0][1] = value[0][0]
for oy in range(n):
    for ox in range(m):
        for dy,dx in [(1,0),(0,1)]:
            ny = oy + dy
            nx = ox + dx
            if 0 <= ny < n and 0 <= nx < m:
                nva = value[ny][nx]
                if dx: #　横移動
                    for k in range(4):
                        dp[ny][nx][k] = max(dp[ny][nx][k], dp[oy][ox][k])
                        if k and nva:
                            dp[ny][nx][k] = max(dp[ny][nx][k], dp[oy][ox][k-1] + nva)
                else: #縦移動
                    dp[ny][nx][0] = max(dp[oy][ox])
                    if nva:
                        dp[ny][nx][1] = dp[ny][nx][0] + nva
print(max(dp[-1][-1]))

### FIXED CODE ###

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,k = inpl()
value = [[0 for _ in range(m)] for i in range(n)]
for _ in range(k):
    a,b,c = inpl()
    value[a-1][b-1] = c
dp = [0] * (4*(m+1)*(n+1))
def ind(i,j,k): 
    return 4*(m+1)*i + 4*j + k
for i in range(n):
    for j in range(m):
        for k in range(3)[::-1]:
            dp[ind(i,j,k+1)] = max(dp[ind(i,j,k+1)], dp[ind(i,j,k)] + value[i][j])
        for k in range(4):
            dp[ind(i+1,j,0)] = max(dp[ind(i+1,j,0)], dp[ind(i,j,k)])
            dp[ind(i,j+1,k)] = max(dp[ind(i,j+1,k)], dp[ind(i,j,k)])
# print(dp)
mx = 0
for k in range(4):
    mx = max(mx, dp[ind(n-1,m-1,k)])
print(mx)
### BUGGY CODE ###

import math
a,b,c,d = map(int, input().split())
high = -math.inf
if a > b:
    a,b = b,a
if c > d:
    c,d = d,c
for i in range(a, b+1):
    for j in range(c, d+1):
        if i*j > high:
            high = i*j
print(high)


### FIXED CODE ###

a,b,c,d = map(int, input().split())
print(max(a*d, a*c, b*c, b*d))
### BUGGY CODE ###

from itertools import permutations
class Solve():
    def __init__(self):
        self.N, self.M, self.R = map(int, input().split())
        self.r = list(map(int, input().split()))
        self.route = [[float('inf') for _ in range(self.N)] for _ in range(self.N)]
        for _ in range(self.M):
            a, b, c = map(int, input().split())
            self.route[a - 1][b - 1] = c
            self.route[b - 1][a - 1] = c

    def WFInitialize(self):
        for i in range(self.N):
            # self.dist[i][i] = 0
            self.route[i][i] = 0

    def WarshallFloid(self):
        self.WFInitialize()
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    if self.route[i][j] > self.route[i][k] + self.route[k][j]:
                        self.route[i][j] = self.route[i][k] + self.route[k][j]

    def execute(self):
        self.WarshallFloid()
        ans = float('inf')
        for path in permutations(self.r):
            temp = 0
            for i in range(self.R - 1):
                temp += self.route[path[i] - 1][path[i + 1] - 1]
            ans = min(ans, temp)
        print(ans)


if __name__ == '__main__':
    Solve().execute()

### FIXED CODE ###

from itertools import permutations
class Solve():
    def __init__(self):
        self.N, self.M, self.R = map(int, input().split())
        self.r = list(map(int, input().split()))
        self.route = [[float('inf') for _ in range(self.N)] for _ in range(self.N)]
        for _ in range(self.M):
            a, b, c = map(int, input().split())
            self.route[a - 1][b - 1] = c
            self.route[b - 1][a - 1] = c
        for i in range(self.N):
            self.route[i][i] = 0

    def WarshallFloid(self):
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    if self.route[i][j] > self.route[i][k] + self.route[k][j]:
                        self.route[i][j] = self.route[i][k] + self.route[k][j]

    def execute(self):
        self.WarshallFloid()
        ans = float('inf')
        checked = set()
        for path in permutations(self.r):
            if tuple(reversed(path)) in checked:
                continue
            checked.add(tuple(reversed(path)))
            temp = 0
            for i in range(self.R - 1):
                temp += self.route[path[i] - 1][path[i + 1] - 1]
            ans = min(ans, temp)
        print(ans)


if __name__ == '__main__':
    Solve().execute()
### BUGGY CODE ###

import bisect
n,q = map(int,input().split())
s = input()
li=[]
for i in range(n-1):
  if s[i] == "A" and s[i+1] == "C":
    li.append(i)
for i in range(q):
  l,r = map(int,input().split())
  l = l-1
  r = r-1
  li_2 = li[bisect.bisect_left(li,l):bisect.bisect_right(li,r-1)]
  print(len(li_2))

### FIXED CODE ###

n,q = map(int,input().split())
s = input()
li = [0]
t = 0
for i in range(len(s)-1):
  if s[i] == "A" and s[i+1] == "C":
    t += 1
  li.append(t)
for k in range(q):
  l,r = map(int,input().split())
  print(li[r-1] - li[l-1])
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
    tmp=0
    for j in range(n):
        if abs(a[j]-a[i])<=1:
            tmp+=1
            ans=max(ans,tmp)
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=[0]*100002
for i in a:
    ans[i]+=1
    ans[i+1]+=1
    ans[i+2]+=1
print(max(ans))
### BUGGY CODE ###

n=int(input())
a=[int(input()) for _ in range(n)]
for i in range(n):
  k=a[:i]+a[i+1:]
  print(max(k))

### FIXED CODE ###

n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(list(set(a[:])),reverse=True)
maxa=aa[0]
f=False if a.count(maxa) != 1 else True
for i in range(n):
    if a[i] == maxa and f:
        print(aa[1] if len(aa) != 1 else maxa)
    else:
        print(maxa)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys

YES = "Yes"
NO = "No"

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

scores = [0] * K
pre = A[0]
scores[0] = A[0]
i = 1
while i < K:
    scores[i] = A[i]
    pre = pre * A[i]
    i += 1

while i < N:
    cur = pre
    cur = cur / scores[i % K]
    cur = cur * A[i]
    scores[i % K] = A[i]

    if cur > pre:
        print(YES)
    else:
        print(NO)
    pre = cur
    i += 1

### FIXED CODE ###

#!/usr/bin/env python3
import sys

YES = "Yes"
NO = "No"

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

scores = [0] * K
scores[0] = A[0]
i = 1
while i < K:
    scores[i] = A[i]
    i += 1

while i < N:
    if A[i] > scores[i % K]:
        print(YES)
    else:
        print(NO)
    scores[i % K] = A[i]
    i += 1
### BUGGY CODE ###

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


def get_input() -> tuple:
    """
    標準入力の取得.

    Returns:\n
        tuple -- 標準入力
    """
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))

    return N, K, A


def main(N: int, K: int, A: list) -> None:
    """
    求解処理.\n
    巡回路を探し出し、見つかったら巡回路分は処理を省略する.

    Args:\n
        N (int): 町の数
        K (int): テレポーターの使用回数
        A (list): テレポーターの転送先
    """
    city = 1  # 町1から出発
    cities = [city]
    remain = []
    remain_count = 0
    loop = []
    loop_count = 0
    while True:
        city = A[city-1]
        if city in cities:
            remain_count = cities.index(city)
            remain = cities[:remain_count-1]
            loop = cities[remain_count:]
            loop_count = len(loop)
            break
        else:
            cities.append(city)

    result = int()
    if K < remain_count:
        result = remain[K]
    else:
        result = loop[(K - remain_count) % loop_count]

    # 結果出力
    print(result)


if __name__ == "__main__":
    N, K, A = get_input()
    main(N, K, A)


### FIXED CODE ###

# -*- coding: utf-8 -*-
# モジュールのインポート
import math


def get_input() -> tuple:
    """
    標準入力の取得

    Returns:\n
        tuple: 標準入力
    """
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))

    return N, K, A


def main(N: int, K: int, A: list) -> None:
    """
    求解処理.

    Args:
        N (int): 町の数
        K (int): テレポーターの使用回数
        A (list): テレポーターの転送先
    """
    # タブリング表の作成
    to = [A]
    for i in range(math.ceil(math.log2(K))):
        to_i = to[i]
        to_next = []
        for j in range(N):
            to_next.append(to_i[to_i[j]-1])

        to.append(to_next)

    result = 1
    for i in range(math.ceil(math.log2(K))):
        if ((K >> i) & 1):
            result = to[i][result-1]

    print(result)


if __name__ == "__main__":
    N, K, A = get_input()
    main(N, K, A)