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.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class disjoint2 {
    static PrintWriter out;
    static BufferedReader in;
    static StringTokenizer st;

    public static void main(String[] args) throws FileNotFoundException {
        //out = new PrintWriter("test.out");
        //in = new BufferedReader(new FileReader("test.in"));
        out = new PrintWriter(System.out);
        in = new BufferedReader(new InputStreamReader(System.in));
        new disjoint2().Run();
        out.close();
    }

    String ns() {
        try {
            if (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(in.readLine());
            }
            return st.nextToken();
        } catch (Exception e) {
            return null;
        }
    }

    int nextint() {
        return Integer.valueOf(ns());
    }


    int nodesCount = nextint();
    int[] to = new int[nodesCount];
    int[] parentNodes = new int[nodesCount];

    private int findSet(int x) {
        if (parentNodes[x] == x) {
            return x;
        } else {
            return parentNodes[x] = findSet(parentNodes[x]);
        }
    }

    private boolean isSameSet(int x, int y)
    {
        return findSet(x) == findSet(y);
    }

    private boolean union(int x, int y) {
        x = findSet(x);
        y = findSet(y);

        if (x == y) {
            return false;
        }
        parentNodes[x] = y;
        return true;

    }

    ArrayList<Integer> circle = new ArrayList<>();
    ArrayList<Integer> parent = new ArrayList<>();
    public void Run() {

        for (int i = 0; i < nodesCount; i++) {
            to[i] = nextint() - 1;
            parentNodes[i] = i;
        }

        for (int i = 0; i < nodesCount; i++) {
            if (isSameSet(to[i],i))
                circle.add(i);
        }

        for (int i = 0; i < nodesCount; i++) {
            if (!union(to[i], i)) {
                parent.add(i);
            }
        }
        int [] to2 = to.clone();
        int last;
        if (circle.size() == 0) last = parent.get(0);
        else last = circle.get(0);
        for(int i: circle)
        {
            if (to[i] != last)
                to[i] = last;
        }

        for (int i: parent)
        {
            if (to[i] !=last)
                to[i] = last;
        }
        int count = 0;
        for (int i = 0; i < to.length; i++) {

            if (to[i] != to2[i]) {
                count++;
            }
             if (i ==  to.length - 1) out.println(count);
        }

        for (int i = 0; i < nodesCount; i++) {
            out.print(to[i] + 1 + " ");
        }
    }
}