#include <bits/stdc++.h>
using namespace std;
int root, n, m, tot, ans, a[2000010], zy[2000010];
bool b[2000010], v[2000010];
void dfs(int k) {
  if (b[a[k]]) {
    b[a[k]] = v[a[k]] = false;
    dfs(a[k]);
    v[a[k]] = true;
  } else {
    if (!v[a[k]]) {
      tot++;
      if (root == 0) {
        root = k;
        zy[k] = k;
      } else
        zy[k] = root;
    }
  }
}
int work(int k) {
  if (v[a[k]]) {
    v[a[k]] = false;
    return (work(a[k]));
  } else
    return k;
}
int main(int argc, const char* argv[]) {
  memset(b, true, sizeof(b));
  int i, j, k;
  tot = 0;
  cin >> n;
  root = 0;
  for (i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] == i) root = i;
    zy[i] = a[i];
  }
  if (root != 0) tot = -1;
  for (i = 1; i <= n; ++i)
    if (b[i]) {
      b[i] = v[i] = false;
      dfs(i);
      v[i] = true;
    }
  cout << tot << endl;
  for (i = 1; i <= n; ++i) cout << zy[i] << " ";
  return 0;
}
