#include <bits/stdc++.h>
using namespace std;
using namespace placeholders;
template <typename T>
inline void _max(T& a, T b) {
  a = max(a, b);
}
template <typename T>
inline void _min(T& a, T b) {
  a = min(a, b);
}
const int N = 3e5;
int n;
int ans, a[N], p[N], seen[N];
int r[N], rs, rt;
int main() {
  scanf(" %d", &n);
  for (int i = 1; i <= n; i++) {
    scanf(" %d", p + i);
    a[i] = p[i];
  }
  for (int i = 1; i <= n; i++)
    if (!seen[i]) {
      int j = i;
      seen[i] = i;
      while (!seen[p[j]]) seen[j = p[j]] = i;
      if (p[j] == j && !rt) rt = j;
      if (seen[p[j]] == i) r[rs++] = j;
    }
  if (!rt) rt = r[0];
  for (int i = 0; i < rs; i++) p[r[i]] = rt;
  for (int i = 1; i <= n; i++) ans += (p[i] != a[i]);
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d%c", p[i], " \n"[i == n]);
}
