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 n, p[210000], used[210000], used2[210000], root, ans, good_root = -1;
vector<int> l[210000];
vector<int> comp;
vector<int> roots;
void dfs(int v) {
  used[v] = 1;
  comp.push_back(v);
  int k = l[v].size();
  for (int i = 0; i < k; i++) {
    int v2 = l[v][i];
    if (!used[v2]) dfs(v2);
  }
  return;
}
void cycle_dfs(int v) {
  used2[v] = 1;
  while (used2[p[v]] == 0) {
    v = p[v];
    used2[v] = 1;
  }
  root = p[v];
  return;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    if (i != p[i]) {
      l[i].push_back(p[i]);
      l[p[i]].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      comp.clear();
      dfs(i);
      root = -1;
      int k = comp.size();
      for (int j = 0; j < k; j++)
        if (p[comp[j]] == comp[j] || p[p[comp[j]]] == comp[j]) {
          root = comp[j];
          break;
        }
      if (root == -1) {
        cycle_dfs(i);
      }
      roots.push_back(root);
    }
  }
  int k = roots.size();
  for (int i = 0; i < k; i++) {
    if (p[roots[i]] == roots[i]) {
      good_root = roots[i];
      break;
    }
  }
  if (good_root == -1) {
    good_root = roots[0];
    p[roots[0]] = roots[0];
    ans++;
  }
  for (int i = 0; i < k; i++) {
    int rt = roots[i];
    if (rt != good_root) {
      p[rt] = good_root;
      ans++;
    }
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) cout << p[i] << ' ';
  return 0;
}
