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

import math
import numpy as np
import queue
from collections import deque
import heapq
mod = 10**9+7
ans = 1
iw0 = 0

def twoxxn(t,mod):
    ni = t
    an = 1
    n2 = 2
    while ni > 0:
        if ni%2 == 1:
            an = (an*n2)%mod
        n2 = (n2**2)%mod
        ni >>= 1
    return an

n = int(input())
d = dict()
for i in range(n):
    a,b = map(int,input().split())
    if a == 0 and b == 0:
        iw0 += 1
        continue
    if a == 0:
        b = 1
        g = 1
    elif b == 0:
        a = 1
        g = 1
    else:
        g = math.gcd(abs(a),abs(b))
    if a < 0 :
        a = -a
        b = -b
    p1 = a//g, b//g
    if p1 in d:
        d[p1] += 1
    else:
        d[p1] = 1
done = []
for (i0,i1), din in d.items():
    if (i1,-i0) in done or (-i1,i0) in done:
        continue
    w = d.get((i1,-i0),0) + d.get((-i1,i0),0)
    aaa = (twoxxn(w,mod)+twoxxn(din,mod)-1)%mod
    ans = (ans*aaa)%mod
    done.append((i0,i1))

if len(d.keys()) == 0:
    print(iw0)
    exit()

ans = (iw0+ans+mod-1)%mod
print(ans)


### FIXED CODE ###

import math
import numpy as np
import queue
from collections import deque
import heapq
mod = 10**9+7
ans = 1
iw0 = 0

def twoxxn(t,mod):
    ni = t
    an = 1
    n2 = 2
    while ni > 0:
        if ni%2 == 1:
            an = (an*n2)%mod
        n2 = (n2**2)%mod
        ni >>= 1
    return an

n = int(input())
d = dict()
for i in range(n):
    a,b = map(int,input().split())
    if a == 0 and b == 0:
        iw0 += 1
        continue
    if a == 0:
        b = 1
        g = 1
    elif b == 0:
        a = 1
        g = 1
    else:
        g = math.gcd(abs(a),abs(b))
    if a < 0 :
        a = -a
        b = -b
    p1 = a//g, b//g
    if p1 in d:
        d[p1] += 1
    else:
        d[p1] = 1
done = []
for (i0,i1), din in d.items():
    if d.get((-i1,i0),1) == 0 or d.get((i1,-i0),1) == 0:
        continue
    w = d.get((i1,-i0),0) + d.get((-i1,i0),0)
    aaa = (twoxxn(w,mod)+twoxxn(din,mod)-1)%mod
    ans = (ans*aaa)%mod
    d[(i0,i1)] = 0

if len(d.keys()) == 0:
    print(iw0)
    exit()

ans = (iw0+ans+mod-1)%mod
print(ans)
### BUGGY CODE ###

import sys


n, m = [int(_) for _ in input().split()]
l = []
for i in range(m):
    l.append(int(input()))

d = [0] * (n + 2)
d[0] = 1
if 1 not in l:
    d[1] = 1
for i in range(n):
    if i in l and i + 1 in l:
        print(0)
        sys.exit()
    elif i in l:
        d[i + 2] = d[i + 1]
    elif i + 1 in l:
        d[i + 2] = d[i]
    else:
        d[i + 2] = d[i] + d[i + 1]
    d[i + 2] = d[i + 2] % (10 ** 9 + 7)
print(d[-2])

### FIXED CODE ###

import sys


n, m = [int(_) for _ in input().split()]
l = {}
for i in range(m):
    l[int(input())] = 1

d = [0] * (n + 2)
d[0] = 1
if 1 not in l:
    d[1] = 1
for i in range(n):
    if i in l and i + 1 in l:
        print(0)
        sys.exit()
    elif i in l:
        d[i + 2] = d[i + 1]
    elif i + 1 in l:
        d[i + 2] = d[i]
    else:
        d[i + 2] = d[i] + d[i + 1]
    d[i + 2] = d[i + 2] % (10 ** 9 + 7)
print(d[-2])
### BUGGY CODE ###

s=input()
A=[]
B=[]
for i in range(len(s)):
    for j in range(len(s)):
        if i<j and s[i]=='A' and s[j]=='Z':
            A.append(j+1-i)
print(max(A))

### FIXED CODE ###

s=input()
A=[]
B=[]
for i in range(0,len(s)):
    if s[i]=='A':
        a=i
        break
S=list(reversed(s))
for j in range(0,len(S)):
    if S[j]=='Z':
        b=j
        break
