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

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

import numpy as np
from scipy.sparse.csgraph import floyd_warshall

A = np.zeros((n,n), np.int32)

for i in range(1, n):
    A[i, i-1] = 1
    A[i-1, i] = 1
A[x-1, y-1] = 1
A[y-1, x-1] = 1
dist = floyd_warshall(A, directed = False)

ans = [0] * n
for i in range(n):
    for j in range(i, n):
        ans[int(dist[i][j])] += 1

for i in range(1, n):
    print(ans[i])

### FIXED CODE ###

n, x, y = map(int, input().split())
x = x-1
y = y-1
from collections import deque
que = deque()

INF = 10**5
seen = [[INF] * n for _ in range(n)]
#import numpy as np
for i in range(n):
    que.append(i)
    seen[i][i] = 0
    #print('---', i)
    while len(que) > 0:
        t = que.popleft()
        step = [t-1, t+1]
        if t == x:
            step.append(y)
        if t == y:
            step.append(x)
        for ti in step:
            #print(ti)
            if ti < 0 or ti >= n:
                continue
            if seen[i][ti] == INF:
                que.append(ti)
            seen[i][ti] = min(seen[i][t] + 1, seen[i][ti])
    #print(np.array(seen))
#print(np.array(seen))

ans = [0] * n
for i in range(n):
    for j in range(i, n):
        ans[int(seen[i][j])] += 1

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

import heapq

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse = True)
#print(A)

hq = [(-A[0]*2,0,0)]
used = [[False for _ in range(N)] for _ in range(N)]
used[0][0] = True
ans = 0
for i in range(M):
  a,p,q = heapq.heappop(hq)
  ans -= a
  if p+1 < N and not used[p+1][q]:
    heapq.heappush(hq, (-A[p+1]-A[q],p+1,q))
    used[p+1][q] = True
  if q+1 < N and not used[p][q+1]:
    heapq.heappush(hq, (-A[p]-A[q+1],p,q+1))
    used[p][q+1] = True
print(ans)

### FIXED CODE ###

import bisect

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
#print(A)

# Aの累積和を求めておく。
csum = [A[0] for _ in range(N+1)]
for i in range(1,N):
  csum[i] = csum[i-1]+A[i]

# M回以上握手できるとなる最小の幸福度を求める。
# r:M回以上握手ができる最小の幸福度。
# l:M回以上握手が出来ない最大の幸福度。
l = 0
r = 10**6
while (l+1 < r):
  m = (l+r)//2
  p = 0 # 幸福度がm以上になる握手の回数
  for a in A:
    q = bisect.bisect_left(A,m-a)
    #print(q,m-a,A)
    p += N-q
  #print(l,m,r,p)
  if p >= M:
    l = m
  else:
    r = m
#print(l,m,r)

# 幸福度がlのときに握手ができる回数を求め、
# それとMとの差

ans = 0
cnt = 0
for a in A:
  q = bisect.bisect_right(A,l-a)
  if q == 0:
    ans += csum[N-1]+a*N
    cnt += N
  elif q < N:
    ans += csum[N-1]-csum[q-1]+a*(N-q)
    cnt += N-q
  #print(a,q,ans,cnt)
ans +=l*(M-cnt)
print(ans)
### BUGGY CODE ###

S = input()
Slen = len(S)
s = int(S, 2)
x = 0
for n in range(Slen) :
    if n%2 == 0 :
        x += 2**n
nuri = s^x
ans = 0
while nuri > 0 :
    if nuri&1 == 1 :
        ans += 1
    nuri >>= 1
print(min(ans, Slen-ans))

### FIXED CODE ###

S = input()
a = 0
for n in range(len(S)) :
    if n%2 == 0 :
        if S[n] == "0" :
            a += 1
    else :
        if S[n] == "1" :
            a += 1
print(min(a, len(S)-a))
### BUGGY CODE ###

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

ans=[]
for i in range(1,n+1):
    b=str(a.count(i))
    ans.append(b)

print('\n'.join(ans))

