Harryxun/stf_run huggingface dataset:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans


def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2
        
        if rr == mid:
            return ll
        
        if cou(x,mid) <= n:
            rr = mid
        else:
            ll = mid+1

def cou(x,le):
    co = 0
    for i in range(len(x)):
        co += -(-x[i]//le) - 1
    return co


n,k = m()

a = l()

left = 0

right = 10**9


aaa = nibu(a,k,right)
print(aaa)


### FIXED CODE ###

import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans


def nibu(x,n,r):
    ll = 1
    rr = r
    while True:
        mid = (ll+rr)//2
        
        if rr == mid:
            return ll
        
        if cou(x,mid) <= n:
            rr = mid
        else:
            ll = mid+1

def cou(x,le):
    co = 0
    for i in range(len(x)):
        if le != 0:
            co += -(-x[i]//le) - 1
    return co


n,k = m()

a = l()

left = 0

right = 10**9


aaa = nibu(a,k,right)
print(aaa)
a,b = map(int, input().split())
if (a+b) % 2 = 0:
  print(int((a+b)/2))
else:
  print(int((a+b)/2)+1)

### FIXED CODE ###

a,b = map(int, input().split())
if (a+b) % 2 == 0:
  print(int((a+b)/2))
else:
  print(int((a+b)/2)+1)
import math
    R = int(input())
     
    l = 2 * R * math.pi
     
    print(l)

### FIXED CODE ###

import math
R = int(input())

l = 2 * R * math.pi

print(l)
cook = []
for i in range(5):
    cook.append(int(input()))
mn = 10
time = 0
for i in range(5):
    if cook[i]%10 < mn and cook[i]%10!=0:
        ans = i
        mn = cook[i]%10
for i in range(5):
    if i==ans:
        continue
    else:
        if cook[i]%10==0:
            time += cook[i]
        else:
            time += cook[i] + 10-(cook[i]%10)
time += cook[ans]
print(time)

### FIXED CODE ###

s = 0
rests = [None]*5

for i in range(5):
    t_num = int(input())
    s += t_num
    rests[i] = (10 - (t_num % 10)) % 10 

print(s + sum(rests)- max(rests))
while True:
    (n,x) = [int(i) for i in input().split()]

    for a in range(1, n + 1 - 2):
        for b in range(a + 1, n + 1 - 1):
            for c in range(b + 1,n + 1):
                if (a + b + c) == x:
                    count += 1
    print(count) 

### FIXED CODE ###

while True:
    (n,x) = [int(i) for i in input().split()]
    if n == x == 0:
        break
    
    count = 0
    for a in range(1, n + 1 - 2):
        for b in range(a + 1, n + 1 - 1):
            for c in range(b + 1,n + 1):
                if (a + b + c) == x:
                    count += 1
    print(count)
import math
from functools import reduce

N, X = map(int, input().split())
x = list(map(int, input().split()))

ans = []
for i in x:
	ans.append(abs(i - X))

print(reduce(math.gcd, ans))

### FIXED CODE ###

import fractions
from functools import reduce

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

for i in range(len(a)):
	a[i] = abs(a[i] - x)

print(reduce(fractions.gcd, a))
import math

A, B = map(int, input().split)
min1 = math.gcd(A, B)

max1 = max(A, B)

for i in range(100000000):
  s = min1 * i
  if max1 < s:
    break
    
print(s)

### FIXED CODE ###

A, B = map(int,input().split())

def gcd(m, n):
  x = max(m, n)
  y = min(m, n)
  
  if x % y == 0:
    return y
  
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z
      
def lcm(m, n):
  return int(m * n / gcd(m, n))

print(lcm(A, B))
n, k = map(int, input().split())

li = [0]
li.extend(list(map(int, input().split())))

def search(town, times):
  if times == 0:
    return town
  else:
    nextTown = li[town]
    return search(nextTown, times-1)

tuita = [0]*(n+1)
cnt = 0
town = 1

while True:
  town = li[town]
  cnt += 1
  if tuita[town] == 0:
    tuita[town] = cnt
  else:
    if k < tuita[town]:
      print(search(1, k))
    elif k == tuita[town]:
      print(town)
    else:
      print(search(town, (k - tuita[town]) % (cnt - tuita[town])))
    break
 

### FIXED CODE ###

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

li = [0]
li.extend(list(map(int, input().split())))
tuita = [0]*(n+1)
cnt = 0
town = 1

lastTown = 1
while True:
  town = li[town]
  cnt += 1
  if tuita[town] == 0:
    tuita[town] = cnt
  else:
    if k < tuita[town]:
      lastTown = 1
      times = k
    elif k == tuita[town]:
      lastTown = town
      times = 0
    else:
      lastTown = town
      times = (k - tuita[town]) % (cnt - tuita[town])
    break

town = lastTown
while times > 0:
  if times <= 0:
    break
  times -= 1
  town = li[town]
print(town)
def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a


def main():
    N, X = map(int, input().split())
    x = [abs(int(i) - X) for i in input().split()] 

    y = x[0]
    for i in range(N):
        if x[i]%y == 0:
            continue
        y = gcd(y, x[i])
    print(y)


if __name__ == '__main__':
    main()

### FIXED CODE ###

A, B = map(int, input().split())

if (A*B % 2) == 0:
    print('No')
else:
    print('Yes')
N=int(input())
A=sorted(list(map(int,input().split())))
C=[0]*(max(A)+1)

for i in A:
    C[i]+=1

T=max(C[0]+C[1],C[-1]+C[-2])
for i in range(1,max(A)):
    T=max(T,C[i-1]+C[i]+C[i+1])

print(T)

### FIXED CODE ###

N=int(input())
A=sorted(list(map(int,input().split())))
C=[0]*(max(A)+1)

for i in A:
    C[i]+=1

if len(C)==1:
    print(C[0])
else:
    T=max(C[0]+C[1],C[-1]+C[-2])
    for i in range(1,max(A)):
        T=max(T,C[i-1]+C[i]+C[i+1])
    print(T)
from collections import defaultdict
N =int( input())
col_nodes = defaultdict(set)
node_col = {}
col = 1
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u_col, v_col = node_col.get(u, 0), node_col.get(v, 0)
    if (0 in [u_col, v_col]) and (u_col or v_col):
        if u_col == 0:
            node_col[u] = v_col * [1, -1][w % 2]
            col_nodes[v_col] = col_nodes[v_col] | {u}
        else:
            node_col[v] = u_col * [1, -1][w % 2]
            col_nodes[u_col] = col_nodes[u_col] | {v}
        continue
    col_ = col * [1, -1][w % 2]
    node_col[u] = col
    node_col[v] = col_
    if u_col and v_col:
        col_nodes[col] = col_nodes[col] | col_nodes.pop(u_col)
        col_nodes[col_] = col_nodes[col_] | col_nodes.pop(v_col)
        continue
    col_nodes[col] =  col_nodes[col] | {u}
    col_nodes[col_] = col_nodes[col_] | {v}
    col += 1
        
for n in range(1, N + 1):
    print([0, 1][node_col[n] > 0])

### FIXED CODE ###

N = int(input())
lis = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    lis[u] += [v * [-1, 1][w % 2]]
    lis[v] += [u * [-1, 1][w % 2]]
colors = [-1 for _ in range(N + 1)]

q = [1]
colors[1] = 0
while q:
    start = abs(q.pop(0))
    nodes = lis[start]
    for node in nodes:
        if colors[abs(node)] < 0:
            if node < 0:
                colors[abs(node)] = colors[start]
            else:
                colors[abs(node)] = int(colors[start] == 0)
            q.append(abs(node))

for c in colors[1:]:
    print(c)
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

def getInputStr():
    inputStr = str(input())
    return inputStr

data = getInputStr()

a = str(data)
listStr = []
listStr = list(a)

del listStr[len(listStr)-1]
listStr.reverse()

dp = [[0]*13 for _ in range(len(listStr)+1)]
dp[0][0] = 1
ordinal = 1

INF = 10 ** 9 + 7

for i in range(len(listStr)):
    if listStr[i] == "?":
        for k in range(10):
            for j in range(13):
                dp[i+1][int(((k*ordinal) + j) % 13)] += dp[i][j]
                dp[i + 1][int(((k * ordinal) + j) % 13)] %= INF
    else:
        k = int(listStr[i])
        for j in range(13):
            tmp = int()
            dp[i + 1][int(((k*ordinal) + j) % 13)] += dp[i][j]
            dp[i + 1][int(((k*ordinal) + j) % 13)] %= INF
    ordinal = ordinal * 10 % 13

print(dp[len(listStr)][5])

### FIXED CODE ###

import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
nb = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    l = len(s)
    dp = [[0 for _ in range(13)] for __ in range(l + 1)]
    dp[0][0] = 1

    for i, si in enumerate(s):
        base = pow(10, l - i - 1, 13)

        if si == "?":
            for k in range(10):
                tmp = base * k % 13
                for j in range(13):
                    dp[i + 1][(j + tmp) % 13] += dp[i][j]
                    dp[i + 1][(j + tmp) % 13] %= MOD
        else:
            si = int(si)
            tmp = base * si % 13
            for j in range(13):
                dp[i + 1][(j + tmp) % 13] += dp[i][j]
                dp[i + 1][(j + tmp) % 13] %= MOD

    print(dp[l][5])


if __name__ == '__main__':
    main()
a=map(int,input().split())
print(max(a)-min(a))

### FIXED CODE ###

a=list(map(int,input().split()))
print(max(a)-min(a))
N = int(input())
A = list[map(int, input().split())]
B = list[map(int, input().split())]
C = list[map(int, input().split())]

total = 0
pos = 0
while pos < N:
  total = total + B[A[pos] - 1]
  if A[pos + 1] - A[pos] == 1:
    total = total + C[A[pos + 1] - 2]
print(total)

### FIXED CODE ###

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

total = 0
pos = 0
while pos< N:
	posB = A[pos] -1
	total = total + B[posB]
	if A[pos] - A[pos - 1] == 1 and pos > 0:
		posC = A[pos] - 2
		total = total + C[posC]
	pos += 1
print(total)
N = int(input())
# A = list(map(int, input().split()))
A = input().split()

# print(A)
c = [0, 0, 0]
# r = 0
# b = 0
# g = 0
sum = 1
# print(c)
for a in A:
    a = int(a)
    # print(a)
    if a == c[0]:
        c[0] += 1
        tmp = c.count(c[0] - 1) + 1
    elif a == c[1]:
        c[1] += 1
        tmp = c.count(c[1]-1) + 1
    elif a == c[2]:
        c[2] += 1
        tmp = c.count(c[2] - 1) + 1
    # print(tmp)
    sum *= tmp
    # print(c)
print(sum % 1000000007)


### FIXED CODE ###

N = int(input())
A = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]
 
for a in A:
    ans = ans * cnt[a] % MOD
    if ans == 0:
        break
    cnt[a] -= 1
    cnt[a+1] += 1
 
print(ans)
def solve(n):
    k = 1
    while k * (k + 1) < 2 * n:
        k += 1
    if k * (k + 1) != 2 * n:
        return False, []
    ans = [[] for _ in range(1000)]
    add_num = 1
    ans[1].append(add_num)
    ans[0].append(add_num)
    for i in range(2, k + 1):
        for j in range(i):
            add_num += 1
            ans[i].append(add_num)
            ans[i - j - 1].append(add_num)
    return True, ans, k


def main():
    n = int(input())
    res, ans, k = solve(n)
    if res:
        print("Yes")
        print(k + 1)
        for a in ans:
            if a:
                print(len(a), " ".join(map(str, a)))
            else:
                break
    else:
        print("No")


if __name__ == '__main__':
    main()


### FIXED CODE ###

def solve(n):
    k = 1
    while k * (k + 1) < 2 * n:
        k += 1
    if k * (k + 1) != 2 * n:
        return False, [], -1
    ans = [[] for _ in range(1000)]
    add_num = 1
    ans[1].append(add_num)
    ans[0].append(add_num)
    for i in range(2, k + 1):
        for j in range(i):
            add_num += 1
            ans[i].append(add_num)
            ans[i - j - 1].append(add_num)
    return True, ans, k


def main():
    n = int(input())
    res, ans, k = solve(n)
    if res:
        print("Yes")
        print(k + 1)
        for a in ans:
            if a:
                print(len(a), " ".join(map(str, a)))
            else:
                break
    else:
        print("No")


if __name__ == '__main__':
    main()
import sys
sys.setrecursionlimit(3000)

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

D=[[0 for i in range(2)] for j in range(M)]
for x in range(M):
    D[x][0],D[x][1]= map(int, input().split())

D=sorted(D, key=lambda x : x[1],reverse=True)
num=0
for y in range(M): #どの要素を代入するか
    for z in range(D[y][0]): #どこに要素を代入するか
        if A[z+num]>=D[y][1]:
            break
        else:
            A[z+num]=D[y][1]
    else:
        num += D[y][0]
        continue
    break
print(A)
print(sum(A))

### FIXED CODE ###

from sys import exit

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))
BC.sort(key=lambda x: -x[1])
A.sort()