print(len(s)-a-b)
### BUGGY CODE ###

n = int(input())
seq = list(map(int,input().split()))
ans = 1

for i in range(1, len(seq)):
    if min(seq[0:i]) > seq[i]:
        ans += 1

print(ans)

### FIXED CODE ###

n = int(input())
seq = list(map(int,input().split()))
ans = 1
minim = n

for i in range(1, n):
    minim = min(minim, seq[i-1])
    if minim > seq[i]:
        ans += 1

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

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

total = 1

for i in range(k - 1, -1, -1):
    total *= a[i]

after = total
for i in range(k + 1, n + 1):
    before = total
    after //= a[i - k - 1]
    after *= a[i - 1]

    if before < after:
        print("Yes")
    else:
        print("No")

    total = after



### FIXED CODE ###

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

for i in range(k + 1, n + 1):
    if a[i - k - 1] < a[i - 1]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

from sys import stdin
K,S = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
for X in range(0,K+1):
    for Y in range(0,K+1):
        for Z in range(0,K+1):
            if X+Y+Z == S:
                ans += 1
print(ans)

### FIXED CODE ###

from sys import stdin
K,S = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
for X in range(0,K+1):
    for Y in range(0,K+1):
            if 0 <= S-(X+Y) <= K:
                ans += 1
print(ans)
### BUGGY CODE ###

n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(2**n):
  x = []
  y = []
  for j in range(n):
    if (i>>j) & 1:
      x.append(v[n - j - 1])
      y.append(c[n - j - 1])
  ans = max(ans,sum(x) - sum(y))
print(ans)

### FIXED CODE ###

n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
# for i in range(2**n):
#   x = []
#   y = []
#   for j in range(n):
#     if (i>>j) & 1:
#       x.append(v[n - j - 1])
#       y.append(c[n - j - 1])
#   ans = max(ans,sum(x) - sum(y))
for i in range(n):
  if v[i] > c[i]:
    ans += v[i] - c[i]
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
#エイシングプログラミングコンテスト2019 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
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()))


dx,dy = [1,0,-1,0],[0,1,0,-1]
h,w = LI()
s = [input() for _ in range(h)]
que = deque()
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            que = deque()
            que.append((i,j))
            check = [[True]*w for _ in range(h)]
            while que:
                y,x = que.popleft()
                for k in range(4):
                    nx,ny = x + dx[k], y + dy[k]
                    if 0 <= nx < w and 0 <= ny < h and check[ny][nx]:
                        if s[ny][nx] != s[y][x]:
                            if s[y][x] == '#':
                                ans += 1
                            que.append((ny,nx))
                            check[ny][nx] = False
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#エイシングプログラミングコンテスト2019 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
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()))


