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;
struct nod {
  int pre, con, hao;
} edge[410000];
int use2[210000], ans, use[210000], num[210000], dl[210000], n, i, j, all, p,
    pos[210000];
void build(int a, int b) {
  p++;
  edge[p].pre = pos[a];
  edge[p].con = b;
  edge[p].hao = i;
  pos[a] = p;
}
void search(int d, int fa) {
  int w;
  if (num[d] == d && use2[d] == 0) dl[++all] = d, use2[d] = 1;
  use[d] = 1;
  for (w = pos[d]; w; w = edge[w].pre)
    if (edge[w].hao != fa) {
      if (use[edge[w].con] == 1) {
        if (use2[edge[w].hao] == 0) {
          dl[++all] = edge[w].hao;
          use2[edge[w].hao] = 1;
        }
        continue;
      }
      search(edge[w].con, edge[w].hao);
    }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
    if (num[i] != i) {
      build(num[i], i);
      build(i, num[i]);
    }
  }
  for (i = 1; i <= n; i++)
    if (use[i] == 0) search(i, 0);
  if (all != 0) {
    for (i = 1; i <= all; i++)
      if (num[dl[i]] == dl[i]) break;
    if (i > all) i = 1, ans++;
    num[dl[i]] = dl[i];
    for (j = 1; j <= all; j++)
      if (j != i) {
        num[dl[j]] = num[dl[i]];
        ans++;
      }
  }
  printf("%d\n", ans);
  for (i = 1; i <= n; i++) printf("%d ", num[i]);
}
