#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) {
    memset(vis, 0, sizeof(vis));
    for (int i = (1); i <= (n); i++) cin >> a[i];
    int cnt = 1;
    int rt = -1;
    int num = 0;
    for (int i = (1); i <= (n); i++) {
      if (a[i] == i && rt == -1) {
        rt = i;
        vis[i] = 1;
        cnt++;
        continue;
      }
      if (vis[i] == 0) {
        int id = i;
        while (vis[id] == 0) {
          vis[id] = cnt;
          id = a[id];
          if (vis[id] == cnt) {
            if (id != a[id] || rt != -1) {
              a[id] = -1;
              num++;
            } else
              rt = 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;
}
