#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long double eps = 1e-8;
template <typename T>
void cmin(T &x, T y) {
  x = y < x ? y : x;
}
template <typename T>
void cmax(T &x, T y) {
  x = y > x ? y : x;
}
long long read() {
  char ch = getchar();
  long long x = 0;
  int op = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') op = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
  return x * op;
}
void write(long long a) {
  if (a < 0) putchar('-'), a = -a;
  if (a >= 10) write(a / 10);
  putchar(a % 10 + '0');
}
long long ksm(long long x, long long p) {
  long long ret = 1;
  for (; p; p >>= 1, x = x * x)
    if (p & 1) ret = ret * x;
  return ret;
}
int n, fa[200005], a[200005], b[200005], stk[200005], cnt, top, rt, mk[200005];
int getfa(int x) { return (x == fa[x] || !fa[x]) ? x : fa[x] = getfa(fa[x]); }
int main() {
  n = read();
  for (int i = (1); i <= (n); i++) {
    a[i] = b[i] = read();
    if (i == a[i]) fa[i] = i;
  }
  for (int i = (1); i <= (n); i++) {
    if (i == a[i]) continue;
    if (getfa(a[i]) == i)
      fa[i] = b[i] = i, mk[i] = 1;
    else
      fa[i] = a[i];
  }
  for (int i = (1); i <= (n); i++)
    if (getfa(i) == i) stk[++top] = i;
  for (int i = (1); i <= (top); i++)
    if (!mk[stk[i]]) {
      rt = stk[i];
      break;
    }
  if (!rt) rt = stk[1];
  for (int i = (1); i <= (top); i++)
    if (rt != stk[i]) b[stk[i]] = rt;
  for (int i = (1); i <= (n); i++)
    if (b[i] != a[i]) cnt++;
  printf("%d\n", cnt);
  for (int i = (1); i <= (n); i++) printf("%d ", b[i]);
  return 0;
}
