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

import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
A = [0] + list(map(int,readline().split()))

c = 1
while K:
  if K&1:
    c = A[c]
  na = [0] * (N+1)
  for i in range(N+1):
    na[i] = A[A[i]]
  A = na
  K >>= 1
print(c)

### FIXED CODE ###

# A_1からスタートして、同じA_iに戻ってくるまでの[移動回数][到着場所]をリスト化

import sys
readline = sys.stdin.readline

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

route = [0]
visited = {0}
while True:
  nex = A[route[-1]] - 1
#  print(route[-1]," -> ",nex)
  if nex in visited:
#    print(nex,"is already visited")
    loopstart = route.index(nex)
#    print("loopstart =",loopstart)
    break
  else:
    visited.add(nex)
    route += [nex]
    
#print("route",route)

before_loop,one_loop = route[:loopstart],route[loopstart:]
#print("before_loop",before_loop)
#print("one_loop",one_loop)

if K <= len(before_loop) - 1:
  print(before_loop[K] + 1)
else:
  K -= len(before_loop)
  K %= len(one_loop)
  print(one_loop[K] + 1)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
h,w=map(int,input().split())
s=[list(input())for i in range(h)]
a=[[float("inf")]*w for i in range(h)]
b=[[False]*w for i in range(h)]
def f(x,y,t):
    if 0<=x<h and 0<=y<w:
        if s[x][y]=="#":
            if b[x][y]==False:
                a[x][y]=0
                b[x][y]=True
                f(x,y+1,1)
                f(x+1,y,1)
                f(x-1,y,1)
                f(x,y-1,1)
        else:
            if a[x][y]>t and t<h+w:
                a[x][y]=t
                f(x,y+1,t+1)
                f(x+1,y,t+1)
                f(x-1,y,t+1)
                f(x,y-1,t+1)
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            f(i,j,0)
            break
print(max(max(i)for i in a))

### FIXED CODE ###

import numpy as np
from scipy.ndimage import distance_transform_cdt as d
h,w=map(int,input().split())
s=[[1 if i=="." else 0 for i in input()]for i in range(h)]
a=d(s,metric='taxicab')
print(a.max())
### BUGGY CODE ###

N,K = map(int, input().split())
lst = list(map(int, input().split()))
dp = [0 for i in range(N)]
for i in range(1,N):
    mn = 999999999999999999
    for j in range(1,K+1):
        if i-j >= 0:
            mn = min(mn,dp[i - j] + abs(lst[i] - lst[i - j]))
        else:
            break
    dp[i] = mn
print(dp[-1])

### FIXED CODE ###

N,K = map(int, input().split())
lst = list(map(int, input().split()))
dp = [0 for i in range(N)]
for i in range(1,N):
    mn = 999999999999999999
    for j in range(max(i-K,0), i):
        mn = min(mn,dp[j] + abs(lst[i] - lst[j]))
    dp[i] = mn
print(dp[-1])
### BUGGY CODE ###

#flog2
n,k=map(int,input().split())
lists=list(map(int,input().split()))
mini_list=[0 for i in range(n+1)]
#mini_list[i]=iだんめに行くまでに払う最小のコスト
#帰るには一段上がるか、、、、、K段上がるかのK通りで、それぞれの値を計算してそれのmin値を採用すればいい
mini_list[1]=0
mini_list[2]=abs(lists[0]-lists[1])
for i in range(3,n+1):
    a=10**10
    for j in range(1,k+1):
        if   i>j :
            a=min(a,mini_list[i-j]+abs(lists[i-1]-lists[i-1-j]))
    mini_list[i]=a
print(mini_list[-1])

### FIXED CODE ###

#flog2
n,k=map(int,input().split())
lists=list(map(int,input().split()))
mini_list=[0 for i in range(n+1)]
#mini_list[i]=iだんめに行くまでに払う最小のコスト
#帰るには一段上がるか、、、、、K段上がるかのK通りで、それぞれの値を計算してそれのmin値を採用すればいい
mini_list[1]=0
mini_list[2]=abs(lists[0]-lists[1])
for i in range(3,n+1):
    a=10**10
    for j in range(1,k+1):
        if   i>j :
            a=min(a,mini_list[i-j]+abs(lists[i-1]-lists[i-1-j]))
        else:
            break
    mini_list[i]=a
