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

n = int(input())
a = list(map(int,input().split()))
c = 0
for i in a:
    c ^= i

c = format(c,'b').zfill(50)

buf = []
for i in a:
    s = format(i,'b').zfill(50)
    ans = list(c)
    for j in range(len(s)):
        x = (int(ans[j])+int(s[j]))%2
        ans[j] = str(x)
    x = ''.join(ans)
    buf.append(int(x,2))
print(*buf)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
c = 0
for i in a:
    c ^= i

buf = []
for i in a:
    buf.append(c^i)
    
print(*buf)
### BUGGY CODE ###

N,price  = map(int,input().split())
answer = []
for i in range(N+1):
    if price<10000*i and len(answer) != 0 :
        break
    else:
        if(N-i+1)*5000>price-10000*i :
            for j in range(N-i+1):
                if price<10000*i+5000*j and len(answer) != 0:
                    break
                else:
                    if(N-i-j+1)*1000>price-10000*i-5000*j :
                        for k in range(N-i-j+1):
                            if price<10000*i+5000*j+1000*k and len(answer) != 0:
                                break
                            if N==i+j+k and price == 10000*i+5000*j+1000*k:
                                answer = [i,j,k]
if(len(answer)!=0):
    for i in range(3):
        print(answer[i], end = " ")
else:
    for i in range(3):
        print(-1, end = " ")
            

### FIXED CODE ###

N,Y=map(int,input().split())
for x in range(N+1):
    for y in range(N-x+1):
        z=N-x-y
        if 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
            print(x,y,z)
            exit()
print(-1,-1,-1)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in a:
    ans *= i
if ans > 10 ** 18:
    ans = -1
print(ans)

### FIXED CODE ###

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

if 0 in A:
    print(0)
    quit()

ans = 1
for a in A:
    ans *= a
    if ans > 1000000000000000000:
        print(-1)
        quit()

print(ans)
### BUGGY CODE ###

# テスト対象（ABC081A - Placing Marbles (https://atcoder.jp/contests/abs/tasks/abc081_a)
H,W = map(int, input().split())
A = 0
dp = []
mat = []
for h in range(H):
    dpr = [-1] * W
    for w, x in zip(range(W), input()):
        if x == "#":
            dpr[w] = 0
            mat += [(h, w, 0)]
    dp += [dpr]

def search(dp, mat, conf, nH, nW, cnt):
    if not conf:
        return
    if dp[nH][nW] < 0:
        mat.insert(0, (nH, nW, cnt+1))
        dp[nH][nW] = cnt+1

while len(mat) > 0:
    h, w, cnt = mat.pop()

    search(dp, mat, h > 0, h - 1, w, cnt)
    search(dp, mat, h < H-1, h + 1, w, cnt)
    search(dp, mat, w > 0, h , w - 1, cnt)
    search(dp, mat, w < W-1, h , w + 1, cnt)

print(cnt)


### FIXED CODE ###

from collections import deque
H,W = map(int, input().split())
A = 0
dp = [None] * H
mat = [None] * (H*W)
matS = matE = 0
for h in range(H):
    s = list(input())
    for w, x in zip(range(W), s):
        if x == "#":
            mat[matE] = (h, w, 0)
            matE+=1
    dp[h] = s

def search(dp, mat, nH, nW, cnt):
    global matE
    if dp[nH][nW] == ".":
        mat[matE] = (nH, nW, cnt+1)
        matE+=1
        dp[nH][nW] = "#"

while matS < matE:
    h, w, cnt = mat[matS]
    matS += 1

    if h > 0:
        search(dp, mat, h - 1, w, cnt)
    if h < H-1:
        search(dp, mat, h + 1, w, cnt)
    if w > 0:
        search(dp, mat, h , w - 1, cnt)
    if w < W-1:
        search(dp, mat, h , w + 1, cnt)

print(cnt)
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

