#include <bits/stdc++.h>
using namespace std;
const int mx = (int)2e5 + 100;
int n, m, que[mx], rt, vis[mx], top, is[mx], in[mx], fa[mx];
void topoo() {
  for (int i = 1; i <= n; ++i)
    if (!in[i]) que[++top] = i;
  while (top) {
    int x = que[top--];
    vis[x] = 1;
    in[fa[x]]--;
    if (!in[fa[x]]) que[++top] = fa[x];
  }
}
void dfs(int x) {
  if (vis[x]) return;
  vis[x] = 1;
  dfs(fa[x]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &fa[i]);
    in[fa[i]]++;
    if (fa[i] == i) is[i] = 1;
  }
  topoo();
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (is[i]) {
      rt = i;
      vis[i] = 1;
      break;
    }
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      ans++;
      if (!rt)
        rt = i, dfs(i), fa[i] = i;
      else
        dfs(i), fa[i] = rt;
    }
  cout << ans << endl;
  for (int i = 1; i <= n; ++i) cout << fa[i] << ' ';
  return 0;
}
