#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
T ext_gcd(T a, T b, T& first, T& second) {
  if (b == 0) {
    first = 1, second = 0;
    return a;
  }
  T d = ext_gcd(b, a % b, second, first);
  second -= first * (a / b);
  return d;
}
template <typename T>
T inverse(T a, T n) {
  T first, second;
  T t = ext_gcd(a, n, first, second);
  if (t != 1) return -1;
  return (first % n + n) % n;
}
template <typename T>
T Q_mul(T a, T b, T Mod) {
  T ret;
  for (ret = 0; b; b >>= 1, a = (a + a) % Mod)
    if (b & 1) ret = (ret + a) % Mod;
  return ret;
}
template <typename T>
T quick_pow_mod(T a, T b, T Mod) {
  T ret;
  for (ret = 1; b; b >>= 1, (a *= a) %= Mod)
    if (b & 1) (ret *= a) %= Mod;
  return ret;
}
template <typename T>
T quick_pow(T a, T b) {
  T ret;
  for (ret = 1; b; b >>= 1, a *= a)
    if (b & 1) ret *= a;
  return ret;
}
double combination(int n, int r) {
  if (r < n - r) return combination(n, n - r);
  double s = 1.0;
  for (int i = 1; i <= int(n - r); ++i) s *= (r + i), s /= i;
  return s;
}
template <typename T>
inline void read(T& v) {
  T ret = 0, sgnv = 1;
  char p;
  while (!isdigit(p = getchar()))
    if (p == '-') sgnv = -1;
  do ret = (ret << 3) + (ret << 1) + p - '0';
  while (isdigit(p = getchar()));
  v = sgnv * ret;
}
struct Edge {
  int v, next;
} edge[200000 + 5];
int cnt, head[200000 + 5], s[200000 + 5], t[200000 + 5], p[200000 + 5];
bool vis[200000 + 5];
inline void addedge(int u, int v) {
  edge[cnt].v = v, edge[cnt].next = head[u], head[u] = cnt++;
}
void dfs(int u, int root) {
  vis[u] = true;
  for (int i = head[u]; ~i; i = edge[i].next)
    if (edge[i].v != root) dfs(edge[i].v, root);
}
int main() {
  int n, u, tot = 0, len = 0;
  read(n), memset(head + 1, -1, sizeof(int) * n);
  for (int i = 1; i <= int(n); ++i) {
    read(u), p[i] = u;
    if (u != i)
      addedge(u, i);
    else
      s[tot++] = i;
  }
  for (int i = 0; i < int(tot); ++i) dfs(s[i], 0);
  for (int i = 1; i <= int(n); ++i)
    if (!vis[i]) {
      u = i;
      while (!vis[u]) vis[u] = true, u = p[u];
      t[len++] = u, dfs(u, u);
    }
  for (int i = 1; i <= int(tot - 1); ++i) p[s[i]] = s[0];
  if (tot)
    for (int i = 0; i < int(len); ++i) p[t[i]] = s[0];
  else {
    p[t[0]] = t[0];
    for (int i = 1; i <= int(len - 1); ++i) p[t[i]] = t[0];
  }
  printf("%d", tot == 0 ? len : tot + len - 1), putchar('\n');
  for (int i = 1; i <= int(n); ++i)
    printf("%d", p[i]), i == n ? putchar('\n') : putchar(' ');
  return 0;
}