### FIXED CODE ###

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

b=[0]*n

for i in a:
    b[i-1]+=1

for j in b:
    print(j)
### BUGGY CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = [ni() for _ in range(n)]

a.sort()
count = 0
ans = 0
for i in a:
    count = a.count(i)
    if count % 2 != 0:
        ans += 1
print(ans)


### FIXED CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
s = set()
for i in range(n):
    x = ni()
    if x in s:
        s.remove(x)
    else:
        s.add(x)
print(len(s))
### BUGGY CODE ###

n,W = map(int,input().split())
wt =[];val=[]

dp = [[0 for i in range(W+1)] for j in range(n)]
for _ in range(n):
  wi , vi= map(int,input().split())
  wt.append(wi)
  val.append(vi)

for i in range(W+1):
  if i>=wt[0]:
    dp[0][i]=val[0]   
  else:
    dp[0][i]=0
    
    
    
#print(dp)  
for i in range(1,n):
  wi = wt[i]
  vi = val[i]
  for w in range(1,W+1):
    if wi <= w:
      dp[i][w] = max(vi + dp[i-1][w-wi] , dp[i-1][w] )
    else:
      dp[i][w] = dp[i-1][w]

print(dp[n-1][W])        
        
        


### FIXED CODE ###

N,W = map(int,input().split())
INF = 10**9+7
NV = (10**3)*N
dp = [[INF for j in range(NV+1)] for i in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    w,v = map(int,input().split())
    for j in range(NV+1):
        if j < v:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-v]+w)
ans = 0
for j in range(NV+1):
    if dp[N][j] <= W:
        ans = j
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
M = 1
while M <= N :
    print(A.count(M))
    M = M+1


### FIXED CODE ###

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

a = [0]*N

for i in range(N-1) :
  a[A[i]-1] = a[A[i]-1]+1
 
for i in a :
  print(i)
### BUGGY CODE ###

#import sys 
#input = sys.stdin.readline

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

dp = [0] * 100010

dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,min(K,N)):
    Minimum = dp[i-1]+abs(h[i]-h[i-1])
    for j in range(2,i+1):
        Minimum = min(dp[i-j]+abs(h[i]-h[i-j]),Minimum)
    dp[i] = Minimum
if N > K:
    if K == 1:
        for i in range(K,N):
            Minimum = dp[i-1]+abs(h[i]-h[i-1])
            dp[i] = Minimum
        
    else:
        for i in range(K,N):
            Minimum = dp[i-1]+abs(h[i]-h[i-1])
            for (j,k) in zip(dp[i-K:i-1],h[i-K:i-1]):
                Minimum = min(j+abs(h[i]-k),Minimum)
            dp[i] = Minimum
        
print(dp[N-1])

### FIXED CODE ###

#import sys 
#input = sys.stdin.readline

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

dp = [0] * 100010

dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,min(K,N)):
    Minimum = dp[i-1]+abs(h[i]-h[i-1])
    for j in range(2,i+1):
        Minimum = min(dp[i-j]+abs(h[i]-h[i-j]),Minimum)
    dp[i] = Minimum
if N > K:
    if K == 1:
        for i in range(K,N):
            Minimum = dp[i-1]+abs(h[i]-h[i-1])
            dp[i] = Minimum
        
    else:
        for i in range(K,N):
            Minimum = dp[i-1]+abs(h[i]-h[i-1])
            for (j,k) in zip(dp[i-K:i-1],h[i-K:i-1]):
                Minimum = min(j+abs(h[i]-k),Minimum)
            dp[i] = Minimum
        
print(dp[N-1])
### BUGGY CODE ###

X,Y,Z,K=map(int,input().split())
if X>Y and X>Z:
  X,Z=Z,X
  A,C=C,A
elif Y>X and Y>Z:
  Y,Z=Z,Y
  B,C=C,Y
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
k=min(K,X*Y)
AB=sorted([a+b for a in A for b in B],reverse=True)[:k]
ABC=sorted([ab+c for ab in AB for c in C[:K]],reverse=True)[:K]
for x in ABC:
  print(x)

