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.StringTokenizer;

public class Main {
    private FastScanner in;
    private PrintWriter out;

    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = in.nextInts(n);
        Integer root = null;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            a[i]--;
            if (a[i] == i) {
                if (root == null) {
                    root = i;
                } else {
                    ans++;
                    a[i] = root;
                }
            }
        }
        int[] was = new int[n];
        int time = 1;
        if (root == null) {
            loop:
            for (int i = 0; i < n; i++) {
                if (was[i] == 0) {
                    int cur = i;
                    while (true) {
                        was[cur] = time;
                        if (was[a[cur]] != 0) {
                            if (was[a[cur]] == time) {
                                ans++;
                                a[cur] = cur;
                                root = cur;
                            }
                            time++;
                            break loop;
                        } else {
                            cur = a[cur];
                        }
                    }
                }
            }
        }
        if (root == null) throw new RuntimeException();
        was[root] = time++;
        // just remove cycles
        for (int i = 0; i < n; i++) {
            if (i != root && was[i] == 0) {
                int cur = i;
                while (true) {
                    was[cur] = time;
                    if (was[a[cur]] != 0) {
                        if (was[a[cur]] == time) {
                            ans++;
                            a[cur] = root;
                        }
                        break;
                    } else {
                        cur = a[cur];
                    }
                }
                time++;
            }
        }
        out.println(ans);
        for (int e : a) {
            out.print(e + 1 + " ");
        }
    }

    private void run() throws IOException {
        in = new FastScanner();
        out = new PrintWriter(System.out, false);
        solve();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Thread(null, () -> {
            try {
                new Main().run();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }, "", 1 << 27).run();
    }
}

class FastScanner {
    private final BufferedReader br;
    private StringTokenizer st;
    private String last;

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public FastScanner(String path) throws IOException {
        br = new BufferedReader(new FileReader(path));
    }

    public FastScanner(String path, String decoder) throws IOException {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(path), decoder));
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        last = null;
        return st.nextToken();
    }

    String nextLine() throws IOException {
        st = null;
        return (last == null) ? br.readLine() : last;
    }

    boolean hasNext() {
        if (st != null && st.hasMoreElements())
            return true;

        try {
            while (st == null || !st.hasMoreElements()) {
                last = br.readLine();
                st = new StringTokenizer(last);
            }
        } catch (Exception e) {
            return false;
        }

        return true;
    }

    String[] nextStrings(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = next();
        return arr;
    }

    String[] nextLines(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLine();
        return arr;
    }

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

    int[] nextInts(int n) throws IOException {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    Integer[] nextIntegers(int n) throws IOException {
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    int[][] next2Ints(int n, int m) throws IOException {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextInt();
        return arr;
    }

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

    long[] nextLongs(int n) throws IOException {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLong();
        return arr;
    }

    long[][] next2Longs(int n, int m) throws IOException {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextLong();
        return arr;
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next().replace(',', '.'));
    }

    double[] nextDoubles(int size) throws IOException {
        double[] arr = new double[size];
        for (int i = 0; i < size; i++)
            arr[i] = nextDouble();
        return arr;
    }

    boolean nextBool() throws IOException {
        String s = next();
        if (s.equalsIgnoreCase("true") || s.equals("1"))
            return true;

        if (s.equalsIgnoreCase("false") || s.equals("0"))
            return false;

        throw new IOException("Boolean expected, String found!");
    }
}