#include <bits/stdc++.h>
using namespace std;
int v[200010];
int ar[200010];
int main() {
  int n;
  scanf("%d", &n);
  int j = -1;
  int res = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v[i]);
    if (i == v[i]) {
      if (j == -1)
        j = i;
      else {
        v[i] = j;
        res++;
      }
    }
  }
  int c = 1;
  for (int i = 1; i <= n; i++) {
    if (ar[i] == 0) {
      int k = i;
      while (true) {
        if (k == v[k] || (ar[k] > 0 && ar[k] < c)) break;
        if (ar[k] == c) {
          if (j == -1) {
            v[k] = k;
            j = k;
          } else
            v[k] = j;
          res++;
          break;
        }
        ar[k] = c;
        k = v[k];
      }
      c++;
    }
  }
  printf("%d\n", res);
  printf("%d", v[1]);
  for (int i = 2; i <= n; i++) printf(" %d", v[i]);
  printf("\n");
  return 0;
}
