#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2e5 + 5;
int n, m, ans = 0, root = -1, a[Maxn], f[Maxn];
inline int R() {
  char c;
  int res, sign = 1;
  while ((c = getchar()) > '9' || c < '0')
    if (c == '-') sign = -1;
  res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  return res * sign;
}
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void merge(int x, int y) { f[find(y)] = find(x); }
int main() {
  n = R();
  for (int i = 1; i <= n; ++i) {
    a[i] = R();
    f[i] = i;
    if (a[i] == i) root = i;
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] == root && a[i] == i) continue;
    if (a[i] == i && a[i] != root) {
      a[i] = root, ++ans;
      merge(a[i], root);
    } else if (a[i] != i && find(a[i]) != find(i))
      merge(a[i], i);
    else if (a[i] != i && find(a[i]) == find(i)) {
      if (!(root + 1)) root = i;
      a[i] = root, ++ans;
      merge(root, i);
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; ++i) printf("%d ", a[i]);
}
