#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
int a[N], fa[N];
bool mark[N];
int findf(int x) {
  if (fa[x] != x) fa[x] = findf(fa[x]);
  return fa[x];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (i != a[i]) {
      if (findf(i) != findf(a[i])) {
        fa[fa[i]] = fa[a[i]];
        mark[i] = 1;
      }
    }
  }
  int ans = 0;
  int now = -1;
  for (int i = 1; i <= n; ++i) {
    if (!mark[i] && a[i] == i) {
      now = i;
    }
  }
  if (now != -1) mark[now] = 1;
  for (int i = 1; i <= n; ++i) {
    if (!mark[i]) {
      if (now == -1) now = i;
      a[i] = now;
      ++ans;
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; ++i) printf("%d%c", a[i], (i == n ? '\n' : ' '));
  return 0;
}