### FIXED CODE ###

X,Y,Z,K=map(int,input().split())
A=sorted(list(map(int,input().split())),reverse=True)
B=sorted(list(map(int,input().split())),reverse=True)
C=sorted(list(map(int,input().split())),reverse=True)
ans=[]
for i in range(X):
  if i+1>K:
    break
  for j in range(Y):
    if (i+1)*(j+1)>K:
      break
    for k in range(Z):
      if (i+1)*(j+1)*(k+1)>K:
        break
      ans.append(A[i]+B[j]+C[k])
ans=sorted(ans,reverse=True)
for a in ans[:K]:
  print(a)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import bisect
import heapq

def solve(H: int, W: int, black):
    Q = []
    marked = [[0] * W for h in range(H)]
    for h, w in black:
        heapq.heappush(Q, (0, h, w))
        marked[h][w] = 1
    dmax = 0
    while len(Q) > 0:
        d, h, w = heapq.heappop(Q)
        dmax = max(d, dmax)
        for hh, ww in [(h-1, w), (h+1, w), (h, w-1), (h, w+1)]:
            if 0 <= hh <= H-1 and 0 <= ww <= W-1 and marked[hh][ww] == 0:
                heapq.heappush(Q, (d+1, hh, ww))
                marked[hh][ww] = 1
    print(dmax)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    black = []
    for h in range(H):
        line = next(tokens)
        for w, c in enumerate(line):
            if c == '#':
                black.append((h, w))
    solve(H, W, black)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

inf = float('inf')

def solve(H: int, W: int, A: "List[str]"):
    dist = [[inf] * W for h in range(H)]
    for h in range(1, H):
        for w in range(1, W):
            if A[h][w] == '#':
                dist[h][w] = 0
            else:
                dist[h][w] = min(dist[h-1][w], dist[h][w-1]) + 1
    
    dmax = 0
    for h in range(H-1, -1, -1):
        for w in range(W-1, -1, -1):
            if A[h][w] == '#':
                dist[h][w] = 0
            elif h+1 <= H-1 and w+1 <= W-1:
                dist[h][w] = min(dist[h][w], min(dist[h+1][w], dist[h][w+1]) + 1)
            elif w+1 == W and h+1 <= H-1:
                dist[h][w] = min(dist[h][w], dist[h+1][w] + 1)
            elif h+1 == H and w+1 <= W-1:
                dist[h][w] = min(dist[h][w], dist[h][w+1] + 1)
            dmax = max(dist[h][w], dmax)
    print(dmax) 
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, A)

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

S=input()
N=len(S)

if N < 4:
    ans=0
else:
    ans = 0
    for i in range(N-3):
        for j in range(i+3,N):
            n=int(S[i:j+1])
            if n%2019==0:
                ans +=1
print(ans)

### FIXED CODE ###

S=input()

N=len(S)
d={}
for i in range(2019):
    d[i]=0

d[0] = 1

mod=0
dig=1

for i in range(N):
    #s=S[N-1-i:]
    #d[int(s)%2019]+=1
    mod += dig * int(S[N-1-i])
    mod %= 2019
    d[mod] += 1
    dig *= 10
    dig %= 2019


ans = 0
for k in d.keys():
    v = d[k]
    if v > 1:
        ans += v*(v-1)//2
print(ans)
### BUGGY CODE ###

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

d = {}
def kitaichi(n):
	if n in d.keys(): return d[n]
	else:
		ret = 0
		for i in range(n+1):
			ret += i
		d[n] = ret / n
		return d[n]

ans = 0
for i in range(len(p)):
	pp = p[i:i+k]
	if len(pp) != k: break
	tmp = 0
	for j in pp:
		tmp += kitaichi(j)
	ans = max(ans, tmp)


print(ans)

### FIXED CODE ###

from itertools import accumulate
n, k = map(int, input().split())
p = [-~int(i)/2 for i in input().split()]
a = [0] + list(accumulate(p))
print(max(j-i for i, j in zip(a, a[k:])))
### BUGGY CODE ###

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


