#include <bits/stdc++.h>
using namespace std;
int a[200005];
int vis[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n) {
    int cnt = 1;
    int rt = -1;
    int num = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = (1); i <= (n); i++) {
      cin >> a[i];
      if (a[i] == i) rt = i;
    }
    for (int i = (1); i <= (n); i++) {
      int id = i;
      while (vis[id] == 0) {
        vis[id] = cnt;
        if (vis[a[id]] == cnt) {
          if (a[id] != rt) {
            a[id] = -1;
            num++;
            break;
          }
        }
        id = a[id];
      }
      cnt++;
    }
    printf("%d\n", num);
    for (int i = (1); i <= (n); i++) {
      if (a[i] == -1 && rt == -1) rt = i;
      if (a[i] != -1)
        printf("%d ", a[i]);
      else
        printf("%d ", rt);
    }
    printf("\n");
  }
  return 0;
}
