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>
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
using namespace std;
const int maxn = (int)2e5 + 13;
const long long INFL = 9223372036854775807;
const int INF = 2147483646;
const long long MOD = (int)1e9 + 21;
const long long base = 257;
vector<int> gr[maxn];
bool vis[maxn];
void dfs(int v, vector<int> &c, int &r, int p = -1) {
  vis[v] = 1;
  c.push_back(v);
  for (auto t : gr[v]) {
    if (!vis[t] && t != p) {
      dfs(t, c, r, v);
    } else if (t != p) {
      r = t;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n + 1);
  vector<int> roots;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
    if (i != p[i])
      gr[i].push_back(p[i]), gr[p[i]].push_back(i);
    else
      roots.push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      vector<int> v;
      int r = -1;
      dfs(i, v, r);
      if (r != -1 && roots.size() != 0)
        p[r] = roots[0], ans++;
      else if (r != -1 && roots.size() == 0)
        p[r] = r, ans++, roots.push_back(r);
    }
  }
  for (int i = 1; i < roots.size(); ++i) {
    p[roots[i]] = roots[0];
    ans++;
  }
  cout << ans << "\n";
  for (int i = 1; i <= n; ++i) cout << p[i] << " ";
  return 0;
}
