#include <bits/stdc++.h>
using namespace std;
int pr[200010], a[200010], n, sum, b[200010];
int get_pr(int x) {
  if (pr[x] == 0)
    return x;
  else
    return pr[x] = get_pr(pr[x]);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    b[i] = x;
    int u = get_pr(i);
    int v = get_pr(x);
    if (u == v) {
      a[i] = i;
    } else {
      pr[u] = v;
      a[i] = x;
    }
  }
  int cur = 0;
  for (int i = 1; i <= n; i++) {
    if (pr[i] == 0 && a[i] == b[i]) {
      cur = i;
      break;
    }
  }
  if (cur == 0) cur = get_pr(1);
  for (int i = 1; i <= n; i++) {
    int u = get_pr(i);
    if (u != cur) {
      pr[u] = cur;
      a[u] = cur;
    }
  }
  for (int i = 1; i <= n; i++)
    if (a[i] != b[i]) sum++;
  cout << sum << "\n";
  for (int i = 1; i <= n; i++) cout << a[i] << " ";
}
