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 dfs(node,g,vis):
	vis[node]=1

	for i in g[node]:
		if vis[i]==0:
			dfs(i,g,vis)
def dfs2(node,g,vis,path):
	path.append(node)
	vis[node]=1
	for i in g[node]:
		if vis[i]==0:
			dfs2(i,g,vis,path)
def main():
	def f(a):
		n=len(a)
		g=defaultdict(list)
		good=None
		for i in range(0,len(a)):
			if a[i]==i+1 and good==None:
				# print(a[i],i,"lodu")
				good=a[i]
			g[i+1].append(a[i])
			g[a[i]].append(i+1)
		cnt=0
		# print(g)
		if good==None:
			t=max(g.keys(),key=lambda s:len(g[s]))
			g[t].remove(a[t-1])
			g[a[t-1]].remove(t)
			g[t].append(t)
			a[t]=t
			good=t
			cnt+=1
		vis=[0]*(len(a)+1)
		dfs(good,g,vis)
		# print(vis)

		for i in range(1,n+1):
			if i==good-1:
				continue
			if vis[i]==0:
				pah=[]
				dfs2(i,g,vis,pah)
				if pah:
					cnt+=1
				a[i-1]=good
		print(cnt)
		print(*a)
	a=input()
	lst=list(map(int,input().strip().split()))
	f(lst)
threading.stack_size(10 ** 8)
t = threading.Thread(target=main)
t.start()
t.join()
