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>
using namespace std;
const double PI = acos(-1.0);
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
vector<int> heads, circs;
int par[200005], color[200005];
void DFS(int s) {
  color[s] = 1;
  if (color[par[s]] == 0)
    DFS(par[s]);
  else if (color[par[s]] == 1) {
    if (par[s] == s)
      heads.push_back(s);
    else
      circs.push_back(s);
  }
  color[s] = 2;
}
int main() {
  int n, i, chng, s;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &par[i]);
    par[i]--;
    color[i] = 0;
  }
  for (i = 0; i < n; i++)
    if (color[i] == 0) DFS(i);
  chng = heads.size() + circs.size() - 1;
  if (chng > 0) {
    s = 0;
    if (heads.size() == 0) {
      par[circs[0]] = circs[0];
      heads.push_back(circs[0]);
      s = 1;
    }
    for (i = 1; i < heads.size(); i++) par[heads[i]] = heads[0];
    for (i = s; i < circs.size(); i++) par[circs[i]] = heads[0];
  }
  printf("%d\n", chng);
  for (i = 0; i < n - 1; i++) printf("%d ", par[i] + 1);
  printf("%d\n", par[i] + 1);
  return 0;
}
