#include <bits/stdc++.h>
using namespace std;
int p[200000];
bool used[200000];
bool now[200000];
int main() {
  vector<int> c(0, 0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  int x;
  int l, r, m;
  queue<int> q;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      x = i;
      while (!used[x] && !now[x]) {
        used[x] = 1;
        now[x] = 1;
        q.push(x);
        x = p[x];
      }
      if (now[x]) {
        l = -1;
        r = c.size();
        while (r - l > 1) {
          m = (r + l) / 2;
          if (c[m] > x)
            r = m;
          else
            l = m;
        }
        c.insert(c.begin() + l + 1, x);
      }
      while (!q.empty()) {
        x = q.front();
        q.pop();
        now[x] = 0;
      }
    }
  }
  x = -1;
  for (int i = 0; i < c.size(); i++) {
    if (p[c[i]] == c[i]) {
      x = c[i];
      break;
    }
  }
  r = 0;
  if (x == -1) {
    x = c[0];
    p[x] = x;
    r = 1;
  }
  for (int i = 0; i < c.size(); i++) {
    if (c[i] != x) {
      p[c[i]] = x;
      r++;
    }
  }
  cout << r << endl;
  for (int i = 0; i < n; i++) {
    cout << p[i] + 1 << " ";
  }
  cout << endl;
  return 0;
}