def lcs(s, t):
  dp = [['' for _ in range(len(t)+1)] for _ in range(len(s)+1)]
  for i, si in enumerate(s, 1):
    for j, tj in enumerate(t, 1):
      dp[i][j] = max([''.join([dp[i-1][j-1], si]) if si==tj else '', dp[i-1][j], dp[i][j-1]], key=lambda x: len(x))
  return dp[-1][-1]

def main():
  s = input().strip()
  t = input().strip()
  print(lcs(s, t))


if __name__=='__main__':
  main()

### FIXED CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

# @profile
def calc_lcs(s, t):
  dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]
  # dp = numpy.zeros((len(s)+1, len(t)+1))
  for i, si in enumerate(s, 1):
    for j, tj in enumerate(t, 1):
      dp[i][j] = max((dp[i-1][j-1] + 1) if si==tj else 0, dp[i-1][j], dp[i][j-1])

  lcs = ''
  i, j = len(s), len(t)
  while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
      i -= 1
    elif dp[i][j] == dp[i][j-1]:
      j -= 1
    else:
      lcs = s[i-1] + lcs
      i -= 1
      j -= 1
  return lcs

def main():
  s = input().strip()
  t = input().strip()
  print(calc_lcs(s, t))


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

from itertools import combinations
from collections import deque
N,M = map(int,input().split())
maze = []
for i in range(N):
    maze.append(list(input()))
INF = -1
cost = [[INF]*M for _ in range(N)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
sx,sy = 0,0
gx,gy = 0,0
ls = []
for i in range(N):
    for j in range(M):
        if maze[i][j] != "#":
            ls.append([i,j])
def bfs():
    P = deque()
    P.append([sx,sy])
    cost[sx][sy] = 0
    while len(P) != 0:
        p = P.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < N and 0 <= ny < M and maze[nx][ny] != "#" and cost[nx][ny] == INF:
                P.append([nx,ny])
                cost[nx][ny] = cost[p[0]][p[1]]+1
    return cost[gx][gy]
comb = list(combinations(list(range(len(ls))),2))
ans = 0
for i in range(len(comb)):
    cost = [[INF]*M for _ in range(N)]
    sx,sy = ls[comb[i][0]][0],ls[comb[i][0]][1]
    gx,gy = ls[comb[i][1]][0],ls[comb[i][1]][1]
    res = bfs()
    if res > ans:
        ans = res
print(ans)

### FIXED CODE ###

from collections import deque
H,W = map(int,input().split())
maze = []
dx = [1,0,-1,0]
dy = [0,1,0,-1]
for i in range(H):
    maze.append(list(input()))
def bfs(sx,sy):
    INF = -1
    cost = [[INF]*W for _ in range(H)]
    P = deque()
    P.append([sx,sy])
    cost[sx][sy] = 0
    while len(P) != 0:
        p = P.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] != "#" and cost[nx][ny] == INF:
                P.append([nx,ny])
                cost[nx][ny] = cost[p[0]][p[1]]+1
    return cost
def solve():
    ans = 0
    for i in range(H):
        for j in range(W):
            if maze[i][j] != "#":
                sx,sy = i,j
                cs = bfs(sx,sy)
                for k in range(len(cs)):
                    if max(cs[k]) > ans:
                        ans = max(cs[k])
    return ans
print(solve())
### BUGGY CODE ###

# コンテスト時にトライしていたアルゴリズム
# その後の検証でアルゴリズムは正しそうなのでコードエラーを探す

n, x = map(int, input().split())
city_list = list(map(int, input().split()))
 
import numpy as np
 
def getNearestValue(list, num):
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

# TLE対策 dist_listからmax_Dを求める
# nearest_city = getNearestValue(city_list, x)
# Dとなり最大値はXと最も近い都市との距離に等しい
# max_D = abs(nearest_city-x)

# TLE対策 都市との距離は事前に計算
dist_list = []
for city in city_list:
    dist_list.append(abs(city - x))

