#include <bits/stdc++.h>
using namespace std;
long long n;
long long p[200001];
long long s[200001];
long long res[200001];
vector<long long> v;
bool cmp(long long i, long long j) { return abs(p[i] - i) < abs(p[j] - j); }
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
    res[i] = p[i];
  }
  for (long long i = 0; i < n; i++) {
    if (!s[i]) {
      long long j;
      set<long long> u;
      for (j = i; !s[j]; j = p[j]) {
        u.insert(j);
        s[j] = 1;
      }
      if (!u.count(j)) continue;
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end(), cmp);
  for (long long i = 0; i < v.size(); i++) res[v[i]] = v[0];
  long long cnt = 0;
  for (long long i = 0; i < n; i++)
    if (res[i] != p[i]) cnt++;
  cout << cnt << endl;
  for (long long i = 0; i < n; i++) cout << res[i] + 1 << " ";
  cout << endl;
  return 0;
}
