#include <bits/stdc++.h>
using namespace std;
int a[200005];
int father[200005];
int seek(int x) { return father[x] == x ? x : father[x] = seek(father[x]); }
set<int> st;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) father[i] = i;
  for (int i = 1; i <= n; i++) {
    int a1 = seek(i);
    int a2 = seek(a[i]);
    if (a1 != a2) father[a1] = a2;
  }
  for (int i = 1; i <= n; i++) {
    int a1 = seek(a[i]);
    st.insert(a1);
  }
  int re = -1, ans = 0;
  for (auto it = st.begin(); it != st.end(); it++) {
    if (a[*it] == *it) {
      re = *it;
      break;
    }
  }
  if (re == -1) {
    for (auto it = st.begin(); it != st.end(); it++) {
      a[*it] = *st.begin();
    }
    ans = st.size();
  } else {
    for (auto it = st.begin(); it != st.end(); it++) {
      a[*it] = re;
    }
    ans = st.size() - 1;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) cout << a[i] << (i == n ? '\n' : ' ');
  return 0;
}
