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;
int P[200005], N;
vector<int> E[200005];
int Color[200005];
int BRKA, Root[200005], Size[200005], Sink[200005];
void dfs(int x) {
  if (Color[x]) return;
  Color[x] = BRKA;
  Size[BRKA]++;
  for (int y : E[x]) dfs(y);
}
int nadji(int x, int step) {
  while (step--) {
    x = P[x];
  }
  return x;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", P + i);
    E[i].push_back(P[i]);
    E[P[i]].push_back(i);
  }
  for (int i = 1; i <= N; i++) {
    if (!Color[i]) {
      BRKA++;
      Root[BRKA] = i;
      dfs(i);
    }
  }
  for (int i = 1; i <= BRKA; i++) {
    Sink[i] = nadji(Root[i], Size[i]);
  }
  int ima = -1;
  for (int i = 1; i <= BRKA; i++) {
    if (Sink[i] == P[Sink[i]]) ima = i;
  }
  if (ima != -1) {
    swap(Root[ima], Root[1]);
    swap(Size[ima], Size[1]);
    swap(Sink[ima], Sink[1]);
  }
  int chg = 0;
  for (int i = BRKA; i > 1; i--) {
    P[Sink[i]] = Root[i - 1];
    chg++;
  }
  if (ima == -1) {
    P[Sink[1]] = Sink[1];
    chg++;
  }
  printf("%d\n", chg);
  for (int i = 1; i <= N; i++) printf("%d%c", P[i], i == N ? '\n' : ' ');
  scanf("%d", &N);
  return 0;
}
