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;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
const unsigned long long int mod = 1e9 + 7;
long long int power(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res % mod;
}
vector<long long int> arr, ans1, ans;
long long int res = 0, total;
long long int get(long long int x) {
  if (x == arr[x]) return arr[x];
  return get(arr[x]);
}
void merge(long long int a, long long int b, long long int kk[]) {
  long long int t1 = a, t2 = b;
  if (a == b) return;
  a = get(a);
  b = get(b);
  if (a == b) {
    ans.push_back(t2);
    return;
  }
  arr[b] = a;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    long long int kk[n], aa[n];
    arr.resize(n);
    for (long long int i = 0; i < n; i++) arr[i] = i;
    for (long long int i = 0; i < n; i++) {
      cin >> kk[i];
      aa[i] = kk[i];
      merge(kk[i] - 1, i, kk);
    }
    set<long long int> s;
    for (long long int i = 0; i < n; i++) {
      s.insert(get(i));
    }
    for (auto x : ans) s.insert(x);
    set<long long int>::iterator it = s.begin();
    for (auto x : s) {
      if (x != *it) {
        kk[x] = *it + 1;
      }
    }
    for (long long int i = 0; i < n; i++) {
      if (kk[i] != aa[i]) res++;
    }
    cout << res << '\n';
    for (auto x : kk) cout << x << " ";
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