# TLE対策 mac_D対策
dist_list.sort()
max_D = dist_list[0]

for xx in reversed(range(1, max_D+1)):
    flag = True
    for dist in dist_list:
        if (dist % xx) != 0:
            flag = False
            break
    if flag:
        break
print(xx)

### FIXED CODE ###

import fractions

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

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

dist_list = []
for city in city_list:
    dist_list.append(abs(city - x))

max_common_value = dist_list.pop(0)

for dist in dist_list:
    # 今までのDと次の都市の距離との最大公約数を見つける
    max_common_value = fractions.gcd(max_common_value, dist)

print(max_common_value)
### BUGGY CODE ###

N,X,Y=map(int,input().split())
D=[]
X-=1;Y-=1
for i in range(N-1):
  for j in range(i+1,N):
    if i<=X:
      if j<=X:
        d=j-i
      elif X<j<Y:
        d=min(j-i,X-i+1+Y-j)
      else:
        d=X-i+1+j-Y
    elif X<i<Y:
      if X<j<Y:
        d=min(j-i,i-X+1+Y-j)
      else:
        d=min(j-i,i-X+1+j-Y)
    else:
      d=j-i
    #print(i,j,d)
    D.append(d)
for i in range(1,N):
  print(D.count(i))

### FIXED CODE ###

N,X,Y=map(int,input().split())
Ans=[0 for i in range(1,N)]
X-=1;Y-=1
for i in range(N-1):
  for j in range(i+1,N):
    if i<=X:
      if j<=X:
        d=j-i
      elif X<j<Y:
        d=min(j-i,X-i+1+Y-j)
      else:
        d=X-i+1+j-Y
    elif X<i<Y:
      if X<j<Y:
        d=min(j-i,i-X+1+Y-j)
      else:
        d=min(j-i,i-X+1+j-Y)
    else:
      d=j-i
    #print(i,j,d)
    Ans[d-1]+=1
for a in Ans:
  print(a)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N,M,R = map(int,input().split())
