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

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

def divisors(n):
	div = [1, n]
	
	for i in range(2, int(n**0.5)+1):
		if n % i == 0:
			div.append(i)
			if i != n//i:
				div.append(n//i)
	
	return div

flag = False
inter = set(divisors(A[0]))
union = set(divisors(A[0]))
s = len(set(divisors(A[0])))
for i in range(1,N):
    div = set(divisors(A[i]))
    s += len(div)
    inter &=  div
    union |= div
if len(union) == s - N + 1:
    print('pairwise coprime')
elif inter == {1}:
    print('setwise coprime')
else:
    print('not coprime')

### FIXED CODE ###

import numpy as np
N = int(input())
A = list(map(int,input().split()))
cnt = [0] * (10**6 + 1)
for i in range(N):
    cnt[A[i]] += 1

maxcount = 0
for i in range(2,10**6+1):
    maxcount = max(maxcount,sum(cnt[i::i]))

if np.gcd.reduce(A) != 1:
    print('not coprime')
elif maxcount <= 1:
    print('pairwise coprime')
else:
    print('setwise coprime')
### BUGGY CODE ###

import copy

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

for i in range(N-1):
    a, b = map(int,input().split())
    nord[a-1].add(b-1)
    nord[b-1].add(a-1)

nord_num = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int,input().split())
    nord_num[p-1] = nord_num[p-1] + x
    
currentN = set([0])
stockList = set()
arrive = set([0])
count = 1
while count<N:
    nextN = set()
    for i in currentN:
        stockList = nord[i] - currentN - arrive
        for j in stockList:
            arrive.add(j)
            nord_num[j] = nord_num[j] + nord_num[i]
            count += 1
        nextN = nextN | stockList
    currentN = nextN
    
        

count = 1
for i in nord_num:
    if count == N:
        print(i)
    else:
        print(i, end=" ")
        count += 1


### FIXED CODE ###

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

for i in range(N-1):
    a, b = map(int,input().split())
    nord[b-1].add(a-1)
    
nord_num = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int,input().split())
    nord_num[p-1] = nord_num[p-1] + x
    
for i in range(N):
    for j in nord[i]:
        nord_num[i] = nord_num[j] + nord_num[i]
        
count = 1
for i in nord_num:
    if count == N:
        print(i)
    else:
        print(i, end=" ")
        count += 1
### BUGGY CODE ###

# input
n, m = map(int, input().split())
la = sorted(list(map(int, input().split())), reverse=True)

while m > 0:
    d = 0
    for i in range(n):
        if i < n-1 and la[i] >= la[i+1]:
            if la[i+1] > 0:
                d = la[i] // la[i+1]
            else:
                d = 1
            if d > m:
                d = m
                la[i] = la[i] // (2**d)
            else:
                la[i] = la[i] // (2**d)
            #print(la)
            for j in range(i, n-1):
                if la[j] <= la[j+1]:
                    tmp = la[j]
                    la[j] = la[j+1]
                    la[j+1] = tmp
                else:
                    break
            break
        else:
            la[i] = la[i] // 2
            d = 1
            break
    #la.sort(reverse=True)
    #print(la)
    # sprint(d)
    m -= d

print(sum(la))


### FIXED CODE ###

import heapq as h

# input
n, m = map(int, input().split())
la = list(map(lambda x: int(x)*-1, input().split()))

h.heapify(la)

