#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int M = 2e5 + 5, INF = 0x3f3f3f3f, mod = 1e9 + 7;
int A[M];
int fa[M];
int get(int x) {
  if (fa[x] != x) return fa[x] = get(fa[x]);
  return x;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int j = 1; j <= n; j++) fa[j] = j;
  int t = 0;
  int cnt = 0;
  for (int j = 1; j <= n; j++) {
    scanf("%d", &A[j]);
    if (A[j] == j)
      t = j, cnt++;
    else {
      int a = get(j), b = get(A[j]);
      if (a == b) {
        A[j] = j, cnt++;
      } else
        fa[a] = b;
    }
  }
  if (t == 0) {
    for (int j = 1; j <= n; j++)
      if (A[j] == j) t = j;
    cnt++;
  }
  printf("%d\n", cnt - 1);
  for (int j = 1; j <= n; j++) {
    if (A[j] == j) A[j] = t;
    printf("%d%c", A[j], " \n"[j == n]);
  }
  return 0;
}
