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;
const int N = 200005;
long long int parent[N], connected[N];
struct DSU {
  void intialize(int x) {
    for (long long int i = 1; i < x; i++) {
      parent[i] = i;
      connected[i] = 1;
    }
  }
  long long int getparent(long long int k) {
    while (k != parent[k]) {
      parent[k] = parent[parent[k]];
      k = parent[k];
    }
    return k;
  }
  long long int getsize(long long int k) { return connected[getparent(k)]; }
  bool unionn(long long int u, long long int v) {
    long long int parent1 = getparent(u), parent2 = getparent(v);
    if (parent1 == parent2) return 0;
    if (connected[parent1] > connected[parent2]) swap(parent1, parent2);
    connected[parent2] += connected[parent1];
    connected[parent1] = 0;
    parent[parent1] = parent[parent2];
    return 1;
  }
};
void solve() {
  long long int n;
  cin >> n;
  DSU dsu;
  dsu.intialize(n + 3);
  long long int root = -1;
  long long int a[n + 1];
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    bool chk = dsu.unionn(a[i], i);
    if (!chk) {
      if (root == -1) root = i;
      dsu.unionn(i, root);
      if (a[i] == root) continue;
      a[i] = root;
      ans++;
    }
  }
  cout << ans << "\n";
  for (long long int i = 1; i <= n; i++) cout << a[i] << " ";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
}
