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 

/*-
 * Codeforces problem :
 * http://codeforces.com/problemset/problem/698/B
 *
 * In the first line print the minimum number of elements to change,
 * in order to get a valid sequence.
 * In the second line, print any valid sequence possible to get
 * from (a1, a2, ..., an) in the minimum number of changes.
 * If there are many such sequences, any of them will be accepted.
 */

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @author Karthik Venkataraman
 * @email kafy83@gmail.com
 */
public class FixATree {

    int n;
    int sn;
    int[] pi;
    int[] mi;
    int[] ri;

    private void compute() {
        InputReader sc = new InputReader(System.in);
        n = sc.nextInt();
        pi = new int[n + 1];
        mi = new int[n + 1];
        ri = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            pi[i] = sc.nextInt();
            if (sn == 0 && i == pi[i]) {
                sn = i;
            }
        }
        for (int i = 1; i <= n; i++) {
            if (mi[i] == 0) {
                dfs(i);
            }
        }
        int result = 0;
        if (sn == 0) {
            result++;
            sn = pi[ri[1]] = ri[1];
        }
        for (int i = 1; i <= n; i++) {
            if (sn != pi[ri[i]]) {
                pi[ri[i]] = sn;
                result++;
            }
        }
        System.out.println(result);
        for (int i = 1; i <= n; i++) {
            System.out.print(pi[i] + " ");
        }
    }

    private int dfs(int i) {
        mi[i] = 1;
        int pmi = mi[pi[i]];
        int sr;
        switch (pmi) {
            case 0:
                sr = dfs(pi[i]);
                break;
            case 1:
                sr = i;
                break;
            case 2:
            default:
                sr = ri[pi[i]];
                break;
        }
        mi[i] = 2;
        return ri[i] = sr;
    }

    class InputReader {

        private static final int INPUT_KB = 1024;
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), INPUT_KB);
        }

        String readNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException ex) {
                    throw new IllegalArgumentException(ex);
                }
            }
            return tokenizer.nextToken();
        }

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

    public static void main(String... args) {
        FixATree fat = new FixATree();
        fat.compute();
    }
}