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.*;
import java.math.BigInteger;
import java.util.Map.Entry;

import static java.lang.Math.*;

public class B extends PrintWriter {

    boolean dfs(int u, int f, int[] p, int[] color) {
        if (color[u] == 2) {
            return false;
        }
        if (color[u] == 1) {
            return true;
        }

        color[u] = 1;

        int v = p[u];
        if (v != f) {
            if (dfs(v, f, p, color)) {
                p[u] = f;
            }
        }

        color[u] = 2;
        return false;
    }

    void run() {
        int n = nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = nextInt() - 1;
        }

        int f = -1;
        int[] t = new int[n];

        for (int i = 0; i < n; i++) {
            t[i] = p[i];
            if (p[i] == i) {
                if (f == -1) {
                    f = i;
                } else {
                    t[i] = f;
                }
            }
        }

        if (f == -1) {
            boolean[] use = new boolean[n];
            int u = 0;

            while (true) {
                use[u] = true;
                int v = t[u];
                if (use[v]) {
                    f = t[u] = u;
                    break;
                }
                u = v;
            }
        }

        int[] color = new int[n];

        for (int i = 0; i < n; i++) {
            dfs(i, f, t, color);
        }

        int cnt = 0;

        for (int i = 0; i < n; i++) {
            if (t[i] != p[i]) {
                ++cnt;
            }
        }

        println(cnt);

        for (int i = 0; i < n; i++) {
            print(t[i] + 1);
            print(' ');
        }
        println();
    }

    int[][] nextMatrix(int n, int m) {
        int[][] matrix = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                matrix[i][j] = nextInt();
        return matrix;
    }

    String next() {
        while (!tokenizer.hasMoreTokens())
            tokenizer = new StringTokenizer(nextLine());
        return tokenizer.nextToken();
    }

    boolean hasNext() {
        while (!tokenizer.hasMoreTokens()) {
            String line = nextLine();
            if (line == null) {
                return false;
            }
            tokenizer = new StringTokenizer(line);
        }
        return true;
    }

    int[] nextArray(int n) {
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = nextInt();
        }
        return array;
    }

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

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

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

    String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException err) {
            return null;
        }
    }

    public B(OutputStream outputStream) {
        super(outputStream);
    }

    static BufferedReader reader;
    static StringTokenizer tokenizer = new StringTokenizer("");
    static Random rnd = new Random();
    static boolean OJ;

    public static void main(String[] args) throws IOException {
        OJ = System.getProperty("ONLINE_JUDGE") != null;
        B solution = new B(System.out);
        if (OJ) {
            reader = new BufferedReader(new InputStreamReader(System.in));
            solution.run();
        } else {
            reader = new BufferedReader(new FileReader(new File(B.class.getName() + ".txt")));
            long timeout = System.currentTimeMillis();
            while (solution.hasNext()) {
                solution.run();
                solution.println();
                solution.println("----------------------------------");
            }
            solution.println("time: " + (System.currentTimeMillis() - timeout));
        }
        solution.close();
        reader.close();
    }
}
