#include <bits/stdc++.h>
using namespace std;
long long p[200009], par[200009];
long long res;
bool bb[200009];
bool b[200009], bo[200009];
long long seq[200009];
long long dfs(long long v) {
  long long ver = p[v];
  if (par[ver] != -1) {
    return par[ver];
  }
  if (v == ver) {
    par[v] = v;
    return v;
  }
  if (b[v] == 1) {
    p[v] = -1;
    bb[v] = 1;
    return v;
  }
  b[v] = 1;
  long long pr = dfs(ver);
  par[v] = pr;
}
int main() {
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    seq[i] = p[i];
  }
  memset(par, -1, sizeof(par));
  for (int i = 1; i <= n; i++) {
    if (!b[i]) par[i] = dfs(i);
  }
  for (int i = 1; i <= n; i++) {
    bo[par[i]] = 1;
  }
  long long dad = -1;
  for (int i = 1; i <= n; i++) {
    if (par[i] == i && bb[i] == 0) {
      dad = i;
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (p[i] == -1) {
      if (dad == -1) {
        p[i] = i;
        dad = i;
        par[i] = i;
      } else {
        p[i] = dad;
        par[i] = par[dad];
      }
    }
  }
  long long prev = -1;
  for (int i = 1; i <= n; i++) {
    if (bo[i] == 0) continue;
    if (prev == -1) {
      prev = i;
      continue;
    } else {
      if (i == dad) continue;
      p[i] = prev;
      prev = p[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (p[i + 1] != seq[i + 1]) res++;
  }
  cout << res << endl;
  for (int i = 0; i < n; i++) {
    cout << p[i + 1] << " ";
  }
  return 0;
}