print(mini_list[-1])
### BUGGY CODE ###

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

import bisect
import array


def solve():
    n, m, q = map(int, input().split())
    nl = [[] for j in range(n + 1)]
    for i in range(m):
        l, r = map(int, input().split())
        bisect.insort_left(nl[l], r)
    table = [array.array("i", [0] * (n + 1)) for j in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            table[i][j] = bisect.bisect_right(nl[i], j)

    s = array.array("i", [0] * q)
    for i in range(q):
        l, r = map(int, input().split())
        for j in range(l, r + 1):
            s[i] += table[j][r] - table[j][l - 1]
    print("\n".join([str(e) for e in s]))


if __name__ == "__main__":
    solve()


### FIXED CODE ###

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

import bisect
import array


def solve():
    n, m, q = map(int, input().split())
    nl = [[0 for i in range(n + 1)] for j in range(n + 1)]
    for e in [input().split() for _ in range(m)]:
        l, r = int(e[0]), int(e[1])
        nl[l][r] += 1
    table = [array.array("i", [0] * (n + 2)) for j in range(n + 2)]
    ran = array.array("i", range(n + 1))
    for i in ran:
        for j in ran:
            table[i][j + 1] = table[i][j] + nl[i][j]

    for i, e in enumerate([input().split() for _ in range(q)]):
        l, r = int(e[0]), int(e[1])
        ans = 0
        for j in range(l, r + 1):
            ans += table[j][r + 1] - table[j][l]
        print(ans)


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

# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(N):
    if i % 2 == 0:
        ans.append(A[i])
    else:
        ans = [A[i]] + ans
if N % 2 != 0:
    print(*ans[::-1])
else:
    print(*ans)

### FIXED CODE ###

# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
if N % 2 != 0:
    for i in range(N-1, -1, -2):
        print(A[i], end=" ")
    for i in range(1, N, 2):
        print(A[i], end=" ")
else:
    for i in range(N-1, 0, -2):
        print(A[i], end=" ")
    for i in range(0, N, 2):
        print(A[i], end=" ")
### BUGGY CODE ###

n,s = map(int,input().split())
maxx = s // 10000
maxy = s // 5000 
isloop = True
for x in range(maxx+1):
    
    if(isloop==False):
        break
    xv = x*10000
    for y in range(maxy+1):
        
        if(isloop==False):
            break
        yv = y*5000
        xysum = xv+yv
        if(xysum > s):
            continue
        
        z = (s-(xysum))//1000
        if((x+z+y)==n):
            print(x,y,z)
            isloop=False
            break

if(isloop==True):
    print(-1,-1,-1)

### FIXED CODE ###

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

isloop = True
for x in range(2001):
    
    if(isloop==False):
        break
    xv = x*10000
    for y in range(2001):
        
        if(isloop==False):
            break
        yv = y*5000
        xysum = xv+yv
        if(xysum > s):
            continue
        
        z = (s-(xysum))//1000
        if((x+z+y)==n):
            print(x,y,z)
            isloop=False
            break

if(isloop==True):
    print(-1,-1,-1)
### BUGGY CODE ###

import math

k = int(input())
total = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      total+=math.gcd(math.gcd(a, b), c)
print(total)

### FIXED CODE ###

def main():
  from math import gcd
  k = int(input())
  
  total = 0
  for a in range(1,k+1):
    for b in range(1,k+1):
      temp = gcd(a, b)
      for c in range(1,k+1):
        total+= gcd(temp, c)
  print(total)
main()
### BUGGY CODE ###

s = input()
t = input()

c=0
j=-1
k=1

#print(len(s))

#t
for i in range(0,len(t)):
  while True:
    j=j+1
    c=c+1

    if j>=len(s):
#      print("折り返し")
#      print(j)
      #jがお尻まで行ったら先頭に戻る
      j=0

#    print(j)
#    print(c)
    
    if t[i:i+1]==s[j:j+1]:
#      print("hit")
      #kはもう一度一文字めからカウントし直し
      k=1
      break
    else:
      #hitしなかった場合、index　カウントアップ
      k=k+1
      #一周回ってもヒットしなかったらエラー
      if k>len(s)+1:
        print("-1")
        exit()
print(c)


### FIXED CODE ###

s = input()
t = input()

x = len(s)
y = len(t)

a = 0
b = x
c = 0
a0 = 0


for i in range(0,y):
  while True:
    #先頭からの位置
    a=s.find(t[i:i+1],a0)+1
    if a <= 0:
      a=s.find(t[i:i+1])+1
    if a <= 0:
      print("-1")
      exit()
    
    if a<=a0:
      c=c+a+b
    else:
      c=c+a-a0
    b=x-a
    a0=a
    break
    
print(c)
### BUGGY CODE ###

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""

#B
import queue
n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a].append([b,c])
    v[b].append([a,c])
