#include <bits/stdc++.h>
using namespace std;
set<int> Set;
vector<int> v[250001];
int a[250001], p[250001], n, i, j, ans;
bool pole[250001], x;
void Merge(int nom1, int nom2) {
  int i;
  if (nom1 == p[1]) {
    for (i = 0; i < v[nom2].size(); i++) Set.erase(v[nom2][i]);
  }
  if (nom2 == p[1]) {
    for (i = 0; i < v[nom1].size(); i++) Set.erase(v[nom1][i]);
  }
  if (v[nom1].size() < v[nom2].size()) {
    for (i = 0; i < v[nom1].size(); i++) {
      v[nom2].push_back(v[nom1][i]);
      p[v[nom1][i]] = nom2;
    }
    v[nom1].clear();
  } else {
    for (i = 0; i < v[nom2].size(); i++) {
      v[nom1].push_back(v[nom2][i]);
      p[v[nom2][i]] = nom1;
    }
    v[nom2].clear();
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == i) x = true;
  }
  for (i = 1; i <= n; i++) {
    v[i].push_back(i);
    p[i] = i;
  }
  for (i = 2; i <= n; i++) Set.insert(i);
  if (!x) {
    for (i = 1; i <= n; i++)
      if (p[i] != p[a[i]]) {
        pole[i] = true;
        Merge(p[i], p[a[i]]);
      }
    for (i = 1; i <= n; i++)
      if (!pole[i]) {
        if (!x) {
          ans++;
          x = true;
          a[i] = i;
          continue;
        }
        ans++;
        if (p[i] != p[1]) {
          Merge(p[i], p[1]);
          a[i] = 1;
        } else {
          a[i] = *Set.begin();
          Merge(p[i], p[*Set.begin()]);
        }
      }
  } else {
    x = false;
    for (i = 1; i <= n; i++)
      if (p[i] != p[a[i]]) {
        pole[i] = true;
        Merge(p[i], p[a[i]]);
      }
    for (i = 1; i <= n; i++)
      if (!pole[i]) {
        if (a[i] == i && !x) {
          x = true;
          continue;
        }
        ans++;
        if (p[i] != p[1]) {
          Merge(p[i], p[1]);
          a[i] = 1;
        } else {
          a[i] = *Set.begin();
          Merge(p[i], p[*Set.begin()]);
        }
      }
  }
  cout << ans << '\n';
  for (i = 1; i <= n; i++) cout << a[i] << " ";
  cout << '\n';
  return 0;
}
