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.*;
import java.io.*;

public class _698_B {
	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		int n = Integer.parseInt(in.readLine());
		int[] a = new int[n];
		int[] res = new int[n];
		StringTokenizer line = new StringTokenizer(in.readLine());
		for(int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(line.nextToken()) - 1;
			res[i] = a[i];
		}
		int[] components = new int[n];
		int curcomp = 1;
		ArrayList<Integer> reps = new ArrayList<Integer>();
		int head = -1;
		for(int i = 0; i < n; i++) {
			if(components[i] != 0) continue;
			int rep = dfs(a, i, components, curcomp);
			curcomp++;
			reps.add(rep);
			if(a[rep] == rep) head = rep;
		}
		int count = 0;
		if(head == -1) {
			head = reps.get(0);
			res[reps.get(0)] = reps.get(0); 
			count++;
		}
		for(int i = 0; i < reps.size(); i++) {
			if(reps.get(i) == head) continue;
			res[reps.get(i)] = head;
			count++;
		}
		out.println(count);
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < n; i++) {
			sb.append(res[i] + 1);
			sb.append(' ');
		}
		out.println(sb.toString());
		in.close();
		out.close();
	}
	static int dfs(int[] a, int node, int[] components, int curcomp) {
		if(components[node] != 0) return node;
		components[node] = curcomp;
		return dfs(a, a[node], components, curcomp);
	}
}
