#include <bits/stdc++.h>
using namespace std;
vector<int> d;
int a[200010], fa[200010];
int findset(int x) { return fa[x] == x ? x : (fa[x] = findset(fa[x])); }
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    if (a[i] == i) continue;
    int x = findset(i), y = findset(a[i]);
    if (x != y)
      fa[x] = y;
    else
      d.push_back(i);
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] == i) {
      cnt++;
      d.push_back(i);
    }
  for (int i = 0; i < d.size(); i++) a[d[i]] = d[d.size() - 1];
  if (cnt >= 1)
    cout << d.size() - 1 << endl;
  else
    cout << d.size() << endl;
  for (int i = 1; i <= n; i++) printf("%d ", a[i]);
  return 0;
}