i = 0
for b, c in BC:
    for x in range(b):
        if i < N and A[i] < c:
            A[i] = c
            i += 1
        else:
            print(sum(A))
            exit()
print(sum(A))
import sys
S = input()
cnt = [False] * 30
for i in S:
    if i in "abcdefghijklmnopqrstuvwxyz"
    cnt[ord(i) - ord('a')] = True
 
for i in range(len(cnt)):
    if not cnt[i]:
        print(chr(ord('a')+i))
        sys.exit()
print("None")

### FIXED CODE ###

import sys
S = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"

for s in alphabet:
    if s not in S:
        print(s)
        sys.exit()

print("None")
h,a=divmod(int(input()))
m,s=divmod(a)
print(h+":"+m+":"+s)

### FIXED CODE ###

h,a=divmod(int(input()), 3600)
m,s=divmod(a,60)
print("{}:{}:{}".format(h,m,s))
n = int(input())
count = 0

for i in range(1,n):
  for j in range(1,n):
    if(a*b < n):
      count += 1
      
print(count)

### FIXED CODE ###

n = int(input())
count = ((n-1) * 2) -1

for i in range(2,n):
  if(i*2 >= n):
    break
  for j in range(2,n):
    if(i*j < n):
      count += 1
    else:
      break
    
print(count)
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
IronMan = sorted(p)
CaptainAmerica = sorted(q)
for i in range(X):
    r.append(IronMan.pop())
