#include <bits/stdc++.h>
using namespace std;
int root[200010], p[200010], n, ans = 0, m = -1;
set<int> trees, ill;
int findRoot(int i) {
  if (p[root[i]] != root[i]) root[i] = findRoot(p[i]);
  return root[i];
}
bool child(int t, int i) {
  int par = p[i];
  while (1) {
    if (par == t) return true;
    if (p[par] == par) return false;
    par = p[par];
  }
}
void add(int i, int t) {
  if (t == i) {
    trees.insert(i);
    p[i] = t;
  } else if (child(i, t)) {
    ill.insert(i);
  } else
    p[i] = t;
}
int main() {
  cin >> n;
  int t;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t);
    root[i] = i;
    p[i] = i;
    add(i, t);
  }
  if (trees.size() > 0) {
    auto it = trees.begin();
    m = *it;
    trees.erase(it);
  } else if (ill.size() > 0) {
    auto it = ill.begin();
    m = *it;
    ill.erase(it);
    ans++;
    p[m] = m;
  } else {
    cout << 0 << endl;
    for (int i = 1; i <= n; i++) printf("%d ", p[i]);
    return 0;
  }
  for (auto it = trees.begin(); it != trees.end(); it++) {
    p[*it] = m;
    ans++;
  }
  for (auto it = ill.begin(); it != ill.end(); it++) {
    p[*it] = m;
    ans++;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) printf("%d ", p[i]);
  return 0;
}
