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

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

N_K = [K for i in range(N)]
for a in A:
    for j, n_k in enumerate(N_K):
        N_K[j] = n_k-1 if a-1 != j else n_k

for n_k in N_K:
    if n_k <= 0:
        print("No")
    else:
        print("Yes")


### FIXED CODE ###

N, K, Q = map(int, input().split())
A = [0]*N
# print(A)

for i in range(Q):
    A[int(input())-1] +=1
    # print(A)

for i in range(N):
    if K-Q+A[i] <= 0:
        print("No")
    else:
        print("Yes")
### BUGGY CODE ###

import math

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)

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

dic = {}
for i in range(N):
  if A[i] in dic:
    dic[A[i]] += 1
  else:
    dic[A[i]] = 1

ans = 0
for k in dic:
  tmp  =dic[k]
  if tmp >= 2:
    ans += C(tmp, 2)

for i in range(N):
  tmp = dic[A[i]]
  if tmp == 1:
    print(ans)
  if tmp == 2:
    print(ans - 1)
  if tmp > 2:
    print(ans - (C(tmp, 2) - C(tmp-1, 2)))

### FIXED CODE ###

import math

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

dic = {}
for i in range(N):
  if A[i] in dic:
    dic[A[i]] += 1
  else:
    dic[A[i]] = 1

memo = [0 for i in range(10 ** 6)]
ans = 0
for k in dic:
  tmp  =dic[k]
  if tmp >= 2:
    if memo[tmp] == 0:
      memo[tmp] = tmp * (tmp - 1) // 2
      ans += memo[tmp]
    else:
      ans += memo[tmp]

