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[200001], a[200001], b[200001];
int Find(int x) {
  if (a[x] == x) return x;
  return Find(a[x]);
}
void Union(int x, int y) {
  x = Find(x), y = Find(y);
  if (x != y) a[x] = y;
}
int main() {
  int n, cnt = 0, sgn = 0;
  cin >> n;
  for (int i = 0; i <= n; ++i) a[i] = i, b[i] = false;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
    if (p[i] != i && Find(i) == Find(p[i]))
      p[i] = i, sgn++, b[i] = true;
    else
      Union(i, p[i]);
  }
  int flag = 0, root = 0, tmp = 0;
  for (int i = 1; i <= n; ++i) {
    if (p[i] == i) {
      if (b[i] == false) {
        root = i, flag = 1;
        break;
      }
      tmp = i;
    }
  }
  if (flag != 1) root = tmp, cnt++;
  flag = 0;
  for (int i = 1; i <= n; ++i) {
    if (i != root && p[i] == i) {
      tmp = Find(i);
      a[tmp] = root;
      p[i] = root;
      cnt++, flag++;
    }
  }
  cout << cnt << endl << p[1];
  for (int i = 2; i <= n; ++i) cout << " " << p[i];
  cout << endl;
  return 0;
}
