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.*;

public class B implements Runnable {

    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer tok = new StringTokenizer("");

    private void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        String fileName = "";
        if (ONLINE_JUDGE && fileName.isEmpty()) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            try {
                if (fileName.isEmpty()) {
                    in = new BufferedReader(new FileReader("input.txt"));
                    out = new PrintWriter("output.txt");
                } else {
                    in = new BufferedReader(new FileReader(fileName + ".in"));
                    out = new PrintWriter(fileName + ".out");
                }
            } catch (Throwable t) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            }
        }
    }

    String readString() {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() {
        return Integer.parseInt(readString());
    }

    long readLong() {
        return Long.parseLong(readString());
    }

    double readDouble() {
        return Double.parseDouble(readString());
    }

    int[] readIntArray(int size) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public static void main(String[] args) {
        new Thread(null, new B(), "", 256 * (1L << 20)).start();
        //new B().run();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    @Override
    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            init();
            solve();
            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    class DSU {
        int[] p;
        Random random = new Random();

        DSU(int size) {
            p = new int[size];
            for (int i = 0; i < size; i++) {
                p[i] = i;
            }
        }

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

        void unite(int a, int b) {
            if (random.nextBoolean()) {
                p[a] = b;
            } else {
                p[b] = a;
            }
        }
    }

    private void solve() {
        int n = readInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = readInt() - 1;
        }
        int root = -1;
        int changes = 0;
        for (int i = 0; i < n; i++) {
            if (i == a[i]) {
                if (root == -1) {
                    root = i;
                } else {
                    changes++;
                    a[i] = root;
                }
            }
        }

        DSU dsu = new DSU(n);
        for (int i = 0; i < n; i++) {
            if (i == root) continue;
            int ca = dsu.find(i);
            int cb = dsu.find(a[i]);
            if (ca == cb) {
                if (root == -1) {
                    root = i;
                }
                changes++;
                a[i] = root;
            } else {
                dsu.unite(ca, cb);
            }
        }

        out.println(changes);
        for (int x : a) {
            out.print(x + 1 + " ");
        }
    }
}
