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;
mt19937 rnd(time(0));
const long long N = 2e5 + 7;
const long long MOD = 1e9 + 7;
long long pw(long long b, long long p) {
  b %= MOD;
  long long res = 1;
  while (p > 0) {
    if (p & 1) res = res * b % MOD;
    b = b * b % MOD;
    p >>= 1;
  }
  return res;
}
vector<long long> par(N);
long long find(long long x) {
  if (par[x] == x) return x;
  return par[x] = find(par[x]);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 1; i < n + 1; i++) {
    par[i] = i;
  }
  vector<long long> a(n + 1);
  long long cnt = 0, root = 0;
  for (long long i = 1; i < n + 1; i++) {
    cin >> a[i];
    if (a[i] == i) {
      root = i;
      cnt++;
    } else {
      long long x = find(i), y = find(a[i]);
      if (x == y) {
        a[i] = i;
        cnt++;
      } else {
        par[i] = a[i];
      }
    }
  }
  if (root == 0) {
    for (long long i = 1; i < n + 1; i++) {
      if (a[i] == i) root = i;
    }
    cnt++;
  }
  cout << cnt - 1 << '\n';
  for (long long i = 1; i < n + 1; i++) {
    cout << ((a[i] == i) ? root : a[i]) << ' ';
  }
  return 0;
}
