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.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        int[] id;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int P[] = new int[N];
            id = new int[N];
            int root = -1;
            int ans = 0;

            for (int i = 0; i < N; i++) {
                P[i] = in.nextInt() - 1;
                if (P[i] == i) {
                    root = i;
                    ans = -1;
                }
            }

            for (int i = 0; i < N; i++) id[i] = i;

            for (int i = 0; i < N; i++) {
                if (!union(P[i], i)) {
                    if (root == -1) {
                        root = i;
                    }
                    ans++;
                    P[i] = root;
                }
            }

            out.println(ans);
            for (int i = 0; i < N; i++) out.print(P[i] + 1 + " ");
            out.println();
        }

        private boolean union(int p, int q) {
            p = find(p);
            q = find(q);

            if (p == q) return false;

            id[p] = q;
            return true;
        }

        private int find(int p) {
            return id[p] == p ? p : (id[p] = find(id[p]));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}

