#include <bits/stdc++.h>
using namespace std;
vector<int> v;
vector<int> vis;
vector<int> c;
void dfs(int x) {
  c[x] = 1;
  if (c[v[x]] == 2) {
    c[x] = 2;
  } else if (c[v[x]] == 1) {
    v[x] = x;
  } else if (c[v[x]] == 0) {
    dfs(v[x]);
  }
  c[x] = 2;
}
int main() {
  int n;
  scanf("%d", &n);
  v.resize(n);
  int n_roots = 0;
  int root = -1;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    v[i] = x - 1;
  }
  vector<int> w = v;
  for (int i = 0; i < n; ++i) {
    if (v[i] == i) {
      root = i;
      break;
    }
  }
  c.assign(n, 0);
  for (int i = 0; i < n; ++i) {
    if (c[i] == 0) dfs(i);
  }
  for (int i = 0; i < n; ++i) {
    if (v[i] != i) continue;
    if (root == -1) {
      root = i;
    } else {
      v[i] = root;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (v[i] != w[i]) ++ans;
  }
  cout << ans << endl;
  for (int x = 0; x < v.size(); x++) {
    cout << v[x] + 1 << " ";
  }
  return 0;
}
