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.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.StringTokenizer;

public class CF698B {
	public static void main(String[] args) throws FileNotFoundException {
		InputStream inputStream = System.in;
//		InputStream inputStream = new FileInputStream(new File("input"));
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		int n;
		int [] a;
		int [] p;

		void makeSet(int id) {
			p[id] = id;
		}

		int find(int id) {
			if (p[id] != id) {
				p[id] = find(p[id]);
			}
			return p[id];
		}

		// from x to y
		void union(int x, int y) {
			int px = find(x);
			int py = find(y);
			if (px == py)
				return;
			p[px] = py;
		}

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			n = in.nextInt();
			a = new int[n + 1];
			p = new int[n + 1];

			for (int i = 1; i <= n; ++i) {
				makeSet(i);
			}

			for (int i = 1; i <= n; ++i) {
				a[i] = in.nextInt();
				union(i, a[i]);
			}
			
			for (int i = 1; i <= n; ++i)
				union(i, a[i]);

			HashSet<Integer> connectedComp = new HashSet<>();
			for (int i = 1; i <= n; ++i) {
				connectedComp.add(p[i]);
			}

			int r = connectedComp.size() - 1;
			List<Integer> roots = new ArrayList<>(connectedComp);
			int root = -1;
			for (int i = 0; i < roots.size(); ++i) {
				int curRoot = roots.get(i);
				if (curRoot == a[curRoot]) {
					root = curRoot;
					break;
				}
			}

			if (root == -1) {
				r += 1;
				root = roots.get(0);
				a[root] = root;
			}

			for (int i = 0; i < roots.size(); ++i) {
				int curRoot = roots.get(i);
				if (curRoot != root) {
					a[curRoot] = root;
				}
			}

			out.println(r);
			for (int i = 1; i <= n; ++i) {
				out.print(a[i] + " ");
			}

		}

	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}