#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const int N = 2e5 + 5;
int n, a[N], root, ans, vis[N], x, cnt = 1;
vector<int> v[N];
void dfs(int x) {
  vis[x] = cnt;
  for (int i = 0; i < v[x].size(); i++) {
    if (!vis[v[x][i]])
      dfs(v[x][i]);
    else if (vis[v[x][i]] == cnt) {
      if (!root) root = v[x][i];
      a[v[x][i]] = root, ans++;
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++)
    if (a[i] == i) root = i;
  if (root) ans--;
  for (int i = 1; i <= n and root; i++)
    if (a[i] == i) a[i] = root, ans++;
  for (int i = 1; i <= n; i++)
    if (i != a[i]) v[i].push_back(a[i]);
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i), cnt++;
  cout << ans << "\n";
  for (int i = 1; i <= n; i++) cout << a[i] << " ";
  return 0;
}
