#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, gv = 0, ans = 0, q;
  cin >> n;
  vector<int> a(n + 1);
  vector<int> flag(n + 1);
  int t = 1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (gv == 0 && a[i] == i) gv = i;
  }
  if (gv) ans = -1;
  for (int i = 1; i <= n; ++i)
    if (flag[i] == 0) {
      ++t;
      flag[i] = t;
      q = i;
      while (flag[a[q]] == 0) {
        flag[a[q]] = t;
        q = a[q];
      }
      if (flag[a[q]] != t) continue;
      if (gv == 0) gv = q;
      a[q] = gv;
      ++ans;
    }
  cout << ans << endl;
  for (int i = 1; i <= n; ++i) printf("%d ", a[i]);
}