Q,k = LI()
d = [-1 for i in range(n)]
d[k-1] = 0
q = queue.Queue()
q.put(k-1)
while q:
    x = q.get()
    for y,c in v[x]:
        if d[y] == -1:
            d[y] = d[x]+c
            q.put(y)
for i in range(Q):
    x,y = LI()
    x -= 1
    y -= 1
    print(d[x]+d[y])
#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""

#B
def dijkstra(k):
    d[k] = 0
    q = [[0,k]]
    while q:
        dx,x = heappop(q)
        for y,c in v[x]:
            if d[y] > dx+c:
                d[y] = dx+c
                heappush(q,[d[y],y])

n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a].append([b,c])
    v[b].append([a,c])
q,k = LI()
d = [float("inf") for i in range(n)]
dijkstra(k-1)
for i in range(q):
    x,y = LI()
    x -= 1
    y -= 1
    print(d[x]+d[y])
#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T
### BUGGY CODE ###

# coding: utf-8
n,m=map(int,input().split())
edge=[]
for i in range(m):
    a,b,c=map(int,input().split())
    edge.append((a-1,b-1,-c))
inf=99999999999999999999
d=[inf for i in range(n)]
d[0]=0
count=0
while True:
    count+=1
    if count==n:
        tmp=d[n-1]
    update=False
    for i in range(m):
        f,t,cost=edge[i]
        if(d[t]>d[f]+cost):
            d[t]=d[f]+cost
            update=True
    if count==n and tmp!=d[n-1]:
        print('inf')
        break
    if not update:
        print(-d[n-1])
        break
else:
    print(-d[n-1])

### FIXED CODE ###

# coding: utf-8
n,m=map(int,input().split())
edge=[]
for i in range(m):
    a,b,c=map(int,input().split())
    edge.append((a-1,b-1,-c))
inf=99999999999999999999
d=[inf for i in range(n)]
d[0]=0
count=0
while count<n+1:
    count+=1
    if count==n:
        tmp=d[n-1]
    update=False
    for i in range(m):
        f,t,cost=edge[i]
        if(d[t]>d[f]+cost):
            d[t]=d[f]+cost
            update=True
    if count==n and tmp!=d[n-1]:
        print('inf')
        break
    if not update:
        print(-d[n-1])
        break
else:
    print(-d[n-1])
### BUGGY CODE ###

L, R = list(map(int, input().split()))

R = min(R, L+4038)

ans =  2018

for i in range(L, R+1):
    for j in range(i+1, R+1):
        x = i*j%2019
        ans = min(ans, x)
print(ans)

### FIXED CODE ###

L, R = list(map(int, input().split()))

R = min(R, L+4038)

ans =  2018

for i in range(L, R+1):
    for j in range(i+1, R+1):
        x = i*j%2019
        ans = min(ans, x)
print(ans)
### BUGGY CODE ###

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

dp = [0]*n

dp[1] = abs(h[1]-h[0])
for i in range(2, n):
  dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(i+1,k+1))])
  #for j in range(1,min(i+1,k+1)):
   # if j == 1:
    #  dp[i] = dp[i-1]+abs(h[i]-h[i-1])
    #print([i,j], dp[i-j]+abs(h[i]-h[i-j]), dp[i])
    #dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]))
#print(h)
print(dp[-1])

