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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Wolfgang Beyer
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] p = in.readIntArray(n);

            boolean[] visited = new boolean[n];
            boolean[] visitedCurrently = new boolean[n];
            for (int i = 0; i < n; i++) {
                visited[i] = false;
                visitedCurrently[i] = false;
                p[i]--;
            }

            int result = 0;
            int root = -1;
            int i = 0;
            while ((i < n) && (p[i] != i)) i++;
            if (i < n) root = i;
            else {
                int current = 0;
                visitedCurrently[current] = true;
                while (!visitedCurrently[p[current]]) {
                    current = p[current];
                    visitedCurrently[current] = true;
                }
                root = current;
                result++;
                p[root] = root;
            }
            //System.out.println("root: " + root);

            for (i = 0; i < n; i++) visitedCurrently[i] = false;

            for (i = 0; i < n; i++) {
                if (!visited[i]) {
                    visited[i] = true;
                    visitedCurrently[i] = true;
                    int current = i;
                    while (!visited[p[current]]) {
                        current = p[current];
                        visited[current] = true;
                        visitedCurrently[current] = true;
                    }
                    if ((p[current] != root) && (visitedCurrently[p[current]])) {
                        result++;
                        p[current] = root;
                    }
                    //for (int j = 0; j < n; j++) visitedCurrently[j] = false;
                    current = i;
                    while (visitedCurrently[current]) {
                        visitedCurrently[current] = false;
                        current = p[current];
                    }
                }
            }

            out.println(result);
            for (i = 0; i < n; i++) out.print((p[i] + 1) + " ");
        }

    }

    static class InputReader {
        private static BufferedReader in;
        private static StringTokenizer tok;

        public InputReader(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
        }

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

        public int[] readIntArray(int n) {
            int[] ar = new int[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }

        public String next() {
            try {
                while (tok == null || !tok.hasMoreTokens()) {
                    tok = new StringTokenizer(in.readLine());
                }
            } catch (IOException ex) {
                System.err.println("An IOException was caught :" + ex.getMessage());
            }
            return tok.nextToken();
        }

    }
}

