#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const long long MMOD = 0x7FFFFFFF;
const int MOD = 1e9 + 7;
const double EPS = 1e-6;
const int maxn = 200000 + 5;
int N;
int arr[maxn] = {0};
int yl[maxn] = {0};
int fa[maxn] = {0};
int rk[maxn] = {0};
int ans = 0;
int find(int x) {
  if (x == fa[x]) return x;
  fa[x] = find(fa[x]);
  return fa[x];
}
bool uni(int x, int y) {
  int k1 = find(x);
  int k2 = find(y);
  if (k1 == k2) return true;
  if (rk[k1] < rk[k2])
    fa[k1] = k2;
  else
    fa[k2] = k1;
  if (rk[k1] == rk[k2]) rk[k2]++;
  return false;
}
vector<int> vc;
int main(void) {
  scanf("%d", &N);
  int root = -1;
  for (int i = (1); i <= (N); i++) {
    rk[i] = 1;
    fa[i] = i;
  }
  for (int i = (1); i <= (N); i++) {
    scanf("%d", &arr[i]);
    yl[i] = arr[i];
    if (arr[i] == i) {
      if (root == -1)
        root = i;
      else {
        arr[i] = root;
        uni(i, root);
      }
    } else {
      if (uni(i, arr[i])) vc.push_back(i);
    }
  }
  if (root == -1) {
    root = vc.back();
    arr[root] = root;
    vc.pop_back();
  }
  for (int i = 0; i < (vc.size()); i++) {
    arr[vc[i]] = root;
  }
  int ans = 0;
  for (int i = (1); i <= (N); i++)
    if (yl[i] != arr[i]) ans++;
  cout << ans << endl;
  printf("%d", arr[1]);
  for (int i = (2); i <= (N); i++) printf(" %d", arr[i]);
  puts("");
  return 0;
}
