#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
struct NodeDSU {
  int parent;
  int rank;
  NodeDSU() : parent(), rank() {}
} dsu[N];
int n, a[N], sol;
int root, k;
vector<int> v[N], contain[N];
bool mark[N], seen[N];
int hes[N], inv[N];
bool valid[N];
set<int> skup;
int problem, pos;
void init() {
  for (int i = 1; i <= n; i++) {
    dsu[i].parent = i;
    dsu[i].rank = 0;
  }
}
int findSet(int x) {
  if (dsu[x].parent == x) return x;
  dsu[x].parent = findSet(dsu[x].parent);
  return dsu[x].parent;
}
void uniteSet(int x, int y) {
  x = findSet(x);
  y = findSet(y);
  if (dsu[x].rank < dsu[y].rank)
    dsu[x].parent = y;
  else
    dsu[y].parent = x;
  if (dsu[x].rank == dsu[y].rank) dsu[x].rank++;
}
int main() {
  scanf("%d", &n);
  init();
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == i) {
      if (!root)
        root = a[i];
      else
        mark[i] = true;
    } else {
      if (findSet(i) == findSet(a[i]))
        mark[i] = true;
      else
        uniteSet(i, a[i]);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!seen[findSet(i)]) {
      seen[findSet(i)] = true;
      k++;
      skup.insert(k);
      hes[findSet(i)] = k;
      inv[k] = findSet(i);
    }
  }
  for (int i = 1; i <= n; i++) contain[hes[findSet(i)]].push_back(i);
  for (int i = 1; i <= n; i++) {
    if (!mark[i]) continue;
    v[hes[findSet(i)]].push_back(i);
  }
  for (int i = 1; i <= k; i++) {
    if (!v[i].size()) continue;
    skup.erase(i);
    if (!root) {
      sol++;
      root = v[i][0];
      a[v[i][0]] = v[i][0];
      for (int j = 1; j < v[i].size(); j++) {
        sol++;
        if (!skup.size()) {
          problem = i;
          pos = j;
          break;
        }
        int xt = *skup.begin();
        a[v[i][j]] = contain[xt][0];
        skup.erase(xt);
      }
    } else {
      for (int j = 0; j < v[i].size(); j++) {
        sol++;
        if (!skup.size()) {
          problem = i;
          pos = j;
          break;
        }
        int xt = *skup.begin();
        a[v[i][j]] = contain[xt][0];
        skup.erase(xt);
      }
    }
  }
  if (problem) {
    a[v[problem][pos]] = contain[1][0];
  }
  printf("%d\n", sol);
  for (int i = 1; i <= n; i++) printf("%d ", a[i]);
  return 0;
}
