#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int T[maxn], a[maxn];
int findn(int x) { return x == T[x] ? x : T[x] = findn(T[x]); }
int main() {
  int n, num = 0, flag = 0, x;
  cin >> n;
  for (int i = 1; i <= n; i++) T[i] = i;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x == i) {
      if (flag) {
        a[x] = flag;
        num++;
      } else {
        flag = i;
        a[i] = flag;
      }
    } else {
      int xx = findn(i);
      int yy = findn(x);
      if (xx != yy) {
        a[i] = x;
        T[xx] = yy;
      } else {
        num++;
      }
    }
  }
  cout << num << endl;
  for (int i = 1; i <= n; i++) {
    if (a[i])
      cout << a[i] << " ";
    else {
      if (flag) {
        cout << flag << " ";
      } else {
        flag = i;
        cout << flag << " ";
      }
    }
  }
  return 0;
}
