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.lang.*;
import java.util.*;
import java.math.*;

// Sachin_2961 submission //
public class CodeforcesA {
    int N = 200000;
    int[]parent = new int[N];
    ArrayList<Integer>root=new ArrayList<>();
    int count;
    public int Parent(int x){
        if(parent[x]!=x)
            return Parent(parent[x]);
        return parent[x];
    }
    public void add(int i,int p,int[]ar){
        if(i == p){
            root.add(p);
            ar[i] = p;
            return;
        }
        int temp = p;
        p = Parent(p);
        if( i == p ){
            ar[i] = p;
            count++;
        }else{
            ar[i] = temp;
            parent[i] = temp;
        }
    }
    public void solve() {
        int n = fs.nInt();
        for(int i=1;i<=n;i++){
            parent[i] = i;
        }
        count = 0;
        int[]ar = new int[N];
        for(int i=1;i<=n;i++){
            int p = fs.nInt();
            add(i,p,ar);
        }
        int sz = root.size();
        if(sz > 1 ) {
            int allRoot = root.get(sz - 1);
            for (int i = 0; i < sz - 1; i++) {
                count++;
                ar[root.get(i)] = allRoot;
            }
        }
        out.println(count);
        for(int i=1;i<=n;i++)
            out.print(ar[i]+" ");

    }
    static boolean multipleTestCase = false; static FastScanner fs; static PrintWriter out;
    public void run(){
        fs = new FastScanner();
        out = new PrintWriter(System.out);
        int tc = (multipleTestCase)?fs.nInt():1;
        while (tc-->0)solve();
        out.flush();
        out.close();
    }
    public static void main(String[]args){
        try{
            new CodeforcesA().run();
        }catch (Exception e){
            e.printStackTrace();
        }

    }
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String n() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        String Line()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
        int nInt() {return Integer.parseInt(n()); }
        long nLong() {return Long.parseLong(n());}
        int[]aI(int n){
            int[]ar = new int[n];
            for(int i=0;i<n;i++)
                ar[i] = nInt();
            return ar;
        }
    }
}