3
2 1 1
 6
6 2 6 2 4 2
 2
1 2
 8
2 1 2 2 6 5 6 6
 18
2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18
 7
1 2 3 4 5 6 7
 7
4 3 2 6 3 5 2
 7
7 5 3 1 2 1 5
 7
1 6 4 4 5 6 7

1
2 2 1  0
6 2 6 2 4 2  1 
1 1 
 2 
2 2 2 2 6 2 6 6 
 5 
2 3 4 5 11 7 8 9 10 11 11 11 14 15 11 17 18 11 
 6 
1 1 1 1 1 1 1 
 1
4 3 3 6 3 5 2  1
7 5 3 1 3 1 5  4 
1 6 4 1 1 1 1 

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int f[N], a[N], check[N], tem;
int finda(int x) {
  if (check[x] == tem) return x;
  check[x] = tem;
  if (f[x] == x) return x;
  return f[x] = finda(f[x]);
}
int main() {
  int n, x, ans;
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) f[i] = a[i];
    memset(check, 0, sizeof(check));
    for (int i = 1; i <= n; i++) {
      tem = i;
      finda(i);
    }
    x = ans = 0;
    for (int i = 1; i <= n; i++) {
      if (f[i] == i && a[i] == i) {
        x = i;
        f[i] = 0;
        break;
      }
    }
    if (!x) {
      ans++;
      for (int i = 1; i <= n; i++) {
        if (f[i] == i) {
          x = i;
          a[i] = i;
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      if (f[i] == i) {
        ans++;
        a[i] = x;
      }
    }
    printf("%d\n", ans);
    for (int i = 1; i < n; i++) {
      printf("%d ", a[i]);
    }
    printf("%d\n", a[n]);
  }
  return 0;
}