### FIXED CODE ###

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

main()
### BUGGY CODE ###

import sys
import math

if __name__ == '__main__':
    a, b, n = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    old = 0

    for x in range(n+1):
        tmp = math.floor(a*x/b)-a*math.floor(x/b)
        if tmp < old:
            print(old)
            break
        else:
            old = tmp
    else:
        print(tmp)

### FIXED CODE ###

import sys
import math

if __name__ == '__main__':
    a, b, n = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    old = 0
    if 0 <= b-1 and b-1 <= n:
        x = b - 1
        print(math.floor(a*x/b)-a*math.floor(x/b))
    else:
        x = n
        print(math.floor(a*x/b)-a*math.floor(x/b))
### BUGGY CODE ###

from collections import defaultdict
S = input()
l = len(S)
d = {l: 0}
for i in range(len(S)):
    s = int(S[i:l])
    d[i] = s%2019
count_d = defaultdict(int)
for i in range(len(S)+1):
    count_d[d[i]] += 1
counter = 0
for key in count_d.keys():
    counter += count_d[key] - 1
print(counter)

### FIXED CODE ###

from collections import defaultdict
S = input()
l = len(S)
d = {0:0}
mod10n = 1
for i in range(1, len(S)+1):
    s = int(S[l-i])
    d[i] = (d[i-1] + s * mod10n) %2019
    mod10n = (mod10n * 10) % 2019
count_d = defaultdict(int)
for key in d.keys():
    count_d[d[key]] += 1
counter = 0
for key in count_d.keys():
    counter += (count_d[key] * (count_d[key]-1)) //2

print(counter)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

answer = 1
x = 1
if N < 100:
    while True:
        x += 1
        y = x ** N
        if y > P:
            break
        if P % y == 0:
            answer = x

print(answer)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

f = []
x = 2
while x*x <= P:
    if P%x == 0:
        f.append(x)
        P //= x
        continue
    x += 1

if P > 1:
    f.append(P)

from collections import Counter
counter = Counter(f)

