#include <bits/stdc++.h>
using namespace std;
template <int um>
class UF {
 public:
  vector<int> par;
  UF() {
    par = vector<int>(um, 0);
    for (int i = 0; i < um; i++) par[i] = i;
  }
  int operator[](int x) {
    return par[x] == x ? x : par[x] = operator[](par[x]);
  }
  void operator()(int x, int y) {
    x = operator[](x);
    y = operator[](y);
    if (x != y) par[x] = y;
  }
};
int n;
int a[201010];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]), a[i]--;
  UF<201010> uf;
  vector<int> roots, loops;
  for (int i = 0; i < n; i++) {
    if (a[i] == i) {
      roots.push_back(i);
      continue;
    }
    if (uf[i] == uf[a[i]])
      loops.push_back(i);
    else
      uf(i, a[i]);
  }
  int ans = 0;
  if (roots.size() == 0) {
    if (loops.size() != 0) {
      int root = loops[0];
      a[root] = root;
      ans++;
      for (int i = 1; i < loops.size(); i++) a[loops[i]] = root, ans++;
    }
  } else {
    int root = roots[0];
    a[root] = root;
    for (int i = 1; i < roots.size(); i++) a[roots[i]] = root, ans++;
    for (int i = 0; i < loops.size(); i++) a[loops[i]] = root, ans++;
  }
  printf("%d\n", ans);
  for (int i = 0; i < n; i++) printf("%d ", a[i] + 1);
  printf("\n");
}