for i in range(Y):
    CaptainAmerica.append(q.pop())
SpiderMan = sorted(r)[::-1]
print(sum(SpiderMan[:X+Y]))


### FIXED CODE ###

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
IronMan = sorted(p)
CaptainAmerica = sorted(q)
for i in range(X):
    r.append(IronMan.pop())
for i in range(Y):
    r.append(CaptainAmerica.pop())
SpiderMan = sorted(r)[::-1]
print(sum(SpiderMan[:X+Y]))
a,b = input().split(' ')

if a == "H":
    print(b)
else if b == "H":
    print(a)
else:
    print("H")

### FIXED CODE ###

a,b = input().split(' ')
 
if a == "H":
    print(b)
elif b == "H":
    print(a)
else:
    print("H")
va, b, k = [int(i) for i in input().split()]
print(*([i for i in range(a, min(a + k, b + 1))] + [i for i in range(max(a + k, b - k + 1), b + 1)]), sep="\n")

### FIXED CODE ###

a, b, k = [int(i) for i in input().split()]
print(*([i for i in range(a, min(a + k, b + 1))] + [i for i in range(max(a + k, b - k + 1), b + 1)]), sep="\n")
import sys
import math

def main():
    a, b, k = [int(x) for x in sys.stdin.readline().split()]
    
    query_range = list(range(a, b + 1))
    if a == b:
        res = query_range
    elif k >= math.ceil((b - a + 1) / 2):
        res = query_range
    else:
        res = query_range[:k] + query_range[-k:]
    
    for i in res:
        print(i)
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