answer = 1
for p,k in counter.items():
    answer *= p ** (k//N)
print(answer)
### BUGGY CODE ###

from collections import defaultdict
import numpy as np
def main():
    s = input()
    n = len(s)
    d = np.zeros(2019,np.int64)
    ans = 0
    num = 0
    d[0] += 1
    for i in reversed(range(n)):
        num += int(s[i]) * 10 ** (n - 1 - i)
        #print(num, num % 2019, i)
        mod = num % 2019
        ans += d[mod]
        d[mod] += 1
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import defaultdict
import numpy as np
def main():
    s = input()
    n = len(s)
    d = np.zeros(2019,np.int64)
    ans = 0
    num = 0
    pow10 = 1
    d[0] = 1
    for i in reversed(range(n)):
        pow10 = pow10 * 10 % 2019
        num += int(s[i]) * pow10
        #print(num, num % 2019, i)
        mod = num % 2019
        ans += d[mod]
        d[mod] += 1
    print(ans)

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

N = int(input())
S = []
for i in range(N):
    S.append(input())

def check(S, A, B):
    for i in range(N):
        for j in range(N):
            if i + A < N:
                a = i + A
            else:
                a = i + A - N
            if j + B < N:
                b = j + B
            else:
                b = j + B - N
            if j + A < N:
                c = j + A
            else:
                c = j + A - N
            if i + B < N:
                d = i + B
            else:
                d = i + B - N
            if S[a][b] != S[c][d]:
                return False
    return True

cnt = 0
for i in range(N):
    if check(S, 0, i):
        cnt += 1
print(cnt * N)

### FIXED CODE ###

N = int(input())
S = []
for i in range(N):
    S.append(input())

def check(S, A, B):
    for i in range(N):
        for j in range(i+1, N):
            if S[i][j] != S[j][i]:
                return 0
    return 1

cnt = 0
for i in range(N):
    cnt += check(S[i:] + S[:i], 0, i)
print(cnt * N)
### BUGGY CODE ###

import sys
import heapq
my_input = sys.stdin.readline

xs, ys, xt, yt = map(int, my_input().split())
N = int(my_input())
C = [(xs, ys, 0), (xt, yt, 0)]
C += [tuple(map(int, my_input().split())) for i in range(N)]

G = [[] for i in range(N+2)]
for i in range(N + 2):
    for j in range(i + 1, N + 2):
        cost = max(0, ((C[i][0] - C[j][0]) ** 2 + (C[i][1] - C[j][1]) ** 2) ** 0.5 - (C[i][2] + C[j][2]))
        G[i].append((j, cost))
        G[j].append((i, cost))


def dijkstra(graph, start, inf=float('inf')):
    import heapq
    n = len(graph)
    distances = [inf] * n
    distances[start] = 0
    visited = [False] * n

    # 距離・頂点
    hq = [(0, start)]
    while hq:
        dist, fr = heapq.heappop(hq)
        visited[fr] = True

        for to, cost in graph[fr]:
            new_dist = distances[fr] + cost
            if (visited[to]) or (distances[to] <= new_dist):
                continue

            distances[to] = new_dist
            heapq.heappush(hq, (new_dist, to))

    return distances


dist = dijkstra(G, 0)
print(dist[1])


### FIXED CODE ###

import sys
import heapq
my_input = sys.stdin.readline

def main():
    xs, ys, xt, yt = map(int, my_input().split())
    N = int(my_input())
    C = [(xs, ys, 0), (xt, yt, 0)]
    C += [tuple(map(int, my_input().split())) for i in range(N)]

    G = [[] for i in range(N+2)]
    for i in range(N + 2):
        for j in range(i + 1, N + 2):
            cost = max(0, ((C[i][0] - C[j][0]) ** 2 + (C[i][1] - C[j][1]) ** 2) ** 0.5 - (C[i][2] + C[j][2]))
            G[i].append((j, cost))
            G[j].append((i, cost))


    def dijkstra(graph, start, inf=float('inf')):
        import heapq
        n = len(graph)
        distances = [inf] * n
        distances[start] = 0
        visited = [False] * n

        # 距離・頂点
        hq = [(0, start)]
        while hq:
            dist, fr = heapq.heappop(hq)
            if distances[fr] < dist:
                continue
            if fr == 1:
                return distances
            visited[fr] = True

            for to, cost in graph[fr]:
                new_dist = distances[fr] + cost
                if (visited[to]) or (distances[to] <= new_dist):
                    continue

                distances[to] = new_dist
                heapq.heappush(hq, (new_dist, to))

        return distances


    dist = dijkstra(G, 0)
    print(dist[1])


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

N = int(input())
A = [[] for _ in range(N)]

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

for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:  # 最短でない
                print('-1')
                exit()

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(N):
            if k == i or k == j:
                continue
            if A[i][j] == A[i][k] + A[k][j]:  # 代替可能
                break
        else:
            ans += A[i][j]

print(ans)


### FIXED CODE ###

N = int(input())
A = [[] for _ in range(N)]

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

for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:  # 最短でない
                print('-1')
                exit()

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(N):
            if k == i or k == j:
                continue
            if A[i][j] == A[i][k] + A[k][j]:  # 代替可能
                break
        else:
            ans += A[i][j]

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

X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
xy=[]
for a in A:
    for b in B:
        xy.append(a+b)
xy=sorted(xy,reverse=True)
xy=xy[:K]
xyz=[]
for x in xy:
    for c in C:
        xyz.append(x+c)
xyz=sorted(xyz,reverse=True)
for i in range(K):
    print(xyz[i])


### FIXED CODE ###

X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
xy=[]
for a in A:
    for b in B:
        xy.append(a+b)
xy=sorted(xy,reverse=True)
xy=xy[:K]
xyz=[]
for c in C:
    for x in xy:
        xyz.append(x+c)
xyz=sorted(xyz,reverse=True)
for i in range(K):
    print(xyz[i])
### BUGGY CODE ###


def parse():
  N, K = map(int, input().split(" "))
  A = []
  for a in input().split(" "):
    A.append(int(a) - 1)
  return N, K, A

def fast_mod(x, N):
  return (x * N) >> 32

def main():
  N, K, A = parse()
  # print(N, K, A)

  # 経路の計算
  route = []
  next_town = A[0]
  town = 0
  while not (next_town in route):  # 既出の町に行く場合
    route.append(town)
    next_town = A[town]
    town = next_town
  once_route = route[:route.index(next_town)]
  loop_route = route[route.index(next_town):]
  # print("once_route:", once_route)
  # print("loop_route:", loop_route)
  
  # print([town + 1 for town in route])
  # print("K %% len(loop_route):", K % len(loop_route))
  # print(route[K % len(loop_route) + len(once_route)] + 1)
  if K > len(route) and len(once_route) > 0:
    # print("loop")
    loop_K = K - len(route)
    print(loop_route[loop_K % len(loop_route)] + 1)
  else:
    # print("normal")
    # print(route[fast_mod(K, len(loop_route))] + 1)
    # print("K:", K)
    # print("K %% len(route):", K % len(route))
    print(route[K % len(route)] + 1)

if __name__ == "__main__":
  main()


### FIXED CODE ###


def parse():
  N, K = map(int, input().split(" "))
  A = []
  for a in input().split(" "):
    A.append(int(a) - 1)
  return N, K, A

def fast_pow(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

def fast_mod(x, N):
  # return x % N
  if N % 2 == 0:
    return x & (N - 1)
  else:
    return x % N

def main():
  N, K, A = parse()
  # print(N, K, A)

  # 移動
  town = 0
  route = [0]
  loop_start_index = None
  i = 0
  visited = [False for i in range(N)]
  visited[0] = True
  for i in range(K):
    # 次の町に移動
    town = A[town]

    if visited[town]:
      # ループ検出
      loop_start_index = route.index(town)
      break

    visited[town] = True
    route.append(town)

  if loop_start_index == None:
    print(town + 1)
  else:
    loop_route = route[loop_start_index:]
    # print(loop_route, K, i)
    print(loop_route[(K - (i + 1)) % len(loop_route)] + 1)
    # print(loop_route[])
  # print(town)
  exit(0)

  # 経路の計算
  route = []
  next_town = A[0]
  town = 0
  while not (next_town in route):  # 既出の町に行く場合
    route.append(town)
    next_town = A[town]
    town = next_town
  once_route = route[:route.index(next_town)]
  loop_route = route[route.index(next_town):]
  # print("once_route:", once_route)
  # print("loop_route:", loop_route)
  
  

  # print([town + 1 for town in route])
  # print("K %% len(loop_route):", K % len(loop_route))
  # print(route[K % len(loop_route) + len(once_route)] + 1)
  if K >= len(route) and len(once_route) > 0:
    # print("loop")
    loop_K = K - len(route)
    print(loop_route[fast_mod(loop_K, len(loop_route))] + 1)
    # print(loop_route[loop_K % len(loop_route)] + 1)
  else:
    # print("normal")
    # print(route[fast_mod(K, len(loop_route))] + 1)
    # print("K:", K)
    # print("K %% len(route):", K % len(route))
    print(route[fast_mod(K, len(route))] + 1)
    # print(route[K % len(route)] + 1)

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

k, s = map(int, input().split())
res = 0
for x in range(k + 1):
  for y in range(x, k + 1):
    for z in range(y, k + 1):
      if x + y + z == s:
        if x == y and y == z:
          res += 1
        elif x == y or y == z or z == x:
          res += 3
        else:
          res += 6
print(res)

### FIXED CODE ###

k, s = map(int, input().split())
res = 0
for x in range(k + 1):
  for y in range(k + 1):
    z = s - x - y
    if 0 <= z <= k:
      res += 1
print(res)