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.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] p = new int[n];
            for (int i = 0; i < n; i++) {
                p[i] = in.nextInt() - 1;
            }
            int[] col = new int[n];
            Arrays.fill(col, -1);
            int numCols = 0;
            List<Integer> cycleRepr = new ArrayList<>();
            List<Integer> cycleLens = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                if (col[i] >= 0) {
                    continue;
                }
                int j;
                for (j = i; col[j] < 0; j = p[j]) {
                    col[j] = numCols;
                }
                if (col[j] == numCols) {
                    // found a new cycle
                    int len = 1;
                    for (int k = p[j]; k != j; k = p[k]) {
                        ++len;
                    }
                    cycleRepr.add(j);
                    cycleLens.add(len);
                }
                ++numCols;
            }
            int root = cycleRepr.get(0);
            boolean goodRoot = false;
            for (int i = 0; i < cycleRepr.size(); i++) {
                if (cycleLens.get(i) == 1) {
                    goodRoot = true;
                    root = cycleRepr.get(i);
                }
            }
            int ans = cycleRepr.size();
            if (goodRoot) {
                --ans;
            }
            out.println(ans);
            for (int x : cycleRepr) {
                p[x] = root;
            }
            for (int i = 0; i < n; i++) {
                if (i > 0) {
                    out.print(" ");
                }
                out.print(p[i] + 1);
            }
            out.println();
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}

