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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class D {

	static int cnt;
	static int[] p;
	static int[] v;
	static int root;
	
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        p = new int[n];
        v = new int[n];
        for(int i=0;i<n;i++){
        	p[i] = in.nextInt()-1;
        	v[i] = 0;
        }
        int dep = 0;
        root = -1;
        for(int i=0;i<n;i++){
        	if(p[i] == i){
        		root = i;
        	}
        }
        for(int i=0;i<n;i++){
        	if(v[i]==0){
        		dep++;
        		dfs(i, dep);
        	}
        }
        out.println(cnt);
        for(int i=0;i<n;i++){
        	out.print((p[i]+1) + " ");
        }
        out.flush();
	}
	
	static void dfs(int u, int dep){
		v[u] = dep;
		if(v[p[u]]==0){
			dfs(p[u], dep);
		} else if(v[p[u]] == dep){
			//circle found
			update(u);
		}
	}
	
	static void update(int u){
		if(root == u) return;
		if(root==-1){
			root = u;
			p[u] = u;
			cnt++;
		} else {
			p[u] = root;
			cnt++;
		}
	}
	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        
        public long nextLong(){
        	return Long.parseLong(next());
        }

    }
}
