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 static java.lang.Math.*;

public class Main {
    FastScanner in;
    PrintWriter out;

    static final String FILE = "";

    int n;
    int ans[];
    int start[];
    boolean used[];
    TreeSet<Integer> neig[];
    ArrayList<Integer> roots = new ArrayList<>();
    boolean isHaveRoot;
    int deep;
    ArrayList<Integer> vertices = new ArrayList<>();

    void dfs(int v) {
        if (used[v]) {
            deep = v;
            return;
        }
        used[v] = true;
        vertices.add(v);
        for (Integer it : neig[v]) {
            dfs(it);
        }
    }

    public void solve() {
        n = in.nextInt();
        ans = new int[n];
        start = new int[n];
        used = new boolean[n];

        neig = new TreeSet[n];
        for (int i = 0; i < n; i++)
            neig[i] = new TreeSet<>();

        for (int i = 0; i < n; i++) {
            int tmp = in.nextInt() - 1;
            ans[i] = tmp;
            start[i] = tmp;
            if (tmp == i) {
                roots.add(tmp);
            }

            if (i != tmp) {
                neig[i].add(tmp);
                neig[tmp].add(i);
            }
        }

        int curr = -1, last = -1;

        ArrayList<Integer> noRoots = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            if (used[i])
                continue;

            vertices.clear();
            dfs(i);

            isHaveRoot = false;
            for (Integer it : vertices) {
                if (ans[it] == it) {
                    isHaveRoot = true;
                    curr = it;
                }
            }

            if (!isHaveRoot) {
                noRoots.add(deep);
            } else {
                if (last == -1)
                    last = curr;
                ans[curr] = last;
            }
        }

        if (noRoots.size() > 0) {
            if (last == -1)
                last = noRoots.get(0);

            for (Integer it : noRoots)
                ans[it] = last;
        }

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

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

    public void run() {
        if (FILE.equals("")) {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);
        } else {
            try {
                in = new FastScanner(new FileInputStream(FILE +
                        ".in"));
                out = new PrintWriter(new FileOutputStream(FILE +
                        ".out"));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        solve();
        out.close();
    }

    public static void main(String[] args) {
        (new Main()).run();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return "";
            }
        }

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

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

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

        public float nextFloat() {
            return Float.parseFloat(next());
        }
    }

    class Pair<A extends Comparable<A>, B extends Comparable<B>>
            implements Comparable<Pair<A, B>> {
        public A a;
        public B b;

        public Pair(A a, B b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair<A, B> o) {
            if (o == null || o.getClass() != getClass())
                return 1;
            int cmp = a.compareTo(o.a);
            if (cmp == 0)
                return b.compareTo(o.b);
            return cmp;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Pair<?, ?> pair = (Pair<?, ?>) o;

            if (a != null ? !a.equals(pair.a) : pair.a != null) return
                    false;
            return !(b != null ? !b.equals(pair.b) : pair.b != null);
        }
    }

    class PairInt extends Pair<Integer, Integer> {
        public PairInt(Integer u, Integer v) {
            super(u, v);
        }
    }

    class PairLong extends Pair<Long, Long> {
        public PairLong(Long u, Long v) {
            super(u, v);
        }
    }

}