r = list(map(int,input().split()))
S = [[]for i in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    S[a-1].append([b-1,c])
    S[b-1].append([a-1,c])
d = [[float('inf')]*N for i in range(N)]
queue = []
hoge = [0]*(M)
for i in range(N):
    queue = [i]
    d[i][i] = 0
    while queue !=[]:
        l = 0
        for q in queue:
            for next,c in S[q]:
                if d[i][next] > d[i][q]+c:
                    d[i][next] = d[i][q]+c
                    if not(next in hoge[:l]):
                        hoge[l] = next
                        l += 1
        queue = hoge[:l]
def func(x,l):
    if l == []:
        return 0
    ans = float('inf')
    for i in range(len(l)):
        ans =min(ans,func(l[i],l[:i]+l[i+1:]) + d[x-1][l[i]-1])
    return ans
ans = float('inf')
for i in r:
    ans = min(ans,func(i,r))
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N,M,R = map(int,input().split())
r = list(map(int,input().split()))
S = [[]for i in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    S[a-1].append([b-1,c])
    S[b-1].append([a-1,c])
d = [[float('inf')]*N for i in range(N)]
queue = []
hoge = [0]*(M)
for i in range(N):
    queue = [i]
    d[i][i] = 0
    while queue !=[]:
        l = 0
        for q in queue:
            for next,c in S[q]:
                if d[i][next] > d[i][q]+c:
                    d[i][next] = d[i][q]+c
                    if not(next in hoge[:l]):
                        hoge[l] = next
                        l += 1
        queue = hoge[:l]
def func(x,l):
    if l == []:
        return 0
    ans = float('inf')
    for i in range(len(l)):
        ans =min(ans,func(l[i],l[:i]+l[i+1:]) + d[x-1][l[i]-1])
    return ans
ans = float('inf')
for i in r:
    ans = min(ans,func(i,r))
print(ans)
### BUGGY CODE ###

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

# def print_map(mp):
#     for r in mp:
#         print(['{:2d}'.format(n) for n in r])

H, W = map(int, input().split())
mp = [[] for h in range(H)]
mp_row = [[0 for w in range(W)] for h in range(H)]
mp_col = [[0 for w in range(W)] for h in range(H)]

# True = なし、 False = 障害物
for h in range(H):
    s = input()
    for w in range(W):
        mp[h] = [True if c == "." else False for c in s]

# 全探索はO(HWHW)となって爆発。
# 縦横でまずカウントするのがよさげ。
# このプログラムはO(HW)だがTLE

## 横のパネル数
for h in range(H):
    st = 0
    cnt = 0
    for w in range(W):
        if mp[h][w] is False:
            for i in range(st, w):
                mp_row[h][i] = cnt
            cnt = 0
            st = w+1
        elif w == W-1:
            cnt += 1
            for i in range(st, W):
                mp_row[h][i] = cnt
        else:
            cnt += 1

## 縦のパネル数
for w in range(W):
    st = 0
    cnt = 0
    for h in range(H):
        if mp[h][w] is False:
            for i in range(st, h):
                mp_col[i][w] = cnt
            cnt = 0
            st = h+1
        elif h == H-1:
            cnt += 1
            for i in range(st, H):
                mp_col[i][w] = cnt
        else:
            cnt += 1

#print_map(mp_row)
#print()
#print_map(mp_col)

mx = 0
for h in range(H):
    for w in range(W):
        # 重なっている中央を引くのを忘れずに
        mx = max(mx, mp_row[h][w]+mp_col[h][w]-1)
print(mx)


### FIXED CODE ###

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

# def print_map(mp):
#     for r in mp:
#         print(['{:2d}'.format(n) for n in r])

H, W = map(int, input().split())
mp = [[] for h in range(H)]
mp_row = [[0 for w in range(W)] for h in range(H)]
mp_col = [[0 for w in range(W)] for h in range(H)]

# True = なし、 False = 障害物
for h in range(H):
    mp[h] = [True if c == "." else False for c in input()]

# 全探索はO(HWHW)となって爆発。
# 縦横でまずカウントするのがよさげ。
# このプログラムはO(HW)だがTLE: カウントしたものの書き込みでO(HHW+HWW)あたりになっている？
# これpythonのforの遅さでTLEしてないか…？

## 横のパネル数
for h in range(H):
    st = 0
    cnt = 0
    for w in range(W):
        if mp[h][w] is False:
            for i in range(st, w):
                mp_row[h][i] = cnt
            cnt = 0
            st = w+1
        elif w == W-1:
            cnt += 1
            for i in range(st, W):
                mp_row[h][i] = cnt
        else:
            cnt += 1

## 縦のパネル数
for w in range(W):
    st = 0
    cnt = 0
    for h in range(H):
        if mp[h][w] is False:
            for i in range(st, h):
                mp_col[i][w] = cnt
            cnt = 0
            st = h+1
        elif h == H-1:
            cnt += 1
            for i in range(st, H):
                mp_col[i][w] = cnt
        else:
            cnt += 1

#print_map(mp_row)
#print()
#print_map(mp_col)

mx = 0
for h in range(H):
    for w in range(W):
        # 重なっている中央を引くのを忘れずに
        mx = max(mx, mp_row[h][w]+mp_col[h][w]-1)
print(mx)
### BUGGY CODE ###

import itertools
import heapq
N, K = [int(x) for x in input().split()]
orig_td = [tuple([int(x) for x in input().split()]) for _ in range(N)]
td = sorted(orig_td.copy(), key=lambda x: x[1], reverse=True)
INF = 10**9
# print(td)


def score(a):
    kiso = sum([x[1] for x in a])
    bonus = len(set([x[0] for x in a]))**2
    return kiso + bonus


first = []
second = []
kind = set()
for i in range(K):
    if td[i][0] not in kind:
        first.append(td[i])
        kind.add(td[i][0])
    else:
        second.append(td[i])

best_ans = sum([x[1] for x in first + second]) + len(first)**2

for k in range(K, N):
    if len(second) == 0:
        break
    if td[k][0] in kind:
        continue

    a = second.pop(-1)
    kind.add(td[k][0])
    first.append(td[k])
    ans = sum([x[1] for x in first + second]) + len(first)**2
    # print(first, second, ans)
    if best_ans < ans:
        best_ans = ans
print(best_ans)


### FIXED CODE ###

N, K = [int(x) for x in input().split()]
td = sorted([[int(x) for x in input().split()] for _ in range(N)],
            key=lambda x: x[1], reverse=True)
INF = 10**9
# print(td)

first = []
second = []
kind = set()
for i in range(K):
    if td[i][0] not in kind:
        first.append(td[i])
        kind.add(td[i][0])
    else:
        second.append(td[i])

yummy = sum([x[1] for x in first + second])
best_ans = yummy + len(kind)**2

for k in range(K, N):
    if len(second) == 0:
        break
    if td[k][0] in kind:
        continue

    a = second.pop(-1)
    yummy -= a[1]
    kind.add(td[k][0])
    first.append(td[k])
    yummy += td[k][1]
    ans = yummy + len(kind)**2
    # print(first, second, ans)
    if best_ans < ans:
        best_ans = ans
print(best_ans)
### BUGGY CODE ###

# coding: utf-8
import sys
sysread = sys.stdin.readline
from heapq import heappop, heappush

def run():
    # import sys
    # A = list(map(int, sys.stdin.readline().split()))
    # all = sys.stdin.readlines()
    # all = list(map(int, sys.stdin.read().split())
    #N, *A = map(int, open(0))
    #N = int(input())
    N, M, S = list(map(int, sysread().split()))
    to = [[] for _ in range(N+1)]
    for _ in range(M):
        u,m,a,b = list(map(int, sysread().split()))
        to[u].append((m,b,a))
        to[m].append((u,b,a))

    CD = [[0,0]]
    for _ in range(N):
        c,d = list(map(int, sysread().split()))
        CD.append([c,d])

    queue = []
    # (time, node, rest-coin)
    heappush(queue, (0, 1, S))

    min_times = [float('inf') for _ in range(N+1)]
    nodes = [0 for _ in range(N)]

    while nodes:
        time, node, coin = heappop(queue)
        if min_times[node] == float('inf'):
            min_times[node] = time
            nodes.pop()
        c, d = CD[node]
        heappush(queue, (time+d, node, coin+c))
        for n_node, n_time, n_coin in to[node]:
            if coin < n_coin:
                continue
            else:
                heappush(queue, (time + n_time, n_node, coin - n_coin))
    for s in min_times[2:]:
        print(s)

if __name__ == "__main__":
    run()

### FIXED CODE ###

import sys
readline = sys.stdin.readline
read = sys.stdin.read
 
n,m,s = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for i in range(m):
    u,v,a,b = [int(i) for i in readline().split()]
    u -= 1
    v -= 1
    g[u].append((v,a,b))
    g[v].append((u,a,b))
 
 
cd = [int(i) for i in read().split()]
c = cd[::2]
d = cd[1::2]
 
 
from heapq import *
INF = 1<<61
M = 2500
if s >= M: s = M-1
dist = [[INF]*M for _ in range(n)] #startからの最短距離
dist[0][s] = 0
q = [(0,s,0)] #(そこまでの距離、銀の枚数、点)
 
while q:
    dv,num,v = heappop(q)
    if dist[v][num] < dv: continue
    if num+c[v] < M and dv+d[v] < dist[v][num+c[v]]:
        dist[v][num+c[v]] = dv + d[v]
        heappush(q, (dv + d[v], num+c[v] ,v))
    for to,a,b in g[v]:
        if num >= a and dv + b < dist[to][num-a]:
            dist[to][num-a] = dv + b
            heappush(q, (dv + b, num-a ,to))
    #print(q)
 
for i in range(1,n):
    print(min(dist[i]))
### BUGGY CODE ###

#i文字目を見て，それより前のAの個数，ABの個数，ABCの個数を持っておく

S=input()
N=len(S)
dp=[[0,0,0] for _ in range(N+1)]

mod=10**9+7

p=[1]*(N+1)
for i in range(N):
    p[i+1]=p[i]*3


count=0#?の数
for i in range(N):
    for j in range(3):
        dp[i+1][j]=dp[i][j]
    if S[i]=="A":
        dp[i+1][0]+=p[count]
    elif S[i]=="B":
        dp[i+1][1]+=dp[i][0]
    elif S[i]=="C":
        dp[i+1][2]+=dp[i][1]
    else:
        dp[i+1][2]=dp[i][2]*3+dp[i][1]
        dp[i+1][1]=dp[i][1]*3+dp[i][0]
        dp[i+1][0]=dp[i][0]*3+p[count]
        count+=1
    for j in range(3):
        dp[i+1][j]%=mod
        
print(dp[-1][-1])   






### FIXED CODE ###

#i文字目を見て，それより前のAの個数，ABの個数，ABCの個数を持っておく

S=input()
N=len(S)
dp=[0,0,0]

mod=10**9+7

p=[1]*(N+1)
for i in range(N):
    p[i+1]=(p[i]*3)%mod


count=0#?の数
for i in range(N):
    if S[i]=="A":
        dp[0]=(dp[0]+p[count]) %mod
    elif S[i]=="B":
        dp[1]=(dp[1]+dp[0])%mod
    elif S[i]=="C":
        dp[2]=(dp[2]+dp[1])%mod
    else:
        dp[2]=(dp[2]*3+dp[1])%mod
        dp[1]=(dp[1]*3+dp[0])%mod
        dp[0]=(dp[0]*3+p[count])%mod
        count+=1
        
print(dp[2]%mod)
### BUGGY CODE ###

N = int(input())
S = input()

K = set()
K.add(S[0:3])
K2 = set()
K2.add(S[0]+S[1])
K2.add(S[0]+S[2])
K2.add(S[1]+S[2])


for i in range(3,N):   
    c = S[i]
    tmp = set()
    tmp2 = set()
    for k in K2:
        tmp.add(k+c)
        tmp2.add(k[0]+c)
        tmp2.add(k[1]+c)
    K = K.union(tmp)
    K2 = K2.union(tmp2)

print(len(K))

### FIXED CODE ###

N = int(input())
S = input()

def f(n):
    n = str(n).zfill(3)
    # print(n)
    found = False
    for i in range(len(S)):
        if S[i] == n[0]:
            found = True
            break
    if found == False:
        return 0
    
    found = False
    for j in range(i+1, len(S)):
        if S[j] == n[1]:
            found = True
            break
    if found == False:
        return 0

    found = False
    for k in range(j+1, len(S)):
        if S[k] == n[2]:
            found = True
            break
    if found:
        return 1
    return 0

ans = 0
for i in range(1000):
    ans += f(i)

print(ans)
### BUGGY CODE ###

n=int(input())
s=input()

ans=0
for i in range(n):
    for j in range(i+1,n):
        if(s[i]!=s[j]):
            for k in range(j+1,n):
                if(k==j+j-i):
                    continue
                elif(s[i]!=s[k] and s[j]!=s[k]):
                    ans+=1
        else:
            continue

print(ans)

### FIXED CODE ###

n=int(input())
s=input()

r=list(s).count('R')
g=list(s).count('G')
b=list(s).count('B')

ans=r*g*b
for i in range(n):
    for j in range(i+1,n):
        k=j+(j-i)
        if(k<n and s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]):
#            print(i,j,k)
            ans-=1
print(ans)
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]

