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

public class Codeforces698B {

	public static void main(String[] args) {
		try {
			BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(f.readLine());
			int[] a = new int[n];
			StringTokenizer st = new StringTokenizer(f.readLine());
			for(int i = 0; i < n; i++)
				a[i] = Integer.parseInt(st.nextToken()) - 1;
			int root = -1;
			int numChanges = 0;
			for(int i = 0; i < n; i++) {
				if(a[i] == i)
					root = i;
			}
			if(root == -1) {
				boolean[] visited = new boolean[n];
				visited[0] = true;
				int current = 0;
				while(!visited[a[current]]) {
					visited[a[current]] = true;
					current = a[current];
				}
				a[current] = current;
				numChanges++;
				root = current;
			}
			int[] component = new int[n];
			component[root] = 1;
			int color = 1;
			for(int i = 0; i < n; i++) {
				if(component[i] == 0) {
					color++;
					int current = i;
					component[current] = color;
					while(component[a[current]] == 0) {
						component[a[current]] = color;
						current = a[current];
					}
					if(component[a[current]] == color) {
						a[current] = root;
						numChanges++;
					}
				}
			}
			System.out.println(numChanges);
			StringBuffer s = new StringBuffer("");
			for(int i = 0; i < n; i++) {
				s.append((a[i] + 1) + " ");
			}
			System.out.println(s.toString().trim());
		}
		catch(IOException e) {
			e.printStackTrace();
		}
	}

}
