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 


import java.util.*;

public class Main 
{
	int V;
	LinkedList<Integer> list[];
	static int value = Integer.MAX_VALUE;
	
	Main(int V)
	{
		this.V = V;
		list = new LinkedList[V+1];
		for(int i=1;i<=V;i++)
			list[i] = new LinkedList<Integer>();
	}
	
	
	public void addEdge(int src, int dest)
	{
		list[src].add(dest);
		list[dest].add(src);
	}
	
	
	public void dfs(int src, boolean visited[], int cost[])
	{
		visited[src] =true;
		if(value>cost[src])
			value=cost[src];
		for(Integer x:list[src])
		{
			if(!visited[x])
			{
				dfs(x, visited, cost);
			}
		}
	}
	public long dfs(int cost[])
	{
		long answer = 0;

		boolean visited[] = new boolean[V+1];
		for(int i=1;i<=V;i++)
		{
			if(!visited[i])
			{
				dfs(i, visited, cost);
//				System.out.println(value);
//				System.out.println(Arrays.toString(visited));
				answer += value;
				value = Integer.MAX_VALUE;
			}
		}
		return answer;
	}
	
	public static void main(String args[])
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int parent[] = new int[n+1];
		DisjointSetImplementationUsingArray set = new DisjointSetImplementationUsingArray(n);
		int par = -1;
		for(int i=1;i<=n;i++)
		{
			parent[i]  = scan.nextInt();
			if(parent[i] == i)
				par = i;
		}

		int count =0;
		
		
		for(int i=1;i<=n;i++)
		{
			boolean flag  = set.union(parent[i], i);
			if(!flag && par ==-1)
			{
				par = i;
				parent[i] = par;
				count++;
				continue;
			}
			if(!flag && i!=par)
			{
				set.union(i, par);
				parent[i] = par;
				count++;
			}
			else
				continue;
		}
		System.out.println(count);
		System.out.println(Arrays.toString(parent));
	}
	
}class DisjointSetImplementationUsingArray 
{
	public int [] rank;
	public int [] parent;
	public int size[] ;
	
			
	int n;
	
	public DisjointSetImplementationUsingArray(int n) 
	{

		parent = new int[n+1];
		this.n= n;
		size = new int[n+1];
		makeSet();
	}
	
	
	public void makeSet()
	{
		for(int i=0;i<=n;i++)
		{
			parent[i] = i;
			size[i] = 1;
		}
		
	}
	
	
	
	public boolean union(int x, int y) 
    { 
        int xRoot = findSet(x), yRoot = findSet(y); 
        if (xRoot == yRoot) 
            return false; 
  
        if (size[xRoot] < size[yRoot])  
        {
            parent[xRoot] = yRoot; 
            size[yRoot] += size[xRoot];
        }
        else if (size[yRoot] < size[xRoot]) 
        {

            size[xRoot] += size[yRoot];
            parent[yRoot] = xRoot; 
        }
  
        else 
        {  
            parent[yRoot] = xRoot; 
            size[xRoot] += size[yRoot];
            // And increment the the result tree's 
           // rank by 1 
        } 
        return true;
    }
	
	
	
	public int findSet(int x)
	{
		
		if(parent[x]==x)
			return x;
		else
		{
			while(parent[x]!=x)
			{
				x=parent[x];
			}
		}
		return x;
	}
	
	
	public int findSetSize(int element)
	{
		int parent = findSet(element);
		return size[parent];
	}
	
	public int findNoOfSets() 
	{
		HashSet<Integer> hash = new HashSet<Integer>();
		for(int i=0;i<n;i++)
		{
			hash.add(findSet(i));
		}
		return hash.size();
	}
}
	
