3
2 1 1
 6
6 2 6 2 4 2
 2
1 2
 8
2 1 2 2 6 5 6 6
 18
2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18
 7
1 2 3 4 5 6 7
 7
4 3 2 6 3 5 2
 7
7 5 3 1 2 1 5
 7
1 6 4 4 5 6 7

1
2 2 1  0
6 2 6 2 4 2  1 
1 1 
 2 
2 2 2 2 6 2 6 6 
 5 
2 3 4 5 11 7 8 9 10 11 11 11 14 15 11 17 18 11 
 6 
1 1 1 1 1 1 1 
 1
4 3 3 6 3 5 2  1
7 5 3 1 3 1 5  4 
1 6 4 1 1 1 1 

#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
struct debugger {
  static void call(const char* it) {}
  template <typename T, typename... valT>
  static void call(const char* it, T val, valT... rest) {
    string var = "";
    for (; *it && *it != ','; it++)
      if (*it != ' ') var += *it;
    cerr << var << '=' << val << " ";
    call(++it, rest...);
  }
};
const int MAX = 2e5 + 10;
int P[MAX], V[MAX], root = -1, cnt = 0;
void dfs(int u) {
  V[u] = 1;
  int v = P[u];
  if (!V[v]) {
    dfs(v);
  } else if (V[v] == 1) {
    if (root != u) {
      if (root == -1) root = u;
      P[u] = root, cnt++;
    }
  }
  V[u] = 2;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < (int)n; i++) {
    scanf("%d", &P[i + 1]);
    if (P[i + 1] == i + 1) root = i + 1;
  }
  for (int i = 0; i < (int)n; i++) {
    int u = i + 1;
    if (!V[u]) {
      dfs(u);
    }
  }
  printf("%d\n", cnt);
  for (int i = 0; i < (int)n; i++) {
    printf("%d ", P[i + 1]);
  }
  puts("");
}
