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;
template <int um>
class UF {
 public:
  vector<int> par;
  UF() {
    par = vector<int>(um, 0);
    for (int i = 0; i < um; i++) par[i] = i;
  }
  int operator[](int x) {
    return par[x] == x ? x : par[x] = operator[](par[x]);
  }
  void operator()(int x, int y) {
    x = operator[](x);
    y = operator[](y);
    if (x != y) par[x] = y;
  }
};
int n;
int a[201010];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]), a[i]--;
  UF<201010> uf;
  vector<int> roots, loops;
  for (int i = 0; i < n; i++) {
    if (a[i] == i) {
      roots.push_back(i);
      continue;
    }
    if (uf[i] == uf[a[i]])
      loops.push_back(i);
    else
      uf(i, a[i]);
  }
  int ans = 0;
  if (roots.size() == 0) {
    int root = loops[0];
    a[root] = root;
    ans++;
    for (int i = 1; i < loops.size(); i++) a[i] = root, ans++;
  } else {
    int root = roots[0];
    for (int i = 1; i < roots.size(); i++) a[i] = root, ans++;
    for (int i = 0; i < loops.size(); i++) a[i] = root, ans++;
  }
  printf("%d\n", ans);
  for (int i = 0; i < n; i++) printf("%d ", a[i] + 1);
  printf("\n");
}
