#include <bits/stdc++.h>
using namespace std;
void read(int a = 0) {
  freopen("in", "r", stdin);
  if (a) freopen("out", "w", stdout);
}
struct dsu {
  vector<int> p, rank, sum;
  dsu(int n) {
    p.assign(n, 0);
    rank.assign(n, 0);
    sum.assign(n, 1);
    for (int i = 0; i < n; i++) p[i] = i;
  }
  int find_set(int i) { return p[i] == i ? i : p[i] = find_set(p[i]); }
  bool issame_set(int i, int j) { return (find_set(i) == find_set(j)); }
  void union_sets(int i, int j) {
    if (!issame_set(i, j)) {
      int n = find_set(i);
      int m = find_set(j);
      if (rank[n] < rank[m]) {
        p[n] = m;
        sum[m] += sum[n];
      } else {
        p[m] = n;
        sum[n] += sum[m];
        if (rank[n] == rank[m]) {
          rank[n]++;
        }
      }
    }
  }
  int sum_set(int i) { return sum[find_set(i)]; }
};
int a[2 * 100009];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  dsu tree(n);
  int par = 0;
  bool done = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == i + 1) done = 1, par = i;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (done && i == par) continue;
    int x = i;
    int y = a[i] - 1;
    if (!tree.issame_set(x, y)) {
      tree.union_sets(x, y);
    } else {
      if (done) {
        int tmp = tree.find_set(par);
        ans++;
        tree.union_sets(x, tmp);
        a[i] = tmp + 1;
      } else {
        ans++;
        done = 1;
        par = i;
        a[i] = i + 1;
      }
    }
  }
  cout << ans << "\n";
  for (int i = 0; i < n; i++) cout << a[i] << " ";
}