def sL(v, x, l, r):
    if l == r:
        return l
    else:
        h = (l + r) // 2
        if x > v[h]:
            return sL(v, x, h + 1, r)
        else:
            return sL(v, x, l, h)

p = 1
x = 0
for k in range(0, 29):
    b_m = [i % (p * 2) for i in b]
    b_m = sorted(b_m)
    s = 0
    for ai in a:
        u = ai % (p * 2)
        s += sL(b_m, p * 2 - u, 0, n) - sL(b_m, p - u, 0, n) + sL(b_m, p * 4 - u, 0, n) - sL(b_m, 3 * p - u, 0, n)
    if s % 2 == 1:
        x += p
    p *= 2

print(x)

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]

#n = 200000
#a = [1] * n
#b = [1] * n
#b_m = [0] * n

p = 1
x = 0
for k in range(0, 29):
    b_m = sorted([i % (p * 2) for i in b])
    a_m = sorted([i % (p * 2) for i in a], reverse=True)
    s = 0
    l1 = 0
    r1 = 0
    l2 = 0
    r2 = 0
    for a_mi in a_m:
        while l1 < n and a_mi + b_m[l1] < p:
            l1 += 1
        while r1 < n and a_mi + b_m[r1] < 2 * p:
            r1 += 1
        while l2 < n and a_mi + b_m[l2] < 3 * p:
            l2 += 1
        while r2 < n and a_mi + b_m[r2] < 4 * p:
            r2 += 1
        s += r2 - l2 + r1 - l1
    if s % 2 == 1:
        x += p
    p *= 2

