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 

n=int(input())
a=list(map(int,input().split()))
par=[]
for i in range(n):
	if a[i]==i+1:
		par.append(i)
v=[False for i in range(n)]
for i in par:
	v[i]=True
ccl=[]
for i in range(n):
	if v[i]:continue
	s=[i]
	v[i]=True
	p=set(s)
	t=True
	while s and t:
		x=s.pop()
		j=a[x]-1
		if j in p:
			ccl.append(j)
			t=False
		else:
			s.append(j)
			p.add(j)
		if v[j]:t=False
		else:v[j]=True
if len(par)==0:
	print(len(ccl))
	c=ccl[0]
	a[c]=c+1
	for i in range(1,len(ccl)):
		a[ccl[i]]=c+1
	print(*a)
else:
	print(len(ccl)+len(par)-1)
	c=par[0]
	for i in range(1,len(par)):
		a[par[i]]=c+1
	for i in range(len(ccl)):
		a[ccl[i]]=c+1
	print(*a)