#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long POWER[65];
long long power(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret *= a;
    a *= a;
    if (ret >= MOD) ret %= MOD;
    if (a >= MOD) a %= MOD;
    b >>= 1;
  }
  return ret;
}
long long inv(long long x) { return power(x, MOD - 2); }
void precompute() {
  POWER[0] = 1;
  for (int i = 1; i < 63; i++) POWER[i] = POWER[i - 1] << 1LL;
}
const int MAXN = 2e5 + 5;
int dsu[MAXN];
int ar[MAXN];
int findR(int x) {
  if (dsu[x] == x) return x;
  return dsu[x] = findR(dsu[x]);
}
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) dsu[i] = i;
  int pos = -1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
    if (ar[i] == i) pos = i;
  }
  for (int i = 1; i <= n; i++) {
    if (ar[i] == i) {
      if (ar[i] == pos)
        ;
      else
        ar[i] = pos, ans++;
      continue;
    }
    int p = findR(i);
    int q = findR(ar[i]);
    if (p == q) {
      if (pos == -1) {
        pos = i;
        ar[i] = i;
        ans++;
      } else {
        ar[i] = pos;
        ans++;
      }
      continue;
    }
    dsu[p] = q;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) {
    if (i != 1) printf(" ");
    printf("%d", ar[i]);
  }
  printf("\n");
  return 0;
}
