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 Main {
    private static int root(int[] parentIds, int c) {
        while(c != parentIds[c]) {
            parentIds[c] = parentIds[parentIds[c]];
            c = parentIds[c];
        }
        return c;
    }
    private static boolean union(int[] parentIds, int[] groupSizes, int a, int b) {
        int rootA = root(parentIds, a);
        int rootB = root(parentIds, b);
        if(rootA == rootB) {
            return false;
        }
        if(groupSizes[rootA] < groupSizes[rootB]) {
            parentIds[rootA] = rootB;
            groupSizes[rootB] += groupSizes[rootA];
        } else {
            parentIds[rootB] = rootA;
            groupSizes[rootA] += groupSizes[rootB];
        }
        return true;
    }
    public static void main(String[] args) throws IOException{
        //BufferedReader f = new BufferedReader(new FileReader("uva.in"));
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = Integer.parseInt(f.readLine());
        int[] a = new int[n];
        int[] parentIds = new int[n];
        int[] groupSizes = new int[n];
        StringTokenizer st = new StringTokenizer(f.readLine());
        int r = -1;
        for(int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(st.nextToken())-1;
            parentIds[i] = i;
            groupSizes[i] = i;
            if(i == a[i]) {
                r = i;
            }
        }
        int count = 0;
        for(int i = 0; i < n; i++) {
            if(i != a[i] && !union(parentIds, groupSizes, i, a[i])) {
                a[i] = r == -1 ? i : r;
                count++;
            }
            if(i == a[i] && r == -1) {
                r = a[i];
            }
        }
        for(int i = 0; i < n; i++) {
            if(i == a[i] && i != r) {
                a[i] = r;
                count++;
            }
        }
        out.println(count);
        out.print(a[0]+1);
        for(int i = 1; i < n; i++) {
            out.print(" " + (a[i]+1));
        }
        out.println();
        f.close();
        out.close();
    }
}
