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 

#include <bits/stdc++.h>
using namespace std;
const long long dx[4] = {-1, 1, 0, 0};
const long long dy[4] = {0, 0, -1, 1};
vector<long long> r;
vector<vector<long long> > c;
long long a[200005], col[200005];
signed main() {
  long long n;
  cin >> n;
  for (long long i = (0); i < (n); i++) {
    cin >> a[i];
    a[i]--;
    if (i == a[i]) r.push_back(i);
  }
  long long color = 1;
  for (long long i = (0); i < (n); i++)
    if (!col[i]) {
      long long pos = i;
      vector<long long> vv;
      while (1) {
        if (col[pos] && col[pos] != color) break;
        if (col[pos] == color) {
          c.push_back(vector<long long>(1, pos));
          for (long long j = ((long long)vv.size()) - 2; j >= 0; j--)
            if (vv[i] == pos)
              break;
            else
              c[((long long)c.size()) - 1].push_back(vv[i]);
          break;
        }
        if (a[pos] == pos) break;
        col[pos] = color;
        pos = a[pos];
      }
      color++;
    }
  if (!((long long)r.size())) {
    cout << ((long long)c.size()) << '\n';
    a[c[0][0]] = c[0][0];
    for (long long i = (1); i < (((long long)c.size())); i++)
      a[c[i][0]] = c[0][0];
    for (long long i = (0); i < (n); i++) cout << a[i] + 1 << ' ';
  } else {
    cout << ((long long)r.size()) + ((long long)c.size()) - 1 << '\n';
    for (long long i = (1); i < (((long long)r.size())); i++) a[r[i]] = r[0];
    for (long long i = (0); i < (((long long)c.size())); i++) a[c[i][0]] = r[0];
    for (long long i = (0); i < (n); i++) cout << a[i] + 1 << ' ';
  }
  return 0;
}
