#include <bits/stdc++.h>
using namespace std;
int n, a[200005], ans[200005], ck[200005], bro;
int Ck[200005];
int Go(int pos) {
  if (Ck[pos]) return pos;
  Ck[pos] = 1;
  return Go(a[pos]);
}
int go(int yo, int pos, int sigh) {
  if (a[pos] == yo) {
    ck[pos] = sigh;
    return bro;
  }
  if (ck[pos] && ck[pos] != sigh) return pos;
  if (ck[pos] == sigh) return bro;
  ck[pos] = sigh;
  ans[pos] = go(pos, a[pos], sigh);
  return pos;
}
int main() {
  int res = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    ans[i] = a[i];
    if (i == a[i] && bro == 0) bro = i;
  }
  if (bro == 0) {
    bro = Go(1);
    a[bro] = bro;
    ans[bro] = bro;
    res++;
  }
  for (int i = 1; i <= n; i++) {
    if (ck[i] == 0) {
      ck[i] = i;
      ans[i] = go(i, a[i], i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] != ans[i]) res++;
  }
  cout << res << endl;
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
