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 {

    public static void main(String[] args) throws IOException, InterruptedException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int[] a = sc.nextIntArray(n);
        int root = -1;
        for (int i = 0; i < n; i++)
            if (--a[i] == i) root = i;
        int ans = 0;
        DSU dsu = new DSU(n);
        for (int i = 0; i < n; i++) {
            if (i == root) continue;
            boolean cycle = dsu.union(i, a[i]);
            if (cycle) {
                ans++;
                if (root == -1)
                    root = i;
                a[i] = root;
                dsu.union(root, i);
            }
        }
        out.println(ans);
        for (int x : a)
            out.print(x + 1 + " ");
        out.close();
        out.flush();

    }

    static class DSU {
        int n;
        int[] size, p;

        public DSU(int n) {
            this.n = n;
            size = new int[n];
            p = new int[n];
            for (int i = 0; i < n; i++) {
                size[i] = 1;
                p[i] = i;
            }
        }

        int findParent(int x) {
            if (p[x] == x) return x;
            return p[x] = findParent(p[x]);
        }

        boolean union(int x, int y) {
            x = findParent(x);
            y = findParent(y);
            if (x == y) return true;
            if (size[x] > size[y]) {
                size[x] += size[y];
                p[y] = x;
            } else {
                size[y] += size[x];
                p[x] = y;
            }
            return false;
        }
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }


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

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

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

        public boolean ready() throws IOException {
            return br.ready();
        }


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

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


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

        public double[] nextDoubleArray(int n) throws IOException {
            double[] ans = new double[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextDouble();
            return ans;
        }

        public short nextShort() throws IOException {
            return Short.parseShort(next());
        }

    }

}