dx,dy = [1,0,-1,0],[0,1,0,-1]
h,w = LI()
s = [input() for _ in range(h)]
que = deque()
ch = [[-1]*w for _ in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if ch[i][j] < 0:
                ch[i][j] = 0
                que = deque()
                que.append((i,j))
                #a:= ルールを守りながら行ける#の数
                #b:= ルールを守りながら行ける.の数
                a,b = 1,0
                while que:
                    y,x = que.popleft()
                    for k in range(4):
                        nx,ny = x + dx[k], y + dy[k]
                        if 0 <= nx < w and 0 <= ny < h and ch[ny][nx] < 0:
                            if s[y][x] != s[ny][nx]:
                                if s[ny][nx] == '#':
                                    a += 1
                                else:
                                    b += 1
                                ch[ny][nx] = 0
                                que.append((ny,nx))
                ans += a*b
print(ans)
### BUGGY CODE ###

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

A = [0]*Q
for i in range(Q):
    A[i] = int(input())

B = [K]*N

for i in range(Q):
    for j in range(N):
        if A[i] != j + 1:
            B[j] -= 1


for i in range(N):
    if B[i] > 0:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

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

A = [0]*Q
for i in range(Q):
    A[i] = int(input())

B = [0]*N

for i in range(Q):
    B[A[i] - 1] += 1


for i in range(N):
    if K - (Q - B[i]) > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

import heapq
def SME(start,end):
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    while i < N :
        if None not in ANS[i:i+L] :
            i += L
            continue
        ANS[i] = min(Whole[i+1-L:i+1])
        i+=1
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
parameter = 0.991
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

from itertools import accumulate
N, M, K = map(int,input().split())
A_list = [0] + list(map(int,input().split()))
B_list = [0] + list(map(int,input().split()))
A_sums_list = list(accumulate(A_list))
B_sums_list = list(accumulate(B_list))

for n in range(N + 1):
    if A_sums_list[n] > K:
        break
    A_max = n
for m in range(M + 1):
    if B_sums_list[m] > K:
        break
    B_max = m
ans = max(A_max, B_max)
for i in reversed(range(A_max + 1)):
    for j in reversed(range(0, B_max + 1)):
        if i + j > ans:
            if A_sums_list[i] + B_sums_list[j] <= K:
                ans = i + j
        else:
            continue
print(ans)

### FIXED CODE ###

import itertools
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

sa = list(itertools.accumulate(a))
sb = list(itertools.accumulate(b))

output = 0
j = m
for i in range(n + 1):
    if sa[i] > k:
        break
    while sa[i] + sb[j] > k:
        j -= 1
    if output < i + j:
        output = i + j
print(output)
### BUGGY CODE ###

nm = input().split()
n = int(nm[0])
m = int(nm[1])

roads = [[] for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    roads[a-1].append(b-1)
    roads[b-1].append(a-1)

visited = [0]
output = [0]*n
shortest = [0]
while len(visited) < n:
    for i in range(len(shortest)):
        for j in range(len(roads[shortest[i]])):
            if roads[shortest[i]][j] not in visited:
                visited.append(roads[shortest[i]][j])
                shortest.append(roads[shortest[i]][j])
                output[roads[shortest[i]][j]] = shortest[i]

print('Yes')
for i in range(1, len(output)):
    print(output[i]+1)


### FIXED CODE ###

from collections import deque

n, m = map(int, input().split())
room = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    room[a-1].append(b)
    room[b-1].append(a)

point = [0 for i in range(n)]
d = deque([0])

while len(d) > 0:
    p = d.popleft()
    for v in room[p]:
        if point[v-1] == 0:
            d.append(v-1)
            point[v-1] = p+1

print('Yes')
for i in range(1, n):
    print(point[i])
### BUGGY CODE ###

class UnionFind: 
    def __init__(self, numV):
        self.pars = list(range(numV))
        self.ranks = [0] * numV
        self.sizes = [1] * numV
    def getRoot(self, x):
        par = self.pars[x]
        if par != x:
            self.pars[x] = par = self.getRoot(par)
        return par
    def merge(self, x, y):
        x, y = self.getRoot(x), self.getRoot(y)
        sx, sy = self.sizes[x], self.sizes[y]
        if x == y: return (0, 0)
        if self.ranks[x] < self.ranks[y]:
            self.pars[x] = y
            self.sizes[y] += sx
        else:
            self.pars[y] = x
            self.sizes[x] += sy
            if self.ranks[x] == self.ranks[y]:
                self.ranks[x] += 1
        return (sx, sy)
    def isSame(self, x, y):
        return self.getRoot(x) == self.getRoot(y)
    def updatePars(self):
        for v in range(len(self.pars)):
            self.getRoot(v)
    def getSize(self, x):
        return self.sizes[self.getRoot(x)]


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

uf = UnionFind(n)
e = [[] for i in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    if not b in e[a]:
        uf.merge(a,b)
        e[a].append(b)
        e[b].append(a)

print(max(uf.sizes))

### FIXED CODE ###

class UnionFind: 
    def __init__(self, numV):
        self.pars = list(range(numV))
        self.ranks = [0] * numV
        self.sizes = [1] * numV
    def getRoot(self, x):
        par = self.pars[x]
        if par != x:
            self.pars[x] = par = self.getRoot(par)
        return par
    def merge(self, x, y):
        x, y = self.getRoot(x), self.getRoot(y)
        sx, sy = self.sizes[x], self.sizes[y]
        if x == y: return (0, 0)
        if self.ranks[x] < self.ranks[y]:
            self.pars[x] = y
            self.sizes[y] += sx
        else:
            self.pars[y] = x
            self.sizes[x] += sy
            if self.ranks[x] == self.ranks[y]:
                self.ranks[x] += 1
        return (sx, sy)
    def isSame(self, x, y):
        return self.getRoot(x) == self.getRoot(y)
    def updatePars(self):
        for v in range(len(self.pars)):
            self.getRoot(v)
    def getSize(self, x):
        return self.sizes[self.getRoot(x)]

import sys
input = sys.stdin.buffer.readline
n, m = map(int,input().split())

uf = UnionFind(n)
e = [[] for i in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    if not b in e[a]:
        uf.merge(a,b)

print(max(uf.sizes))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    X = int(input(),2)
    LIST = []
    PM = [-1]*N
    ANS = [0]*N
    TEMP = [0]*N
    CHAIND = [0]*N
    bit = 1
    for i in range(N):
        LIST.append(X^bit)
        PM[i] += (X & bit == 0)*2
        bit = bit<<1

    for i in range(N):
        cnt = count_ones_by_bitmask(X)
        if LIST[i]!=0:
            TEMP[i] += LIST[i] % (cnt+PM[i])
            ANS[i] += 1

    CHA = list(set(TEMP))

    for i in range(len(CHA)):
        an = 0
        cha = CHA[i]
        cnt = count_ones_by_bitmask(CHA[i])
        while cnt>0:
            an += 1
            cha = cha%cnt
            cnt = count_ones_by_bitmask(cha)
        CHAIND[CHA[i]] = an

    for i in reversed(range(N)):
        print(ANS[i]+CHAIND[TEMP[i]])


def count_ones_by_bitmask(num):
    count = 0
    while num:
        count += num & 1
        num >>= 1
    return count

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N = int(input())
    X = input()
    XINT = int(X,2)
    ANS = [0]*N
    TEMP = [0]*N
    CHAIND = [0]*N

    cnt = count_ones_by_bitmask(XINT)
    
    if cnt == 0:
        for i in range(N):
            print(1)
            return
    if cnt ==1:
        for i in  range(N):
            if X[i] == '1':
                print(0) #全てが0になる
            else:
                if i==N-1:
                    print((int(X[N-1])+1)%2+1) # 2の剰余の反転
                else:
                    print((int(X[N-1]))%2+1) # 2の剰余
        return

    p = XINT % (cnt+1)
    m = XINT % (cnt-1)
    pmod = 1
    mmod = 1
    for i in range(N):
        ANS[i] = 1
        if (X[N-i-1] == '0'):
            TEMP[i] = (p + pmod) % (cnt+1)
        else:
            TEMP[i] = (m - mmod) % (cnt-1)
        pmod = (pmod*2) % (cnt+1)
        mmod = (mmod*2) % (cnt-1)


    CHA = list(set(TEMP))

    for i in range(len(CHA)):
        an = 0
        cha = CHA[i]
        cnt = count_ones_by_bitmask(CHA[i])
        while cnt>0:
            an += 1
            cha = cha%cnt
            cnt = count_ones_by_bitmask(cha)
        CHAIND[CHA[i]] = an

    for i in reversed(range(N)):
        print(ANS[i]+CHAIND[TEMP[i]])


def count_ones_by_bitmask(num):
    count = 0
    while num:
        count += num & 1
        num >>= 1
    return count

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

#!/usr/bin/python3
import copy

r = 998244353

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

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

# s => comb
itbl = {}
rtbl = {}

for i in range(n):
    ai = a[i]
    
    nitbl = copy.copy(itbl)

    if ai in nitbl:
        nitbl[ai] = (nitbl[ai] + i + 1) % r
    else:
        nitbl[ai] = i + 1

    if ai in rtbl:
        rtbl[ai] += (i + 1) * (n - i)
    else:
        rtbl[ai] = (i + 1) * (n - i)

        
    for sk in itbl:
        if sk + ai in nitbl:
            nitbl[sk + ai] = (nitbl[sk + ai] + itbl[sk]) % r
        else:
            nitbl[sk + ai] = itbl[sk]

        if sk + ai in rtbl:
            rtbl[sk + ai] = (rtbl[sk + ai] + itbl[sk] * (n - i)) % r
        else:
            rtbl[sk + ai] = (itbl[sk] * (n - i)) % r
            
    itbl = nitbl
    
print(rtbl.get(s, 0))


### FIXED CODE ###

#!/usr/bin/python3
import copy

r = 998244353

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

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

# s => comb
itbl = {}
rtbl = {}

for i in range(n):
    ai = a[i]
    
    if ai <= s:
        nitbl = copy.copy(itbl)        
        if ai in nitbl:
            nitbl[ai] = (nitbl[ai] + i + 1) % r
        else:
            nitbl[ai] = i + 1

        if ai in rtbl:
            rtbl[ai] += (i + 1) * (n - i)
        else:
            rtbl[ai] = (i + 1) * (n - i)

        for sk in itbl:
            if sk + ai <= s:
                if sk + ai in nitbl:
                    nitbl[sk + ai] = (nitbl[sk + ai] + itbl[sk]) % r
                else:
                    nitbl[sk + ai] = itbl[sk]
                    
                if sk + ai in rtbl:
                    rtbl[sk + ai] = (rtbl[sk + ai] + itbl[sk] * (n - i)) % r
                else:
                    rtbl[sk + ai] = (itbl[sk] * (n - i)) % r
            
        itbl = nitbl
    
print(rtbl.get(s, 0))
### BUGGY CODE ###

from collections import deque


h, w = map(int, input().split())
a = []
d = deque([])
hs = set(range(h))
memo = [[-1] * w for j in hs]
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
for i in hs:
    a.append(list(input()))
    for j, s in enumerate(a[i]):
        if s == '#':
            d.append([i, j])
            memo[i][j] = 0


def d_list_update(d, hmax, wmax):
    dh, dw = d.popleft()
    for i, j in move:
        if (0 <= dh + i < hmax) and (0 <= dw + j < wmax) and (memo[dh + i][dw + j] == -1):
            memo[dh + i][dw + j] = memo[dh][dw] + 1
            d.append([dh + i, dw + j])
    return d


while(d):
    d = d_list_update(d, h, w)
ans = max([max(e) for e in memo])
print(ans)

### FIXED CODE ###

from collections import deque
 
 
h, w = map(int, input().split())
hs, ws = set(range(h)), set(range(w))
d = deque()
memo = [[-1] * w for j in hs]
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
a = tuple(input() for _ in hs)
b = [[i, j] for i in hs for j in ws if a[i][j] == '#']
for i, j in b:
    d.append((i, j))
    memo[i][j] = 0
while d:
    dh, dw = d.popleft()
    for i, j in move:
        dhn, dwn = dh + i, dw + j
        if (0 <= dhn < h) and (0 <= dwn < w) and (memo[dhn][dwn] < 0):
            d.append((dhn, dwn))
            memo[dhn][dwn] = memo[dh][dw] + 1
ans = max([max(e) for e in memo])
print(ans)
### BUGGY CODE ###

N = int(input())
items = [input()]
ans = 1

def binarysearch(items, item):
  xl = -1
  xr = len(items)
  while abs(xl-xr) > 1:
    xs = (xr+xl)//2
    if items[xs] == item:
      return True, -1
    elif items[xs] > item:
      xr = xs
    else:
      xl = xs
  return False, xr
    

for _ in range(N-1):
  item = input()
  found, insert = binarysearch(items, item)
  if not found:
    ans += 1
    items.insert(insert, item)

print(ans)
  

### FIXED CODE ###

N = int(input())
items = {}
ans = 0
for _ in range(N):
    items[input()] = None
print(len(items))
### BUGGY CODE ###

N, K = map(int, input().split())
t_list = list(map(int, input().split()))
go_list = [1] + [-1]*N
hige = 0
syuuki = 0

i = 0
while i <= N:
  if go_list[i] == -1:
    if go_list.count(t_list[go_list[i-1]-1]) == 0:
      go_list[i] = t_list[go_list[i-1]-1]
    else:
      hige = go_list.index(t_list[go_list[i-1]-1])
      syuuki = i - hige
      break
  i += 1

if K > hige:
  K -= hige
  K %= syuuki
  K += hige

print(go_list[K])

### FIXED CODE ###

N, K = map(int, input().split())
T_list = list(map(int, input().split()))
T_list = [T_list[i]-1 for i in range(N)]
point = 0
syuuki = 0

if K < N:
  i = 0
  while i < K:
    point = T_list[point]
    i += 1  

else:
  i = 0
  while i < N:
    point = T_list[point]
    if point == 0:
      syuuki = i+1
      break
    i += 1
  second_point = point
  
  if syuuki != 0:
    L = K % syuuki

  else:
    j = 0
    while j < N:
      point = T_list[point]
      if point == second_point:
        syuuki = j+1
        break
      j += 1
    L = (K-i) % syuuki

  k = 0
  while k < L:
    point = T_list[point]
    k += 1
  
print(point+1)
### BUGGY CODE ###

n = int(input())
c = input()
l = list(c)
ans = 0
a = 0
b = n
while c.count("WR") > 0 :
   for i in range(a,b) :
       if l[i] == "W" :
           l[i] = "R"
           a = i
           break
   for j in reversed(range(0,b)) :
       if l[j] == "R" :
           l[j] = "W"
           b = j
           break
   c = ''.join(l)
   ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
c = list(input())
w = 0
r = c.count("R")
ans = r
for i in range(n) :
    if c[i] == "W" :
        w += 1
    else :
        r -= 1
    if ans > max(w,r) :
        ans = max(w,r)

print(ans)