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 

//package LongChallenges;
import java.util.*;
public class May {
	static boolean[] done;
	static List<Integer> list = new ArrayList<>();
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		 int n = sc.nextInt();
         int[] cycles = new int[n];
         int cyclePtr = 0;
         int identity = -1;
         int[] a = new int[n];
         for (int i = 0; i < n; ++i) {
             a[i] = sc.nextInt() - 1;
             if (a[i] == i) identity = i;
         }
         int[] mark = new int[n];
         int gen = 0;
         for (int i = 0; i < n; ++i)
             if (mark[i] == 0) {
                 ++gen;
                 int j = i;
                 while (mark[j] == 0) {
                     mark[j] = gen;
                     j = a[j];
                 }
                 if (mark[j] == gen) {
                     cycles[cyclePtr++] = j;
                 }
             }
         cycles = Arrays.copyOf(cycles, cyclePtr);
         int res = cyclePtr - 1;
         if (identity < 0) {
             ++res;
             a[cycles[0]] = cycles[0];
             identity = cycles[0];
         }
         for (int x : cycles) {
             if (x != identity) {
                 a[x] = identity;
             }
         }
         System.out.println(res);
         for (int i = 0; i < n; ++i) {
             if (i > 0) System.out.print(" ");
             System.out.print(a[i] + 1);
         }
         System.out.println();
     }
	
}