#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> used(n, 0);
  vector<int> loops;
  int root = -1;
  int curUse = 1;
  int cur, next;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  cur = 0;
  for (int i = 0; i < n; i++) {
    if (used[i]) {
      continue;
    }
    cur = i;
    while (true) {
      used[cur] = curUse;
      next = a[cur];
      if (cur == next) {
        if (root == -1) {
          root = cur;
        } else {
          loops.push_back(cur);
        }
        break;
      } else if (used[next] == curUse) {
        loops.push_back(cur);
        break;
      } else if (used[next]) {
        break;
      }
      cur = next;
    }
    curUse++;
  }
  int startIndex = 0;
  if (root == -1) {
    root = loops[0];
    a[root] = root;
    startIndex++;
  }
  for (int i = startIndex; i < loops.size(); i++) {
    a[loops[i]] = root;
  }
  cout << loops.size() << endl;
  for (int i : a) {
    cout << i + 1 << " ";
  }
  cout << endl;
  return 0;
}
