#include <bits/stdc++.h>
using namespace std;
int fa[200005], a[200005];
bool ch[200005];
int root, fx, fy, i, x, n, num;
int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) fa[i] = i;
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    a[i] = x;
    fx = get(x);
    if (fx == i) {
      if (x == i && !root)
        root = i, a[i] = i;
      else
        ch[i] = 1;
    } else
      fa[i] = fx;
  }
  if (!root)
    for (i = 1; i <= n; i++)
      if (ch[i]) root = i, a[i] = i;
  for (i = 1; i <= n; i++)
    if (ch[i]) a[i] = root, num++;
  printf("%d\n", num);
  for (i = 1; i <= n; i++) printf("%d ", a[i]);
  return 0;
}