for i in range(N):
  tmp = dic[A[i]]
  if tmp == 1:
    print(ans)
  elif tmp == 2:
    print(ans - 1)
  else:
    print(ans - tmp * (tmp - 1) // 2 + (tmp - 1) * (tmp - 2) // 2)
### BUGGY CODE ###

import numpy as np

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

res = np.zeros((N, N), dtype=int)

for _ in range(M):
    l, r = map(int, input().split())
    res[:l, r-1:] += 1

query = []
for _ in range(Q):
    query.append(list(map(int, input().split())))

for q in query:
    print(res[q[0]-1, q[1]-1])


### FIXED CODE ###

# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N, M, Q = ds_in()

section = np.zeros((N, N), dtype=int)
for _ in range(M):
    p, q = ds_in()
    section[N-p, q-1] += 1

cumlist = np.cumsum(np.cumsum(section, axis=0), axis=1)

query = []
for _ in range(Q):
    query.append(ds_in())

for q in query:
    print(cumlist[N-q[0], q[1]-1])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
class Combination:
  def __init__(self, n_max, mod=10**9+7):
    self.mod = mod
    self.modinv = self.make_modinv_list(n_max)
    self.fac, self.facinv = self.make_factorial_list(n_max)

  def __call__(self, n, r):
    return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

  def make_factorial_list(self, n):
    # 階乗のリストと階乗のmod逆元のリストを返す O(n)
    # self.make_modinv_list()が先に実行されている必要がある
    fac = [1]
    facinv = [1]
    for i in range(1, n+1):
      fac.append(fac[i-1] * i % self.mod)
      facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
    return fac, facinv

  def make_modinv_list(self, n):
    # 0からnまでのmod逆元のリストを返す O(n)
    modinv = [0] * (n+1)
    modinv[1] = 1
    for i in range(2, n+1):
        modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
    return modinv

N,K = map(int,input().split())
adj = [ [ ]for _ in range(N) ]
comb = Combination(10**5)

def nPr(n,r):
  if n < r: return 0
  return comb(n, r) * comb.fac[r]

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

def dfs(v, p=-1):
  global ans
  c = 0
  for nei in adj[v]:
    if nei == p: continue
    c += 1
    dfs(nei, v)

  nk = K-1 if p==-1 else K-2
  ans *= nPr(nk, c)
  ans %= 10**9+7

ans = K
dfs(0)
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
class Combination:
  def __init__(self, n_max, mod=10**9+7):
    self.mod = mod
    self.modinv = self.make_modinv_list(n_max)
    self.fac, self.facinv = self.make_factorial_list(n_max)

  def __call__(self, n, r):
    return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

  def make_factorial_list(self, n):
    # 階乗のリストと階乗のmod逆元のリストを返す O(n)
    # self.make_modinv_list()が先に実行されている必要がある
    fac = [1]
    facinv = [1]
    for i in range(1, n+1):
      fac.append(fac[i-1] * i % self.mod)
      facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
    return fac, facinv

  def make_modinv_list(self, n):
    # 0からnまでのmod逆元のリストを返す O(n)
    modinv = [0] * (n+1)
    modinv[1] = 1
    for i in range(2, n+1):
        modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
    return modinv

N,K = map(int,input().split())
adj = [ [ ]for _ in range(N) ]
comb = Combination(10**5)

def nPr(n,r):
  if n < r: return 0
  return comb(n, r) * comb.fac[r]

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

def dfs(v, p=-1):
  global ans
  c = 0
  for nei in adj[v]:
    if nei == p: continue
    c += 1
    dfs(nei, v)

  nk = K-1 if p==-1 else K-2
  ans *= nPr(nk, c)
  ans %= 10**9+7

ans = K
dfs(0)
print(ans)
### BUGGY CODE ###

import collections

N = int(input())
B = list(map(int, input().split()))
temp = 0

setB = list(set(B))
num = len(setB)

for i in range(N):
  if i > 0:
    B[i-1] = temp
  temp = B[i]
  B[i] = 0
  res = 0
  for j in range(num):
    res += B.count(setB[j])*(B.count(setB[j])-1)/2
  print(int(res))

### FIXED CODE ###

N = int(input())
B = list(map(int, input().split()))
count = {}

for i in B:
  if i in count:
    count[i] += 1
  else:
    count[i] = 1
    
total = 0
for i in count:
  total += count[i]*(count[i]-1)/2
  
for i in range(N):
  k = count[B[i]]
  print(int(total-k+1))
### BUGGY CODE ###

import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


h, w = li()
grid = [lc() for _ in range(h)]

def left_right(grid, row, col, cnt, w):
    if col == w:
        return cnt

    elif grid[row][col] == "#":
        return cnt

    else:
        cnt = left_right(grid, row, col+1, cnt+1, w)

    lr[row][col] = cnt
    return cnt


def top_bottom(grid, row, col, cnt, h):
    if row == h:
        return cnt

    elif grid[row][col] == "#":
        return cnt

    else:
        cnt = top_bottom(grid, row+1, col, cnt+1, h)

    tb[row][col] = cnt
    return cnt

lr = [[0]*w for _ in range(h)]
tb = [[0]*w for _ in range(h)]

for row in range(h):
    for col in range(w):
        if grid[row][col] == "." and lr[row][col] == 0:
            left_right(grid, row, col, 0, w)

for col in range(w):
    for row in range(h):
        if grid[row][col] == "." and tb[row][col] == 0:
            top_bottom(grid, row, col, 0, h)

ans = 0
for row in range(h):
    for col in range(w):
        ans = max(ans, lr[row][col] + tb[row][col])

print(ans-1)

### FIXED CODE ###

import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


h, w = li()
grid = [lc() for _ in range(h)]


lr = [[0]*w for _ in range(h)]
tb = [[0]*w for _ in range(h)]

for row in range(h):
    for col in range(w):
        if col == 0:
            lr[row][col] = 1 if grid[row][col] == "." else 0

        else:
            if grid[row][col] == "#":
                continue

            else:
                lr[row][col] = lr[row][col-1] + 1

for row in range(h):
    for col in range(w-2, -1, -1):
        if lr[row][col] == 0:
            continue
        else:
            lr[row][col] = max(lr[row][col+1], lr[row][col])

for col in range(w):
    for row in range(h):
        if row == 0:
            tb[row][col] = 1 if grid[row][col] == "." else 0

        else:
            if grid[row][col] == "#":
                continue
            else:
                tb[row][col] = tb[row-1][col] + 1

for col in range(w):
    for row in range(h-2, -1, -1):
        if tb[row][col] == 0:
            continue
        else:
            tb[row][col] = max(tb[row+1][col], tb[row][col])

ans = 0
for row in range(h):
    for col in range(w):
        ans = max(ans, lr[row][col] + tb[row][col])

print(max(0, ans-1))
### BUGGY CODE ###

S = list(input())

DIVIDER = 13

mod_digit = [i % DIVIDER for i in range(10)]
mod_level = []
tmp = 1
for _ in range(len(S)):
    mod_level.append(tmp % DIVIDER)
    tmp *= 10
mod_level = mod_level[::-1]

memo = [[0] * DIVIDER for _ in range(len(S) + 1)]
# def dp(pos, mod_tmp):
for idx in range(len(S) + 1):
    # if pos < 0:
    #     if mod_tmp == 5:
    #         return 1
    #     else:
    #         return 0
    # elif memo[pos][mod_tmp] != None: return memo[pos][mod_tmp]
    if idx == 0:
        for mod_tmp in range(DIVIDER):
            if mod_tmp == 5:
                memo[0][mod_tmp] = 1
            else:
                memo[0][mod_tmp] = 0
    else:
        pos = idx - 1
        for mod_tmp in range(DIVIDER):
            ret = 0
            if S[pos] == '?':
                for d in range(10):
                    mod_nxt = (mod_tmp + mod_digit[d] * mod_level[pos]) % DIVIDER
                    ret += memo[idx - 1][mod_nxt]
            else:
                d = int(S[pos])
                mod_nxt = (mod_tmp + mod_digit[d] * mod_level[pos]) % DIVIDER
                ret += memo[idx - 1][mod_nxt]
            #
            memo[idx][mod_tmp] = ret % 1000000007

print(memo[len(S)][0])
            

### FIXED CODE ###

inf = 10 ** 18
P = 10 ** 9 + 7

S = input()
N = len(S)

tmp = 1
modrow = [1] * 6
for i in range(5):
    tmp = (tmp * 10) % 13
    modrow[1 + i] = tmp

modtab = [[None] * 10 for i in range(6)]
for i in range(6):
    for j in range(10):
        modtab[i][j] = (modrow[i] * j) % 13

# for modcol in modtab:
#     print("#", sorted(modcol))

# X + question === 5 (mod 13)
X = 0
q_idx = []
for i, Si in enumerate(S[::-1]):
    if Si == '?':
        q_idx.append(i)
    else:
        X = (X + modtab[i % 6][int(Si)]) % 13


M = len(q_idx)
ans_tab = [[0] * 13 for _ in range(M + 1)]

ans_tab[0][0] = 1
for i, idx in enumerate(q_idx):
    for src in range(13):
        for coeff in range(10):
            dst = (src + modtab[idx % 6][coeff]) % 13
            ans_tab[1 + i][dst] = (ans_tab[1 + i][dst] + ans_tab[i][src]) % P
        
# print("#", ans_tab[-1])
idx_ans = (5 - X) % 13
print(ans_tab[-1][idx_ans])
### BUGGY CODE ###

import math,itertools,fractions,heapq,bisect,sys,copy,collections

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[S() for _ in range(h)]

  ans=0
  visited=[[-1 for __ in range(w)] for _ in range(h)]
  q=collections.deque()
  for i in range(h):
    for j in range(w):
      if field[i][j]=='#':
        continue
      q.append((i,j,0))
      for _i in range(h):
        for _j in range(w):
          visited[_i][_j]=-1
      while len(q)>0:
        y,x,c=q.popleft()
        visited[y][x]=c

        for dy,dx in ((-1,0),(0,1),(1,0),(0,-1)):
          ny=y+dy
          nx=x+dx
          if 0<=ny<h and 0<=nx<w:
            if field[ny][nx]=='#':
              continue
            if visited[ny][nx]!=-1:
              continue
            _ans=c+1
            q.append((ny,nx,c+1))
      ans=max(ans,_ans)
  return ans

# main()
print(main())


### FIXED CODE ###

import sys,collections

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[S() for _ in range(h)]

  ans=0
  visited=[[-1 for __ in range(w)] for _ in range(h)]
  q=collections.deque()
  for i in range(h):
    for j in range(w):
      if field[i][j]=='#':
        continue
      q.append((i,j))
      for _i in range(h):
        for _j in range(w):
          visited[_i][_j]=-1
      visited[i][j]=0
      _ans=0
      while q:
        y,x=q.popleft()

        for dy,dx in ((-1,0),(0,1),(1,0),(0,-1)):
          ny=y+dy
          nx=x+dx
          if not 0<=ny<h:
            continue
          if not 0<=nx<w:
            continue
          if field[ny][nx]=='#':
            continue
          if visited[ny][nx]!=-1:
            continue
          _ans=visited[y][x]+1
          visited[ny][nx]=_ans
          q.append((ny,nx))
      ans=max(ans,_ans)
  return ans

# main()
print(main())
### BUGGY CODE ###

N = int(input())
As = list(map(int, input().split()))
o = [0]*(N**2)
INF = 10**19
from itertools import accumulate
aa = [0] + list(accumulate(As))

for i in range(1, N+1):
    for j in range(N-i+1):
        span = (i-1)*N+j
        # 長さi, 開始位置jの合成コスト+構成要素の和
        if i == 1:
            o[span] = As[j]
            continue
        C = INF
        for k in range(1, i):
            # 長さ,開始位置=(k,j)と(i-k,j+k)
            span1, span2 = (k-1)*N+j, (i-k-1)*N+j+k
            C = min(C, o[span1]+o[span2])
        o[span] = C + aa[(j+i-1)+1] - aa[(j-1)+1]
print(o[span]-aa[-1])

### FIXED CODE ###

N = int(input())
As = list(map(int, input().split()))
ma = sum(As)
o = dict()
INF = 10**19
from itertools import accumulate
aa = [0] + list(accumulate(As))

for i in range(N):
    for j in range(N-i):
        span = i*N+j
        # 長さi+1, 開始位置jの合成コスト+構成要素の和
        if i == 0:
            o[span] = As[j]
            continue
        C = INF
#        print(i,j,o)
        for k in range(i):
            # 長さk+1とi+1-(k+1)=i-kに分割
#            print(i,j,k*N+j, (i-k-1)*N+j+k, o)
            C = min(C, o[k*N+j]+o[(i-k-1)*N+j+k+1])
#        o[span] = C + sum(As[j:j+i+1])
        o[span] = C + aa[j+i+1] - aa[j]

print(o[span]-ma)
### BUGGY CODE ###

s = input()
t = input()
lenS = len(s)
lenT = len(t)

dp = [[0]*(lenT+1)for _ in range(lenS+1)]

for i in range(1,lenS+1):
  for j in range(1,lenT+1):
    if s[i-1]==t[j-1]:
      dp[i][j]=dp[i-1][j-1]+1
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j-1])
      