### FIXED CODE ###

def main():
  n, k = map(int, input().split())
  h = [int(n) for n in input().split()]
  dp = [0]*n
  for i in range(1, n):
    dp[i] = min([dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i)])  
  print(dp[-1])

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

# coding: utf-8
# Your code here!

import time

t = time.time()
n,k = map(int,input().split())

s = input()

now = s[0]
tmp = 0

h = []
if s[0]=="0":
    h.append(0)

for i in s:
    if i != now:
        now = i
        h.append(tmp)
        tmp=0
    tmp+=1
h.append(tmp)

ans = 0

for i in range(0,max(len(h),len(h)-k),2):
    ans = max(ans,sum(h[i:i+k*2+1]))
    
print(ans)

### FIXED CODE ###

# coding: utf-8
# Your code here!

import numpy as np

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

s = input()

now = s[0]
tmp = 0

h = []
if s[0]=="0":
    h.append(0)

for i in s:
    if i != now:
        now = i
        h.append(tmp)
        tmp=0
    tmp+=1
h.append(tmp)

h = np.array(h)

ans = 0

for i in range(0,max(len(h),len(h)-k),2):
    ans = max(ans,np.sum(h[i:i+k*2+1]))
    
print(ans)
### BUGGY CODE ###

import sys

def solve(N: int, K: int, A: "List[int]"):
    # 最小値は絶対1になる
    cur = K
    answer = 1
    while K < N:
        cur+=K-1
        answer +=1
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

N,K = (int(i) for i in input().split())
a = [int(x) for x in input().split()]

b= a.index(1)+1

