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 Template implements Runnable {

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

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    class GraphBuilder {
        int n, m;
        int[] x, y;
        int index;
        int[] size;


        GraphBuilder(int n, int m) {
            this.n = n;
            this.m = m;
            x = new int[m];
            y = new int[m];
            size = new int[n];
        }

        void add(int u, int v) {
            x[index] = u;
            y[index] = v;
            size[u]++;
            size[v]++;
            index++;
        }

        int[][] build() {
            int[][] graph = new int[n][];
            for (int i = 0; i < n; i++) {
                graph[i] = new int[size[i]];
            }
            for (int i = index - 1; i >= 0; i--) {
                int u = x[i];
                int v = y[i];
                graph[u][--size[u]] = v;
                graph[v][--size[v]] = u;
            }
            return graph;
        }
    }

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

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

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

    long[] readLongArray(int size) throws IOException {
        long[] res = new long[size];
        for (int i = 0; i < size; i++) {
            res[i] = readLong();
        }
        return res;
    }

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

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

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Template().run();
        // new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

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

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    int dfs(int x, int p, int[][] g, boolean[] used) {
        used[x] = true;
        int cycleVertex = -1;
        for (int y : g[x]) {
            if (p == y) continue;
            if (!used[y]) {
                int r = dfs(y, x, g, used);
                if (r != -1) cycleVertex = r;
            } else {
                cycleVertex = y;
            }
        }
        return cycleVertex;
    }

    void solve() throws IOException {
        int n = readInt();
        int[] a = readIntArray(n);
        GraphBuilder gb = new GraphBuilder(n, n);
        GraphBuilder rgb = new GraphBuilder(n, n);
        for (int i = 0; i < n; i++) {
            gb.add(a[i] - 1, i);
            rgb.add(i, a[i] - 1);
        }
        boolean[] used = new boolean[n];
        int[][] g = gb.build();
        int[][] rg = rgb.build();
        List<Integer> roots = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (i == a[i] - 1) {
                dfs(i, i, g, used);
                roots.add(i);
            }
        }
        List<Integer> cycleRoots = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (!used[i]) {
                cycleRoots.add(dfs(i, i, rg, used));
            }
        }
        int rootsCount = roots.size();
        int cycleCount = cycleRoots.size();
        int answer = 0;
        if (rootsCount == 0) {
            rootsCount++;
            answer++;
            cycleCount--;
            a[cycleRoots.get(0)] = cycleRoots.get(0) + 1;
            roots.add(cycleRoots.remove(0));
        }
        answer += rootsCount - 1;
        answer += cycleCount;
        out.println(answer);

        for (int i = 1; i < roots.size(); i++) {
            a[roots.get(i)] = roots.get(0) + 1;
        }
        for (int x : cycleRoots) {
            a[x] = roots.get(0) + 1;
        }
        for (int x : a) {
            out.print(x + " ");
        }

    }


}