#include <bits/stdc++.h>
using namespace std;
bool v[100];
int n, m, ans, p, f[200010], a[200010], d[200010];
double pp(int x, int y, double z) {
  double Ans = 0.0, k, o;
  if (x == k) return 0;
  for (int i = 1; i <= n; i++)
    if (!v[i] && i != o)
      v[i] = true, Ans += (a[i] / z) * pp(x + 1, i, z - a[i]), v[i] = false;
  return Ans;
}
void dfs(int x) {
  a[x] = p;
  if (f[x] == x) {
    if (f[x] != n) f[x] = n, ans++;
    return;
  }
  if (!a[f[x]])
    dfs(f[x]);
  else if (a[f[x]] == a[x])
    f[x] = (n == 0 ? n = x : n), ans++;
}
int main() {
  cin >> m;
  for (int i = 1; i <= m; i++) scanf("%d", &f[i]), n = (i == f[i] ? i : n);
  ans = 0;
  for (int i = 1; i <= m; i++)
    if (!a[i]) p++, dfs(i);
  cout << ans << endl;
  for (int i = 1; i < m; i++) printf("%d ", f[i]);
  printf("%d\n", f[m]);
  return 0;
}
