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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;


public class B {

	private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	private static PrintStream out = System.out;
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt(in.readLine());
		String[] s = in.readLine().split(" ");
		int[] parents = new int[n];
		int root = -1;
		for (int i = 0; i < n; ++i) {
			parents[i] = Integer.parseInt(s[i]) - 1;
			if (i == parents[i])
				root = i;
		}
		int cnt = 0;
		int[] seen = new int[n];
		for (int i = 0; i < n; ++i)
			seen[i] = -1;
		for (int curr = 0; curr < n; ++curr) {
			int idx = curr;
			while (seen[idx] == -1 && parents[idx] != idx) {
				seen[idx] = curr;
				idx = parents[idx];
			}
			if (seen[idx] == curr && parents[idx] != idx) {
				++cnt;
				if (root == -1) {
					parents[idx] = idx;
					root = idx;
				} else
					parents[idx] = root;
			} else if (parents[idx] == idx && idx != root) {
				++cnt;
				parents[idx] = root;
			}
		}
		out.println(cnt);
		for (int i = 0; i < n; ++i)
			out.print((parents[i] + 1) + " ");
		out.println();
	}

}
