#include <bits/stdc++.h>
using namespace std;
namespace io {
const int __SIZE = (1 << 21) + 1;
char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1,
                                           __c, qu[55];
int __f, qr, _eof;
inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; }
inline void gc(char &x) {
  x = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                   (iS == iT ? EOF : *iS++))
                : *iS++);
}
inline void pc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
inline void pstr(const char *s) {
  int __len = strlen(s);
  for (__f = 0; __f < __len; ++__f) pc(s[__f]);
}
inline void gstr(char *s) {
  for (__c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++);
       __c < 32 || __c > 126 || __c == ' ';)
    __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                    : *iS++);
  for (; __c > 31 && __c < 127 && __c != ' ';
       ++s, __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++))
    *s = __c;
  *s = 0;
}
template <class I>
inline bool gi(I &x) {
  _eof = 0;
  for (__f = 1,
      __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                        (iS == iT ? EOF : *iS++))
                      : *iS++);
       (__c < '0' || __c > '9') && !_eof;
       __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++)) {
    if (__c == '-') __f = -1;
    _eof |= __c == EOF;
  }
  for (x = 0; __c <= '9' && __c >= '0' && !_eof;
       __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++))
    x = x * 10 + (__c & 15), _eof |= __c == EOF;
  x *= __f;
  return !_eof;
}
template <class I>
inline void gp(I x) {
  if (!x) pc('0');
  if (x < 0) pc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) pc(qu[qr--]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io::gc;
using io::gi;
using io::gp;
using io::gstr;
using io::pc;
using io::pstr;
void scan() { return; }
template <class T, typename... Args>
void scan(T &a, Args &&...args) {
  gi(a);
  scan(args...);
  return;
}
template <typename T>
void scann(T a, T b) {
  for (auto it = a; it != b; ++it) scan(*it);
}
template <typename T>
void scerr(T a, T b) {
  for (auto it = a; it != b; ++it) cerr << *it << " ";
  cerr << '\n';
}
void print() { return; }
template <class T, typename... Args>
void print(T a, Args... args) {
  gp(a);
  pc(' ');
  print(args...);
  return;
}
void cer() { return; }
template <class T, typename... Args>
void cer(T a, Args... args) {
  cerr << " " << a;
  cer(args...);
  return;
}
const int N = 2e5 + 100;
const int M = 1e6 + 2;
const long long mod = 998244353;
const int inf = 2e9 + 3;
const long long INF = 1e18;
void data() {}
int n, a[N], u[N], ans, glr, is[N];
vector<int> g[N], h[N], al[N], root;
void dfs(int v) {
  u[v] = 1;
  for (auto to : g[v]) {
    if (!u[to]) {
      dfs(to);
    }
  }
}
void dfs2(int v) {
  u[v] = 1;
  for (auto to : g[v]) {
    if (u[to]) {
      root.push_back(to);
    }
    if (u[to] == 0) {
      dfs2(to);
    }
  }
}
void al1(int v) {
  u[v] = 2;
  for (auto to : al[v]) {
    if (u[to] != 2) al1(to);
  }
}
int main() {
  data();
  scan(n);
  for (int i = 1; i <= n; ++i) {
    scan(a[i]);
    g[i].push_back(a[i]);
    h[a[i]].push_back(i);
    al[i].push_back(a[i]);
    al[a[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] == i) {
      root.push_back(i);
      al1(i);
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (!u[i]) {
      dfs2(i);
      al1(i);
    }
  }
  for (int i = 0; i < (int)root.size(); ++i) {
    if (a[root[i]] == root[i]) {
      glr = root[i];
    }
    is[root[i]] = 1;
  }
  if (glr) {
    for (int i = 1; i <= n; ++i) {
      if (is[i] && i != glr) {
        a[i] = glr;
        ans++;
      }
    }
    print(ans);
    pc('\n');
    for (int i = 1; i <= n; ++i) print(a[i]);
  } else {
    glr = root[0];
    for (int i = 1; i <= n; ++i) {
      if (is[i]) {
        a[i] = glr;
        ans++;
      }
    }
    print(ans);
    pc('\n');
    for (int i = 1; i <= n; ++i) print(a[i]);
  }
}
