#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int n, a[N], de[N], head[N], len, type[N], cnt = 0, pos[N];
bool vis[N];
struct edge {
  int v, fail;
  edge() {}
  edge(int _v, int _fail) {
    v = _v;
    fail = _fail;
  }
} e[N << 1];
void init() {
  memset(head, 0xff, sizeof head);
  len = 0;
}
void add(int u, int v) {
  e[len] = edge(v, head[u]);
  head[u] = len++;
}
void add2(int u, int v) {
  add(u, v);
  add(v, u);
}
void dfs(int u, int pre) {
  vis[u] = 1;
  if (type[cnt] && a[u] == u) pos[cnt] = u;
  for (int i = head[u]; ~i; i = e[i].fail) {
    int v = e[i].v;
    if (v == pre) continue;
    if (vis[v]) {
      type[cnt] = 0;
      pos[cnt] = v;
    } else {
      dfs(v, u);
    }
  }
}
struct note {
  int ty, p;
  bool operator<(const note& A) const { return ty < A.ty; }
} no[N];
int main() {
  scanf("%d", &n);
  memset(de, 0, sizeof de);
  init();
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    if (i == a[i]) continue;
    de[i]++, de[a[i]]++;
    add2(i, a[i]);
  }
  memset(vis, 0, sizeof vis);
  int t = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      type[++cnt] = 1;
      dfs(i, -1);
      if (!type[cnt]) {
        t++;
      }
      no[cnt].ty = type[cnt];
      no[cnt].p = pos[cnt];
    }
  }
  sort(no + 1, no + cnt + 1);
  for (int i = 1; i < cnt; i++) {
    a[no[i].p] = no[i + 1].p;
  }
  int ans = cnt - 1;
  if (t == cnt) a[no[cnt].p] = no[cnt].p, ans++;
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d%c", a[i], i == n ? '\n' : ' ');
  return 0;
}