m = lenS
n = lenT
ans = ""
while m or n:
  if m:
    if dp[m][n] == dp[m-1][n]:
      m -= 1
      continue
  if n:
    if dp[m][n] == dp[m][n-1]:
      n -= 1
      continue
    else:
      m -= 1
      n -= 1
      ans = "".join([s[m],ans])
    continue
print(ans)    

### FIXED CODE ###

# LongestCommonSubsequences
import numpy as np
S = np.array([ord(i)-97 for i in input()], dtype=int)
T = np.array([ord(i)-97 for i in input()], dtype=int)
Ns = len(S)
Nt = len(T)
equal = np.equal.outer(S, T).astype(int)

dp = [np.zeros(Nt + 1, dtype=int)]
for i in range(Ns):
    x = dp[-1].copy()
    newDP = x.copy()
    newDP[1:] = np.maximum(x[:-1] + equal[i], newDP[1:])
    np.maximum.accumulate(newDP, out=newDP)
    dp.append(newDP)


ans = ""
i, j = Ns, Nt
while i > 0 and j > 0:
    if S[i-1] == T[j-1]:
        ans += chr(S[i-1]+97)
        i -= 1
        j -= 1
        continue
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    else:
        j -= 1

print(ans[::-1])
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
a = []
for i in range(1, N + 1):
	j = A.index(i)
	a.append(j + 1)