while m > 0:
    max = abs(la[0])
    h.heapreplace(la, (max // 2)*-1)
    m -= 1

print(abs(sum(la)))
### BUGGY CODE ###

import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    A_ = [int(input()) for _ in range(N)]

    max_A = max(A_)
    
    for i in range(N):
        if A_[i] == max_A:
            L = A_[0:i]
            L.extend(A_[i+1:])
            print(max(L))
        else:
            print(max_A)
            
if __name__ == "__main__":
    main()


### FIXED CODE ###

import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    A_ = [int(input()) for _ in range(N)]

    max_A = max(A_)
    if A_.count(max_A) > 1:
        for i in range(N):
            print(max_A)
            
    else:
        for i in range(N):
            if A_[i] == max_A:
                L = A_[0:i]
                L.extend(A_[i+1:])
                print(max(L))
            else:
                print(max_A)

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

n,q=map(int, input().split())
s=input()
a=[0]*q
b=[0]*q
for i in range(q):
    a[i], b[i] = map(int, input().split())
    
lst=[0]*(n-1)

for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        lst[i]=1

for i in range(q):
    c=lst[a[i]-1:b[i]-1]
    print(c.count(1))

### FIXED CODE ###

import sys
input=sys.stdin.readline
n,q=map(int,input().split())
s=input().rstrip()

lst=[0]
for i in range(1,n):
    if s[i-1]=="A" and s[i]=="C":
        lst.append(lst[i-1]+1)
    else:
        lst.append(lst[i-1])

for i in range(q):
    l,r=map(int,input().split())
    print(lst[r-1]-lst[l-1])
### BUGGY CODE ###

Q = int(input())
INF = 10 ** 9

from bisect import insort_left

ary, absum, bsum, c = [], 0, 0, 0
left, right = -INF, INF
for _ in range(Q):
    query = input()
    if query[0] == '2':
        # absum = sum(abs(a - ary[(c-1)//2]) for a in ary)
        # absum = asum - (c//2 + 1) * ary[(c-1)//2]
        # print(' '.join(map(str, (ary[(c-1)//2], absum + bsum))))
        print(str(ary[(c-1)//2]) + ' ' + str(absum + bsum))
    else:
        _, a, b = map(int, query.split())
        insort_left(ary, a)
        c += 1
        if left <= a <= right:
            absum += 0
        elif a < left:
            absum += left - a
        else:
            absum += a - right
        left, right = ary[(c-1)//2], ary[c - (c-1)//2 - 1]        
        bsum += b


### FIXED CODE ###

Q = int(input())
INF = 10 ** 9

queries = []
for _ in range(Q):
    queries.append(input())

from bisect import insort_left
from heapq import heappush, heappop

absum, bsum, c = 0, 0, 0
# left, right = -INF, INF
lefts, rights = [INF], [INF]
for query in queries:
    if query[0] == '2':
        # absum = sum(abs(a - ary[(c-1)//2]) for a in ary)
        # absum = asum - (c//2 + 1) * ary[(c-1)//2]
        # print(' '.join(map(str, (ary[(c-1)//2], absum + bsum))))
        # print(str(ary[(c-1)//2]) + ' ' + str(absum + bsum))
        print(-lefts[0], absum + bsum)
    else:
        _, a, b = map(int, query.split())
        if c % 2 == 0:
            if -lefts[0] <= a <= rights[0]:
                heappush(lefts, -a)
                heappush(rights, a)
                absum += 0
            elif a < -lefts[0]:
                heappush(lefts, -a)
                heappush(rights, -lefts[0])
                absum += -lefts[0] - a
            else:
                heappush(rights, a)
                heappush(lefts, -rights[0])
                absum += a - rights[0]
        else:
            if a < -lefts[0]:
                absum += -lefts[0] - a
                heappop(lefts)
                heappush(lefts, -a)
            else:
                absum += a - rights[0]
                heappop(rights)
                heappush(rights, a)
        # left, right = ary[(c-1)//2], ary[c - (c-1)//2 - 1]        
        bsum += b
        c += 1
### BUGGY CODE ###

import bisect
from collections import deque
n,m,k=map(int,input().split())
a=deque(map(int,input().split()))
b=deque(map(int,input().split()))
a_sum=deque()
b_sum=deque()
a_sum.append(0)
b_sum.append(0)
for i in range(n):
    a_sum.append(a_sum[i]+a[i])
for j in range(m):
    b_sum.append(b_sum[j]+b[j])
ans=0
for x in range(n+1):
    timecount=k-a_sum[x]
    if timecount>=0:
        y=bisect.bisect_right(b_sum,k-a_sum[x])-1
        ans=max(x+y,ans)
    else:
        break
print(ans)
    

### FIXED CODE ###

import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_sum=[]
b_sum=[]
a_sum.append(0)
b_sum.append(0)
for i in range(n):
    a_sum.append(a_sum[i]+a[i])
for j in range(m):
    b_sum.append(b_sum[j]+b[j])
ans=0
for x in range(n+1):
    timecount=k-a_sum[x]
    if timecount>=0:
        y=bisect.bisect_right(b_sum,k-a_sum[x])-1
        ans=max(x+y,ans)
    else:
        break
print(ans)
### BUGGY CODE ###

import sys,bisect

from sys  import stdin,stdout

from bisect import bisect_left,bisect_right,bisect,insort,insort_left,insort_right

from math import gcd,ceil,floor,sqrt

from collections import Counter,defaultdict,deque,OrderedDict

dx=[-1,1,0,0]
dy=[0,0,1,-1]


sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 998244353
mod = 10**9+7

def isPrime(n):
    if (n <= 1) :return False
    if (n <= 3) :return True
    if (n%2 == 0 or n%3 == 0):return False
    for i in range(5,ceil(sqrt(n))+1,6):
        if (n%i==0 or n%(i+2)==0):
            return False
    return True

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def CC(d,v,i,l):
    v[i]=True
    stack=[i]
    c=1
    while stack:
        a=stack.pop()
        for i in d[a]:
            if not v[i]:
                stack.append(i)
                v[i]=True
                c+=1
    l.append(c)
    
def solve():
    n,m=mp()
    d={i:[] for i in range(1,n+1)}
    for i in range(m):
        a,b=mp()
        d[a].append(b)
        d[b].append(a)

    v=[False for i in range(n+1)]
    x=[]
    for i in range(1,n+1):
        if not v[i]:
            CC(d,v,i,x)


    x.sort()
    cd=0
    while sum(x)!=0:
        for i in range(len(x)):
            if x[i]>0:
                x[i]-=1
        cd+=1
    pr(cd)
        
        
    
for _ in range(1):
    solve()



### FIXED CODE ###

import sys,bisect

from sys  import stdin,stdout

from bisect import bisect_left,bisect_right,bisect,insort,insort_left,insort_right

from math import gcd,ceil,floor,sqrt

from collections import Counter,defaultdict,deque,OrderedDict

dx=[-1,1,0,0]
dy=[0,0,1,-1]


sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 998244353
mod = 10**9+7

def isPrime(n):
    if (n <= 1) :return False
    if (n <= 3) :return True
    if (n%2 == 0 or n%3 == 0):return False
    for i in range(5,ceil(sqrt(n))+1,6):
        if (n%i==0 or n%(i+2)==0):
            return False
    return True

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def CC(d,v,i,l):
    v[i]=True
    stack=[i]
    c=1
    while stack:
        a=stack.pop()
        for i in d[a]:
            if not v[i]:
                stack.append(i)
                v[i]=True
                c+=1
    l.append(c)
    
def solve():
    n,m=mp()
    d={i:[] for i in range(1,n+1)}
    for i in range(m):
        a,b=mp()
        d[a].append(b)
        d[b].append(a)

    v=[False for i in range(n+1)]
    x=[]
    for i in range(1,n+1):
        if not v[i]:
            CC(d,v,i,x)
           
    pr(max(x))
        
        
    
for _ in range(1):
    solve()
### BUGGY CODE ###

N, A, B=map(int,input().split())
llist=[N]
for i in range(N-1):
    if i<A:
       llist.append("blue")
    elif (i>B+1) and A>1 :
       llist.append("blue")
    else :
        llist.append("red")

print(llist.count("blue"))

### FIXED CODE ###


n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)
### BUGGY CODE ###

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

from pprint import pprint as pp
from pprint import pformat as pf

import math


if __name__ == '__main__':
    a, b, n = map(int, input().split())

    m = 0
    for x in range(n + 1):
        k = ((a * x) // b) - a * (x // b)
        #print('x, k, m', x, k, m) # debug
        m = max(m, k)
    print(m) # debug



### FIXED CODE ###

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

from pprint import pprint as pp
from pprint import pformat as pf

import math

def calc(a, b, x):
    return math.floor(a * x / b) - a * math.floor(x / b)

if __name__ == '__main__':
    a, b, n = map(int, input().split())
    if b > n:
        m = calc(a, b, n)
    else:
        m = calc(a, b, b - 1)
    print(m)
### BUGGY CODE ###

# distutils: language=c++
# cython: language_level=3, boundscheck=False, wraparound=False
# cython: cdivision=True

def INT(): return int(input())
def MAPINT(): return map(int, input().split())
def LMAPINT(): return list(map(int, input().split()))
def STR(): return input()
def MAPSTR(): return map(str, input().split())
def LMAPSTR(): return list(map(str, input().split()))

def main():
  n = INT()
  a = sorted(LMAPINT())

  ans = [0] * (max(a) + 1)
  for x in a:
    # 重複
    if ans[x] != 0:
      ans[x] = 2
    else:
      for j in range(x, max(a)+1, x):
        ans[j] += 1
  
  print(len(list(filter(lambda x: ans[x] == 1, a))))


if __name__ == '__main__':
  main()

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
 
xs = [0] * (max(a) + 1)
 
for v in a:
    if xs[v] == 0:
        for j in range(v, len(xs), v):
            xs[j] += 1
    else:
        xs[v] += 1
print(len(list(filter(lambda v: xs[v] == 1, a))))
### BUGGY CODE ###

n,m=map(int,input().split())
l=[[] for _ in range(n)]
l2=[]

for i in range(m):
  p,y=map(int,input().split())
  l[p-1].append(y)
  l2.append([p,y])
for m in l:
  m.sort()

for m in l2:
  print("{:06d}".format(m[0]) +"{:06d}".format(l[m[0]-1].index(m[1])+1))


### FIXED CODE ###

n,m=map(int,input().split())
import bisect
l=[[] for _ in range(n)]
l2=[]

for i in range(m):
  p,y=map(int,input().split())
  bisect.insort_left(l[p-1],y)
  l2.append([p,y])

for m in l2:
  print("{:06d}".format(m[0]) +"{:06d}".format(bisect.bisect_left(l[m[0]-1],m[1])+1))
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
num=[0,2,5,5,4,5,6,3,7,6]
dp=[[1,0,0,0,0,0,0,0,0,0]]
tmp=0
tmp1=0
tmp2=0
for i in range(0,N+1):
    dp.append([0,0,0,0,0,0,0,0,0,0])
    tmp=0
    for j in A:
        if(i-num[j]>=0):
            tmp1=dp[i-num[j]].copy()
            #存在しないなら不可
            if(tmp1[0]==0):
                continue
            tmp1[j]+=1
            tmp2=0
            for k in range(1,10):
                if(tmp1[10-k]!=0):
                    tmp2*=(10**tmp1[10-k])
                    tmp2+=(10-k)*int("1"*tmp1[10-k])
            tmp2=int("9"*tmp1[9]+"8"*tmp1[8]+"7"*tmp1[7]+"6"*tmp1[6]+"5"*tmp1[5]+"4"*tmp1[4]+"3"*tmp1[3]+"2"*tmp1[2]+"1"*tmp1[1])
            if(tmp2>tmp):
                tmp=tmp2
                dp[i]=tmp1
ans=0
for k in range(1,10):
    if(dp[N][10-k]!=0):
        ans*=10**dp[N][10-k]
        ans+=(10-k)*int("1"*dp[N][10-k])
print(int(ans))
    


### FIXED CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
if(1 in A):
    if(4 in A):
        A.remove(4)
    if(9 in A):
        A.remove(9)
    if(6 in A):
        A.remove(6)
if(5 in A):
    if(3 in A):
        A.remove(3)
    if(2 in A):
        A.remove(2)
if(3 in A):
    if(2 in A):
        A.remove(2)
if(9 in A):
    if(6 in A):
        A.remove(6)
if(7 in A):
    if(9 in A):
        A.remove(9)
    if(6 in A):
        A.remove(6)
num=[0,2,5,5,4,5,6,3,7,6]
dp=[0]
keta=[0]
tmp=0
tmp1=0
tmp_keta=-1
tmp1_keta=-1
for i in range(1,N+1):
    tmp=-1
    tmp_keta=-1
    for j in A:
        tmp1=-1
        tmp1_keta=-1
        if(i-num[j]>=0):
            if(dp[i-num[j]]>0):
                tmp1=dp[i-num[j]]+j*(10**keta[i-num[j]])
                tmp1_keta=keta[i-num[j]]+1
            elif(dp[i-num[j]]==0):
                tmp1=j
                tmp1_keta=1

            if(tmp1>tmp):
                tmp=tmp1
                tmp_keta=tmp1_keta
                
    dp.append(tmp)
    keta.append(tmp_keta)
print(dp[N])
### BUGGY CODE ###

h,*s=open(0)
h,w,k=map(int,h.split())
s=[list(map(int,t[:w]))for t in s]
m=9e9
for i in range(1<<h-1):
  t=[]
  b=v=l=0
  for j in range(h):
    if i>>j&1:
      t+=s[b:j+1],
      b=j+1
      l+=1
  t+=s[b:],
  l+=1
  c=[0]*l
  for i in range(w):
    f=g=0
    u=[]
    for j in range(l):
      d=sum(t[i]for t in t[j])
      u+=d,
      if d>k:
        g=1
        break
      c[j]+=d
      f|=c[j]>k
    else:
      v+=f
      if f:c=u
    if g:break
  else:m=min(m,v+l-1)
print(m)

### FIXED CODE ###

h,*s=open(0)
h,w,k=map(int,h.split())
s=[list(map(int,t[:w]))for t in s]
m=9e9
for i in range(1<<h-1):
  t=[]
  b=v=l=0
  for j in range(h):
    if i>>j&1:
      t+=s[b:j+1],
      b=j+1
      l+=1
  t+=s[b:],
  l+=1
  c=[0]*l
  for i in range(w):
    f=g=0
    u=[]
    for j in range(l):
      d=sum(t[i]for t in t[j])
      u+=d,
      if d>k:
        g=1
        break
      c[j]+=d
      f|=c[j]>k
    else:
      v+=f
      if f:c=u
    if g:break
  else:m=min(m,v+l-1)
print(m)
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline


import math
def equation(a, b, c):
    D = (b**2 - 4*a*c) ** (1/2)
    x_1 = (-b + D) / (2 * a)
    x_2 = (-b - D) / (2 * a)

    return x_1, x_2



def main():
    N = int(input())

    for n in range(1, N+1):
        cnt = 0
        for y in range(1, int(math.sqrt(n))):
            for z in range(1, int(math.sqrt(n))):
                x_1, x_2 = equation(1, y+z, y**2 + y*z + z**2 - n)

                if isinstance(x_1, float):
                    x_1 = round(x_1, 5)
                    if x_1.is_integer() == True and x_1 >= 1:
                        cnt += 1

                if isinstance(x_2, float):
                    x_2 = round(x_2, 5)
                    if x_2.is_integer() == True and x_2 >= 1:
                        cnt += 1

        print(cnt)




if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline


import math

# def equation(a, b, c):
#     D = (b**2 - 4*a*c) ** (1/2)
#     x_1 = (-b + D) / (2 * a)
#     x_2 = (-b - D) / (2 * a)

#     return x_1, x_2



def main():
    n = int(input())

    ans = [0]*(n+1)

    for x in range(1, int(math.sqrt(n))):
        for y in range(1, int(math.sqrt(n))):
            for z in range(1, int(math.sqrt(n))):

                e = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if e >= 1 and e <= n:
                    ans[int(e)] += 1

    for i in range(len(ans)-1):
        print(ans[i+1])




                # x_1, x_2 = equation(1, y+z, y**2 + y*z + z**2 - n)

                # if isinstance(x_1, float):
                #     x_1 = round(x_1, 5)
                #     if x_1.is_integer() == True and x_1 >= 1:
                #         cnt += 1

                # if isinstance(x_2, float):
                #     x_2 = round(x_2, 5)
                #     if x_2.is_integer() == True and x_2 >= 1:
                #         cnt += 1

        # print(cnt)




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

N = int(input())
INF = 10**10
cost = [[INF]*N for _ in range(N)] # INFで初期化v

for u in range(N):
    C = list(map(int, input().split()))
    for v in range(N):
        if u==v: # 自身への道路はINFのままにする
            continue
        cost[u][v] = C[v]
 
ans = 0
for u in range(N):
    for v in range(u+1,N): # u < v
        mn = INF # u-w-vのような経路の中で最小の距離を求める
        for w in range(N):
            mn = min(mn, cost[u][w]+cost[w][v])    
        if (cost[u][v] > mn): # 与えられた行列が最短経路ではない
            print (-1) # 終了して良い
            exit()
        elif (cost[u][v] < mn): # 等しくない場合はu-vを直接結ぶ道路が必要 
            ans += cost[u][v]                      
print (ans)

### FIXED CODE ###

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
INF = float('inf')

for i in range(N):
    A[i][i] = INF

answer = 0
for i in range(N):
    for j in range(i+1, N):
  
        count = INF
        for k in range(N):   
            count = min(count, A[i][k] + A[k][j])
        
        if A[i][j] > count:
            print(-1)
            exit()

        if A[i][j] < count:
            answer += A[i][j]
        
print(answer)
### BUGGY CODE ###

import itertools

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

for _ in range(K):
    B = [0] * N
    for i in range(N):
        l = max(0, i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        if r+1 < N:
            B[r+1] -= 1
    B = list(itertools.accumulate(B))
    A = B.copy()
print(*A)

### FIXED CODE ###

import itertools

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

for _ in range(K):
    B = [0] * N
    for i in range(N):
        l = max(0, i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        if r+1 < N:
            B[r+1] -= 1
    B = list(itertools.accumulate(B))
    A = B.copy()
    if A == [N] * N:
        break
print(*A)
### BUGGY CODE ###

def ans(n, k, list_a):
    i=0
    list_memo=[1]
    while i<k:
        next = list_a[list_memo[i]-1]
        if next not in list_memo:
            list_memo.append(next)
        else:
            num=list_memo.index(next)
            len_list=len(list_memo)
            i+=1
            x = len_list-num
            k=k-num
            
            #print(k)
            k%=x
            return list_memo[num+k]
            #return 50000
            
        i+=1
    return list_memo[i]
        




n, k = (int(x) for x in input().split())
list_a = list(map(int, input().split()))
print(ans(n, k, list_a))

### FIXED CODE ###

def ans(n, k, list_a):
    i=0
    dic={}
    dic[1]=1
    list_memo=[1]
    while i<k:
        next = list_a[list_memo[i]-1]
        if next not in dic:
            list_memo.append(next)
            dic[next]=1
        else:
            num=list_memo.index(next)
            len_list=len(list_memo)
            i+=1
            x = len_list-num
            k=k-num
            
            #print(k)
            k%=x
            return list_memo[num+k]
            #return 50000
            
        i+=1
    return list_memo[i]
        




n, k = (int(x) for x in input().split())
list_a = list(map(int, input().split()))
print(ans(n, k, list_a))
### BUGGY CODE ###

n,k=map(int,input().split())
#a%kを決めればb%kとc%kが決まる
cnt=0
for a_mod in range(k):
  if a_mod==0:
    b_mod,c_mod=0,0
  else:
    b_mod=k-a_mod
    c_mod=k-b_mod
    if c_mod!=k-a_mod:
      continue
  for a in range(a_mod,n+1,k):
    for b in range(b_mod,n+1,k):
      for c in range(c_mod,n+1,k):
        if a!=0 and b!=0 and c!=0:
          cnt+=1
print(cnt)

### FIXED CODE ###

n,k=map(int,input().split())
#a%kを決めればb%kとc%kが決まる
cnt=0
ans=0

for a_mod in range(k):
  if a_mod==0:
    b_mod,c_mod=0,0
  else:
    b_mod=k-a_mod
    c_mod=k-b_mod
    if c_mod!=k-a_mod:
      continue

  cnt_a=0
  for a in range(a_mod,n+1,k):
    if a!=0:
      cnt_a+=1
  ans+=cnt_a**3
print(ans)
### BUGGY CODE ###

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

count = 0
for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        count += 1
    elif a[0] == '2':
        if count % 2 == 0 and a[1] == '1':
            S.insert(0, a[2])
        elif a[1] == '1':
            S.append(a[2])
        elif count % 2 == 0:
            S.append(a[2])
        else:
            S.insert(0, a[2])

print(''.join(S) if count % 2 == 0 else ''.join(S[::-1]))

### FIXED CODE ###

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

count = 0
for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        count += 1
    elif a[0] == '2':
        if count % 2 == 0 and a[1] == '1':
            S.appendleft(a[2])
        elif a[1] == '1':
            S.append(a[2])
        elif count % 2 == 0:
            S.append(a[2])
        else:
            S.appendleft(a[2])


if count % 2 == 0:
    print(''.join(S))
else:
    S.reverse()
    print(''.join(S))
### BUGGY CODE ###

R, G, B, N = map(int, input().split())

rgb = []
s = set([x*B for x in range(N) if x*B <= N])
for r in range(N//R + 1):
    for g in range(N//G + 1):
        if N-r*R-g*G in s:
            rgb.append((r,g,(N-r*R-g*G)//B))

print(len(set(rgb)))

### FIXED CODE ###

R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        tmp = N-r*R-g*G
        if tmp%B == 0:
            ans += 1
print(ans)