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 B {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	int[] col;

	void solve() throws IOException {
		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt() - 1;
		}

		col = new int[n];

		List<List<Integer>> lst = new ArrayList<>();
		
		int root = -1;

		for (int i = 0; i < n; i++) {
			if (col[i] == 0) {
				int v = i;
				while (col[v] == 0) {
					col[v] = 1;
					v = a[v];
				}
				List<Integer> cycle = new ArrayList<>();
				if (col[v] == 1) {
					cycle.add(v);
					for (int u = a[v]; u != v; u = a[u]) {
						cycle.add(u);
					}
					lst.add(cycle);
					if (cycle.size() == 1) {
						root = v;
					}
				}
				
				v = i;
				while (col[v] != 2) {
					col[v] = 2;
					v = a[v];
				}
			}
		}
		
		if (root == -1) {
			root = lst.get(0).get(0);
		}
		
		int ans = 0;
		
		for (List<Integer> cycle : lst) {
			if (a[cycle.get(0)] != root) {
				ans++;
				a[cycle.get(0)] = root;
			}
		}
		
		out.println(ans);
		for (int x : a) {
			out.print((x + 1) + " ");
		}
		out.println();
	}

	B() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new B();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}