print(x)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(N: int, a: "List[int]"):

    c = Counter(a)
    kitai = [[[0]*(N+2) for _ in range(N+2)] for _ in range(N+2)]
    kitai[0][0][0] = 0
    for k in range(c[3]+1):
        for j in range(N+1):
            for i in range(N+1):
                if i == 0 and j == 0 and k == 0:
                    continue
                res = N
                if i - 1 >= 0:
                    res += kitai[i-1][j][k]*i
                if j - 1 >= 0:
                    res += kitai[i+1][j-1][k]*j
                if k - 1 >= 0:
                    res += kitai[i][j+1][k-1]*k
                res /= (i+j+k)
                kitai[i][j][k] = res
    print(kitai[c[1]][c[2]][c[3]])

    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
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):

    c = [0]*4
    for A in a:
        c[A] += 1

    J = min(c[2]+c[3]+1, N+1)
    I = min(c[1]+c[2]+c[3]+1, N+1)
    kitai = [[[0]*(I+1) for _ in range(J+1)]
             for _ in range(c[3]+1)]
    for k in range(c[3]+1):
        for j in range(J):
            for i in range(I):
                tot = i+j+k
                if tot == 0 or tot > N:
                    continue
                res = N + kitai[k][j][i-1]*i + \
                    kitai[k][j-1][i+1]*j + kitai[k-1][j+1][i]*k
                kitai[k][j][i] = res/tot
    print(kitai[c[3]][c[2]][c[1]])

    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
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


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


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

P=[1]
now=1

for i in range(K):
    now=A[now-1]
    if now in P:
        x = i+1
        y = P.index(now)
        break
    elif i == K-1:
        print(now)
        exit()
    else:
        P.append(now)

c=(K-y)%(x-y)

Q=P[y:]

print(Q[c])

### FIXED CODE ###


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

P=[1]
S=[0]*N
S[0]=1
now=1

for i in range(K):
    now=A[now-1]
    if S[now-1]==1:
        x = i+1
        y = P.index(now)
        break
    elif i == K-1:
        print(now)
        exit()
    else:
        P.append(now)
        S[now-1]=1

c=(K-y)%(x-y)

print(P[y+c])