print(*a)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
a = [0] * N
for i in range(N):
	a[A[i] - 1] = i + 1
print(*a)
### BUGGY CODE ###

s = str(input())
mod = 2019
li = [int(s[-1])]
for i in range(len(s) - 1):
    li.append((li[-1] + int(s[-(2 + i)]) * (10 ** (i + 1))) % mod)
import collections
A=collections.Counter(li)
ans=0
for v in A.values():
    ans+=v*(v-1)//2
print(ans+li.count(0))




### FIXED CODE ###

s = str(input())
s=s[::-1]
mod = 2019
li = [0]*(len(s)+1)
cnt=1
for i in range(len(s)):
    li[i+1]=li[i] + int(s[i]) * cnt
    li[i+1]%=mod
    cnt*=10
    cnt%=mod
import collections
A=collections.Counter(li[1:]);ans=0
for u,v in A.items():
    ans+=v*(v-1)//2
    if u==0:
        ans+=v
print(ans)
### BUGGY CODE ###

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

prev = 0
ind = 0
for i in range(n - k + 1):
    nex =  sum(p[i:i+k])

    if prev < nex:
        prev = nex
        ind = i

total = 0
for i in range(ind, ind + k):
    total += (1 + p[i]) * (p[i] / 2) / p[i]

print(total)


### FIXED CODE ###

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

prev = sum(p[1:k])
current = sum(p[1:k])
ind = 0

for i in range(1, n - k + 1):
    current = current - p[i - 1] + p[i + k - 1]

    if prev < current:
        prev = current
        ind = i

total = 0
for i in range(ind, ind + k):
    total += p[i] / 2 + 0.5

