#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j, k, p, l, d, q, e, mx, mn, pas, ans;
vector<pair<long long, long long> > v;
string s[1005];
long long fx[(long long)(4e5 + 11)] = {0};
long long c[(long long)(4e5 + 11)] = {0};
long long a[(long long)(4e5 + 11)];
long long S;
bool e1 = 0;
void go(long long x) {
  if (fx[x] == 1) {
    v.push_back({1, x});
    fx[x] = 2;
    return;
  }
  if (fx[x] == 2) return;
  fx[x] = 1;
  if (a[x] == x) {
    v.push_back({0, x});
    fx[x] = 2;
    return;
  }
  go(a[x]);
  fx[x] = 2;
  return;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i != a[i]) c[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (!c[i]) {
      S = i;
      e1 = 0;
      go(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!fx[i]) {
      S = i;
      e1 = 0;
      go(i);
    }
  }
  sort(v.begin(), v.end());
  if (v[0].first) {
    a[v[0].second] = v[0].second;
  }
  for (int i = 1; i < v.size(); i++) {
    a[v[i].second] = a[v[i - 1].second];
  }
  cout << v.size() - 1 + v[0].first << endl;
  for (int i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  return 0;
}