a, b, k = map(int, sys.stdin.readline().split())

def main():
    if k >= b - a + 1:
        res = list(range(a, b+1))
    else:
        res = set(range(a, a+k)) | set(range(b, b-k, -1))
        res = sorted(res)
    return res

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')
S = int(input())
total=10*10
if(S%2==1):
    total=S*((S-1)//2)
else:
    total=(S-1)*((S-2)//2)+(S-1)

print(total)

### FIXED CODE ###

S = input()
T = input()

total=0
for i in range(3):
    if(S[i]==T[i]):
        total+=1
print(total)
L, R = map(int, input().split())
min_mod = 2019
flg=[0]*2018
flg2=[0]*2018
for i in range(L,R):
    idx=i%2019
    if flg[idx]==0:
        for j in range(i+1,R+1):
            mod  = (i*j)%2019
            if flg2[mod]==1:
                break
            flg2[mod]=1
            if min_mod > mod:
                min_mod=mod
        flg[idx]=1
print(min_mod)

### FIXED CODE ###

L, R = map(int, input().split())
min_mod = 2019
flg=[0]*2019
flg2=[0]*2019
for i in range(L,R):
    idx=i%2019
    if flg[idx]==1:
        break
    if flg[idx]==0:
        for j in range(i+1,R+1):
            mod  = (i*j)%2019
            if flg2[mod]==1:
                break
            flg2[mod]=1
            if min_mod > mod:
                min_mod=mod
        flg[idx]=1
print(min_mod)
strings=[input() for string in range(2)]
string=strings[0]
num=int(strings[1])
i=0
check=True

while check:
    s=string[i:i+num]
    if len(s)<num:
        check=False
    print(s)
    i=i+num

### FIXED CODE ###

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

check=0
if a[0]+a[1]==15:
    check=1
elif a[0]*a[1]==15:
    check=2

if check==1:
    print("+")
elif check==2:
    print("*")
else:
    print("x")
s = input()
gx, gy = map(int, input().split())
n = len(s)
X, Y = [], []
x, y, flag = 0, 0, 0
for i in range(n):
    if s[i] == 'F' and flag == 0:
        x += 1
    elif s[i] == 'F' and flag == 1:
        y += 1
    else:
        if flag and y > 0:
            Y.append(y)
            y = 0
        elif not flag and x > 0:
            X.append(x)
            x = 0
        flag = (flag + 1) % 2
if flag and y > 0:
    Y.append(y)
elif not flag and x > 0:
    X.append(x)
gx -= X[0]
if len(X):
    X.pop(0)
for x in sorted(X, reverse = True):
    if gx > 0:
        gx -= x
    else:
        gx += x
for y in sorted(Y, reverse = True):
    if gy > 0:
        gy -= y
    else:
        gy += y
if gx == gy == 0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

S = input() + 'E'
gx, gy = map(int, input().split())
X, Y = [], []
x, y, i, flag = 0, 0, 0, 1
while i <= len(S):
    f = 0
    while S[i] == 'F':
        f += 1
        i += 1
    if flag:
        X.append(f)
    else:
        Y.append(f)
    flag = (flag + 1) % 2
    if S[i] == 'E':
        break
    i += 1
gx -= X[0]
for x in sorted(X[1:], reverse = True):
    if gx > 0:
        gx -= x
    else:
        gx += x
for y in sorted(Y, reverse = True):
    if gy > 0:
        gy -= y
    else:
        gy += y
if gx == gy == 0:
    print("Yes")
else:
    print("No")
x = map(int, input().split())
x.sort()
if x[0] == 5 and x[1] == 5 and x[2]== 5:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

x = list(map(int, input().split()))
x.sort()
if x[0] == 5 and x[1] == 5 and x[2]== 7:
  print("YES")
else:
  print("NO")
N = int(input())
A = list(map(lambda x:int(x)-1,input().split()))
ans = 0
paired = []
for i in range(n):
    if i in paired:
        continue
    else:
        if A[A[i]] == i:
            ans += 1
            paired.append(i)
            paired.append(A[i])
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(lambda x:int(x)-1,input().split()))
ans = 0
paired = []
flag = [0]*N
for i in range(N):
    if flag[i]:
        continue
    else:
        if A[A[i]] == i:
            ans += 1
            flag[A[i]] = 1
print(ans)
import math
n,a,b = map(int,input().split())
mod = 10**9+7
ans = pow(2,n,mod)
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, N + 1):
    g1.append( (g1[-1]*i) % mod)
    inverse.append( (-inverse[mod % i] * (mod//i)) % mod)
    g2.append( (g2[-1]*inverse[-1]) % mod)
ans = ans-(cmb(n,a,mod)+cmb(n,b,mod))-1
print(ans)

### FIXED CODE ###

N,R = map(int,input().split())
if N >= 10:
  print(R)
else:
  print(R+100*(10-N))
a, b = map(float, input().split())

print(long(a * b))

### FIXED CODE ###

from math import floor
import decimal
a, b = input().split()
a = int(a)
b = decimal.Decimal(b)
#print(a, b)
#print(type(a), type(b))
print(floor(a * b))
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        if (N * h * n) % (4 * h * n - N * n - N * h) == 0:
            w = (N * h * n) // (4 * h * n - N * n - N * h)
            print(h, n, w)
            break

### FIXED CODE ###

N = int(input())
end = False
for h in range(1, 3501):
    if end:
        break
    for n in range(1, 3501):
        if (4 * h * n - N * n - N * h):
            if (N * h * n) % (4 * h * n - N * n - N * h) == 0:
                w = (N * h * n) // (4 * h * n - N * n - N * h)
                if w > 0:
                    print(h, n, w)
                    end = True
                    break