print(total)
### BUGGY CODE ###

from collections import deque
h, w = map(int,input().split())
graph = [list(input()) for _ in range(h)]
finishied = [[False for _ in range(w)] for _ in range(h)]
y = [0, 0, 1,-1]
x = [1,-1, 0, 0]
q = deque([])
for i in range(h):
    for j in range(w):
        if graph[i][j] == "#":
            q.append((i,j,0))
while q:
    c = q.popleft()
    for i in range(4):
        nh = c[0]+y[i]
        nw = c[1]+x[i]
        if nh < 0 or nh >= h or nw < 0 or nw >= w or graph[nh][nw] == "#":continue
        graph[nh][nw] = "#"
        q.append((nh,nw,c[2]+1))
print(c[2])

### FIXED CODE ###

from collections import deque
h, w = map(int,input().split())
graph = []
finished = [[False for _ in range(w)] for _ in range(h)]
y = [0, 0, 1,-1]
x = [1,-1, 0, 0]
q = deque([])
for i in range(h):
    a = input()
    graph.append(a)
    for j in range(w):
        if a[j] == "#":
            q.append((i,j,0))
while q:
    c = q.popleft()
    for i in range(4):
        nh = c[0]+y[i]
        nw = c[1]+x[i]
        if nh < 0 or nh >= h or nw < 0 or nw >= w or graph[nh][nw] == "#" or finished[nh][nw]:continue
        finished[nh][nw] = True
        q.append((nh,nw,c[2]+1))
print(c[2])
### BUGGY CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
maxvalue=0
for i in range(N-K+1):
  maxvalue=max(maxvalue,sum(A[i:i+K]))
print((maxvalue+K)/2)

### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
summation=[0,A[0]]
for i in range(1,N):
  summation.append(summation[i]+A[i])

maxvalue=summation[K]
for i in range(1,1+N-K):
  maxvalue=max(maxvalue,summation[i+K]-summation[i])
print((maxvalue+K)/2)
### BUGGY 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
        N (int): 町の数
        K (int): テレポーターの使用回数
        A (list): テレポーターの転送先
    """
    # タブリング表の作成
    bit_num = math.ceil(math.log2(K))
    to = [A]
    for i in range(bit_num):
        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(bit_num):
        if ((K >> i) & 1):
            result = to[i][result-1]

    # 結果出力
    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)
### BUGGY CODE ###

S = input()
Q = int(input())

n = S
# r = S
# for i in range(Q):
#     op = input().split()
#     if len(op) == 1:
#         n, r = r, n
#     elif op[1] == "1":
#         n = op[2] + n
#         r = r + op[2]
#     else:
#         n = n + op[2]
#         r = op[2] + r
# print(n)

mode = 0
operations = []
for i in range(Q):
    operations.append(input().split())
for op in operations:
    if op[0] == "1":
        mode += 1
        mode %= 2
    elif int(op[1]) + mode == 2:
        n = "".join([n, op[2]])
    else:
        n = "".join([op[2], n])
if mode == 0:
    print(n)
else:
    print(n[::-1])

### FIXED CODE ###

from collections import deque
S = input()
Q = int(input())

n = S
mode = 0
operations = []
deq = deque(n)
for i in range(Q):
    operations.append(input().split())
for op in operations:
    if op[0] == "1":
        mode += 1
        mode %= 2
    elif int(op[1]) + mode == 2:
        deq.append(op[2])
    else:
        deq.appendleft(op[2])
if mode == 0:
    print("".join(deq))
else:
    print("".join(reversed(deq)))
### BUGGY CODE ###


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

count = 0
while True:
  x = 0
  for i in A:
    if i % 2 == 1:
      x = 1
  if x == 1:
    break
  else:
    for i in A:
      i /= 2
    count += 1

print(count)

### FIXED CODE ###

import numpy as np
N = int(input())
A = list(map(int,input().split()))
A = np.array(A)
count = 0
while True:
  x = 0
  for i in A:
    if i % 2 == 1:
      x = 1
  if x == 1:
    break
  else:
    A = A / 2
    count += 1

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

S = input()
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L+1):
    t += pow(10, l)*int(S[-l])
    i = t%mod
    dic[i] += 1

for k in dic.keys():
    num = dic[k]
    ans += num*(num-1)//2

print(ans)

### FIXED CODE ###

S = list(input())[::-1]
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L):
    t += pow(10, l, mod)*int(S[l])%mod
    t %= mod
    ans += dic[t]
    dic[t] += 1
    if t==0:
        ans += 1

print(ans)