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


public class B {	
	BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

    public void go(ArrayList<Integer> sorted, boolean[] reached, int[] parents, int cur) {
        if (reached[cur]) return;
        reached[cur] = true;
        go (sorted, reached, parents, parents[cur]);
        sorted.add(cur);
    }

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

        ArrayList<Integer> sorted = new ArrayList<Integer>();
        boolean[] visited = new boolean[N];
        for (int i = 0; i < N; i++) {
            go(sorted, visited, parents, i);
        }

        Collections.reverse(sorted);
//        for (int v: sorted) {
//            out.println(v);
//        }

        boolean[] loopRoot = new boolean[N];
        boolean[] root = new boolean[N];
        Arrays.fill(visited, false);
        for (int v: sorted) {
            if (visited[v]) continue;

            int cur = v;
            visited[cur] = true;
            while (!visited[parents[cur]]) {
//                if (v == 0) out.println("-->" + cur);

                cur = parents[cur];
                visited[cur] = true;
            }

            if (parents[cur] == v) {
                loopRoot[cur] = true;
            }
        }



//        boolean[] reached = new boolean[N];
//        boolean[] loopRoot = new boolean[N];
//        boolean[] root = new boolean[N];
//        for (int i = 0; i < N; i++) {
//            if (reached[i]) continue;
//
//            if (parents[i] == i) {
//                reached[i] = true;
//                continue;
//            }
//
//            int cur = i;
//            while (!reached[parents[cur]]) {
//                reached[cur] = true;
//                cur = parents[cur];
//            }
//
//            if (parents[cur] != cur) {
//                loopRoot[cur] = true;
//            }
//        }
        for (int i = 0; i < N; i++) {
            if (i == parents[i]) {
                root[i] = true;
            }
        }


//        for (int i = 0; i < N; i++) {
//            out.println(i + ": " + root[i] + ", " + loopRoot[i]);
//        }

        int ansRoot = -1;
        for (int i = 0; i < N; i++) {
            if (root[i]) ansRoot = i;
        }

        int ans = 0;
        if (ansRoot == -1) {
            for (int i = 0; i < N; i++) {
                if (loopRoot[i]) {
                    loopRoot[i] = false;
                    ansRoot = i;
                    parents[i] = i;
                    ans++;
                    break;
                }
            }
        }

        for (int i = 0; i < N; i++) {
            if (i != ansRoot && (root[i] || loopRoot[i])) {
                parents[i] = ansRoot;
                ans++;
            }
//            out.println(i + ": " + root[i] + ", " + loopRoot[i]);
        }

        out.println(ans);
        for (int i = 0; i < N; i++) {
            out.print((parents[i] +1)+ " ");
        }
        out.println();

	}

    public void go(int[] parents, boolean[] reached, int cur) {
        if (reached[parents[cur]]) {

        }
    }
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new B().run();
	}
	
	public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            out = new PrintWriter(System.out);
            solve();
            reader.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

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

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

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

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}
