#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C& _a4, C _b4) {
  _a4 = min(_a4, _b4);
}
template <class C>
void maxi(C& _a4, C _b4) {
  _a4 = max(_a4, _b4);
}
template <class TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char* sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[";
  for (auto& vv : V) os << vv << ",";
  os << "]";
  return os;
}
long long n;
long long f[200010];
long long find(long long a) { return f[a] == a ? a : f[a] = find(f[a]); }
bool uni(long long a, long long b) {
  a = find(a);
  b = find(b);
  if (a == b) return 0;
  f[a] = b;
  return 1;
}
long long t[200010];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  if (0) cout << fixed << setprecision(6);
  cin >> n;
  for (long long i = (0); i <= ((long long)(n)-1); i++) f[i] = i;
  long long root = -1;
  long long res = 0;
  for (long long i = (0); i <= ((long long)(n)-1); i++) {
    cin >> t[i];
    t[i]--;
    if (t[i] == i) {
      root = i;
      res = -1;
    }
  }
  for (long long i = (0); i <= ((long long)(n)-1); i++) {
    if (!uni(t[i], i)) {
      if (root == -1) root = i;
      res++;
      t[i] = root;
    }
  }
  cout << res << "\n";
  for (long long i = (0); i <= ((long long)(n)-1); i++) cout << t[i] + 1 << " ";
  cout << "\n";
}
