3
2 1 1
 6
6 2 6 2 4 2
 2
1 2
 8
2 1 2 2 6 5 6 6
 18
2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18
 7
1 2 3 4 5 6 7
 7
4 3 2 6 3 5 2
 7
7 5 3 1 2 1 5
 7
1 6 4 4 5 6 7

1
2 2 1  0
6 2 6 2 4 2  1 
1 1 
 2 
2 2 2 2 6 2 6 6 
 5 
2 3 4 5 11 7 8 9 10 11 11 11 14 15 11 17 18 11 
 6 
1 1 1 1 1 1 1 
 1
4 3 3 6 3 5 2  1
7 5 3 1 3 1 5  4 
1 6 4 1 1 1 1 

from collections import  defaultdict
from sys import stdin,setrecursionlimit
setrecursionlimit(10**6)
import threading
def f(a):
	n=len(a)
	a=list(map(lambda s:s-1,a))
	root=None
	for i in range(len(a)):
		if a[i]==i:
			root=i
	vis=[0]*(n)
	traitors=[]
	for i in range(0,n):
		cycle=-1
		cur=i
		move=set()

		while vis[cur]==0:
			vis[cur]=1
			move.add(cur)
			if a[cur] in move:
				cycle=cur
			cur=a[cur]
		if cycle!=-1:
			traitors.append(cycle)
	ans=len(traitors)-1
	if root==None:
		a[traitors[0]]=traitors[0]
		root=traitors[0]
		ans+=1
	for i in traitors:
		if i!=root:
			a[i]=root
	print(ans)
	a=list(map(lambda s:s+1,a))
	return a
n=input()
a=list(map(int,input().strip().split()))
print(*f(a))