if b/(K-1) == 0:
    answer = -(-(N-1)//(K-1)) +1

else:
    answer = -(-(N-1)//(K-1))

print(answer)
### BUGGY CODE ###

#import numpy as np
N = int(input())
A = list(map(int,input().split()))
#output = np.prod(A)
AA=1
for i in range(N):
  #print(A[i])
  AA = AA * A[i]
a = pow(10,18)
print(AA if abs(AA) <= a else -1)

### FIXED CODE ###

import sys
N = int(input())
A = list(map(int,input().split()))
A.sort()
mul = A[0]
for i in range(1,N):
  mul *= A[i]
  if mul > 10**18:
    print(-1)
    sys.exit()
print(mul)
### BUGGY CODE ###

n, x, y = map(int, input().split())
a = []

for i in range(1, n + 1):
    if i == 1:
        a.append([2])
    elif i == n:
        a.append([n - 1])
    else:
        a.append([i - 1, i + 1])
a[x - 1].append(y)
a[y - 1].append(x)

d = {}
for i in range(n - 1):
    d[i + 1] = 0

pair = set()

def solve(s):
    que = [a[s - 1]]
    visit = [s]
    depth = 0

    while que != []:
        depth += 1
        nn = que[0]
        que = que[1:]
        adj = []
        p = []
        for i in nn:
            if i not in visit:
                if (i, s) not in pair:
                    d[depth] += 1
                    pair.add((s, i))
                    p.append((s, i))
                adj = adj + a[i-1]
            visit.append(i)
        if adj != []:
            que.append(adj)

for i in range(n):
    solve(i + 1)

for i in range(n - 1):
    print(d[i + 1])

### FIXED CODE ###

from collections import deque

n, x, y = map(int, input().split())
a = []

for i in range(1, n + 1):
    if i == 1:
        a.append([2])
    elif i == n:
        a.append([n - 1])
    else:
        a.append([i - 1, i + 1])
a[x - 1].append(y)
a[y - 1].append(x)

d = {}
for i in range(n - 1):
    d[i + 1] = 0

def solve(s):
    queue = deque()
    queue.append(a[s - 1])
    visit = set()
    visit.add(s)
    depth = 0

    while queue:
        depth += 1
        nn = queue.popleft()
        adj = []
        for i in nn:
            if i not in visit:
                d[depth] += 1
                adj = adj + a[i-1]
            visit.add(i)
        if adj != []:
            queue.append(adj)

for i in range(n):
    solve(i + 1)

for i in range(n - 1):
    print(d[i + 1] // 2)
### BUGGY CODE ###

def main():
	X = int(input())
	cur = 0
	p = 0
	for _ in range(X):
		if cur == p:
			cur += 1
			p = 1
		else:
			p += 1
	print(cur)


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
	X = int(input())
	i = 1
	while (i*(i+1))//2 < X:
		i += 1
	print(i)


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

H = int(input())
a = [H]
i = 0
while a != [1]*len(a):
    a = a[1:]

    a += [int(H / 2) for i in range(2)]
    H = a[0]

    i += 1
print(i+sum(a))


### FIXED CODE ###

h = int(input())
ans = 0
while True:
    h = h // 2
    ans += 1
    if h == 0:
        break
print(2**ans-1 )
### BUGGY CODE ###


N = int(input())
x = [int(input()) for i in range(N)]

i=0
while i < N:
    if x[i]==0:
        i+=1
        continue
    j=i+1
    while j < N:
        if x[i]==x[j]:
            x[i]=x[j]=0
            break
        j+=1
    i+=1

res=0
for i in x:
    if i!=0:
        res+=1

print(res)

### FIXED CODE ###


N = int(input())
x = [int(input()) for i in range(N)]

x.sort()
i=0
while i < N-1:
    if x[i]==x[i+1]:
        del x[i+1]
        del x[i]
        N-=2
        continue
    i+=1
print(len(x))
### BUGGY CODE ###

num = list(map(int,input().split()))
string = input()
s_key=[]
#count=[]

for i in range(num[1]):
    s_key.append(list(map(int,input().split())))
    '''
for i in range(num[0]):
    if i==0:
        count.append(0)
    else:
        if (string[i-1]=='A' and string [i]=='C'):
            count.append(count[i-1]+1)
        else:
            count.append(count[i-1])
'''
for k in range(num[1]):
   # result=count[s_key[k][1]-1]-count[s_key[k][0]-1]
    #print(result)
   newone=string[s_key[k][0]-1:s_key[k][1]]
   print(newone.count('AC'))

### FIXED CODE ###

num = list(map(int,input().split()))
string = input()
s_key=[]
count=[]
for i in range(num[1]):
    s_key.append(list(map(int,input().split())))
for i in range(num[0]):
    if i==0:
        count.append(0)
    else:
        if (string[i-1]=='A' and string [i]=='C'):
            count.append(count[i-1]+1)
        else:
            count.append(count[i-1])
for k in range(num[1]):
    result=count[s_key[k][1]-1]-count[s_key[k][0]-1]
    print(result)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N=int(input())
A=[list(map(int,input().split())) for i in range(N)]

B=[[] for i in range(N)]
for i in range(N):
    for j in range(N):
        if A[i][j]==1:
            B[i].append(j)
        
mod=10**9+7

#bitDP
DPLIST=[-1]*(2**N)
DPLIST[2**N-1]=1

def dp(NOW,x):

    if DPLIST[NOW]!=-1:
        return DPLIST[NOW]

    ANS=0

    for b in B[x]:
        if NOW & (1<<b)==0:
            ANS=(ANS+dp(NOW+2**b,x+1))%mod

    DPLIST[NOW]=ANS
    return ANS

print(dp(0,0))

### FIXED CODE ###

import sys
input = sys.stdin.readline

N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
mod=10**9+7

#bitDP
DPLIST=[-1]*(2**N)
DPLIST[2**N-1]=1

def dp(NOW,x):

    if DPLIST[NOW]!=-1:
        return DPLIST[NOW]

    ANS=0

    for i in range(N):
        if A[x][i]==1 and NOW & (1<<i) ==0:
            ANS+=dp(NOW+(1<<i),x+1)

    ANS%=mod
    DPLIST[NOW]=ANS
    return ANS

print(dp(0,0))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
c = [A.count(i + 1) for i in range(N)]
s = 0

for val in c:
  s = s + val * (val - 1) // 2

for val in A:
  m = c[val - 1] - 1
  print(s - m)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
c = [0 for i in range(N)]

for i in range(N):
  c[A[i] - 1] += 1

ans = [c[i] * (c[i] - 1) // 2 for i in range(N)]
s = sum(ans)

for val in A:
  m = c[val - 1] - 1
  print(s - m)
### BUGGY CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
before=1
for i in range(K):
    before*=A[i]
point=1
for i in range(N-K):
    point=before
    point//=A[i]
    point*=A[i+K]
    print("Yes" if point>before else "No")
    before=point

### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N-K):
    print("Yes" if A[i+K]>A[i] else "No")
### BUGGY CODE ###

n = int(input())
A=list(map(int, input().split()))
t=0
for i in range(n):
  for j in range(i+1, n):
    if abs(i-j)==A[i]+A[j]:
      t+=1
print(t)

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
L = [i+x for i, x in enumerate(A)]
R = [i-x for i, x in enumerate(A) if i-x > 0]

from collections import Counter
P = Counter(L)
Q = Counter(R)
 
ans = 0
for k, v in P.items():
  if k in Q:
    ans += v*Q[k]
print(ans)
### BUGGY CODE ###

N=int(input())
A=[]
B=[]
for i in range(N):
	if i%2==0:
		A.append(int(input()))
	else:
		B.append(int(input()))
		
A=sorted(A)
B=sorted(B)
C=sorted(A+B)
#ここまでNlogN
c=0
for a in A:
	if C.index(a)%2==1:
		c+=1
print(c)

### FIXED CODE ###

N=int(input())
A=[]
B=[]
for i in range(N):
	if i%2==0:
		A.append(int(input()))
	else:
		B.append(int(input()))
		
A=sorted(A)
B=sorted(B)
C=sorted(A+B)
#ここまでNlogN
c=0
j=0
for i in range(N):
	if j>=len(A):
		break
	if A[j]==C[i]:
		if i%2==1:
			c+=1
		j+=1
print(c)
### BUGGY CODE ###

h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]
s = [[0]*w for i in range(h)]
for i in range(h):
    count = 0
    for j in range(w):
        if (a[i][j]=='.'):
            count += 1
            
        else:
            for k in range(j-1,j-count-1,-1):
                s[i][k]=count
            count = 0
    for k in range(w-1,w-count-1,-1):
        s[i][k]=count
    count = 0

t = [[0]*w for i in range(h)]
for i in range(w):
    count = 0
    for j in range(h):
        if (a[j][i]=='.'):
            count += 1
            
        else:
            for k in range(j-1,j-count-1,-1):
                t[k][i]=count
            count = 0
    for k in range(h-1,h-count-1,-1):
        t[k][i]=count
    count = 0

ans = 0
for i in range(h):
    for j in range(w):
        if (s[i][j]!=0):
            if (s[i][j]+t[i][j]-1 > ans):
                ans = s[i][j]+t[i][j]-1
print(ans)

### FIXED CODE ###

h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]
s = [[0]*w for i in range(h)]
for i in range(h):
    count = 0
    for j in range(w):
        if (a[i][j]=='.'):
            count += 1
            
        else:
            for k in range(j-1,j-count-1,-1):
                s[i][k]=count
            count = 0
    for k in range(w-1,w-count-1,-1):
        s[i][k]=count
    count = 0

t = [[0]*w for i in range(h)]
for i in range(w):
    count = 0
    for j in range(h):
        if (a[j][i]=='.'):
            count += 1
            
        else:
            for k in range(j-1,j-count-1,-1):
                t[k][i]=count
            count = 0
    for k in range(h-1,h-count-1,-1):
        t[k][i]=count
    count = 0

ans = 0
for i in range(h):
    for j in range(w):
        if (s[i][j]!=0):
            if (s[i][j]+t[i][j]-1 > ans):
                ans = s[i][j]+t[i][j]-1
print(ans)
### BUGGY CODE ###

l = list(map(int,input().split()))
n, k = l[0], l[1]
a = list(map(int,input().split()))

for i in range(k, n):
    bef, cur = 1, 1
    for ii in range(k):
        bef *= a[i-ii-1]
        cur *= a[i-ii]

    if cur > bef:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

l = list(map(int,input().split()))
n, k = l[0], l[1]
a = list(map(int,input().split()))

for i in range(k, n):
    if a[i] > a[i-k]:
        print('Yes')
    else:
        print('No')