#include <bits/stdc++.h>
const double inf = 1e20;
using namespace std;
int n, fa[200200], a[200200], lp[200200];
vector<int> v, v1, v2;
int sfind(int x) {
  if (x == fa[x])
    return x;
  else
    return fa[x] = sfind(fa[x]);
}
int main() {
  int ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    int x = sfind(i), w = sfind(a[i]);
    if (x != w)
      fa[x] = w;
    else if (i != a[i])
      v.push_back(i);
  }
  for (int i = 0; i < v.size(); i++) lp[sfind(v[i])] = 1;
  for (int i = 1; i <= n; i++) {
    if (fa[i] == i) {
      if (lp[i])
        v1.push_back(i);
      else
        v2.push_back(i);
    }
  }
  for (int i = 0; i < (int)v1.size() - 1; i++) a[v1[i]] = v1[i + 1], ans++;
  for (int i = 0; i < (int)v2.size() - 1; i++) {
    if (!i && v1.size()) a[v1[v1.size() - 1]] = v2[0], ans++;
    a[v2[i]] = v2[i + 1];
    ans++;
  }
  if (v2.size() == 1 && v1.size()) a[v1[v1.size() - 1]] = v2[0], ans++;
  if (v2.size() == 0) ans++, a[v1[(int)v1.size() - 1]] = v1[(int)v1.size() - 1];
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", a[i]);
  return 0;
}
