#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n;
int father[maxn];
int num[maxn];
bool vis[maxn];
int find(int n) {
  if (n == father[n])
    return n;
  else if (vis[n])
    return father[n];
  else {
    vis[n] = true;
    father[n] = find(father[n]);
    return father[n];
  }
}
int main() {
  int n;
  cin >> n;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &num[i]);
    father[i] = num[i];
  }
  for (int i = 1; i <= n; ++i) {
    find(num[i]);
  }
  bool flag = true;
  int ans = 0;
  int sel1, sel2;
  for (int i = 1; i <= n; ++i) {
    if (father[i] == i && num[i] != i) {
      ans++;
      if (flag) {
        sel2 = i;
      }
    } else if (father[i] == i) {
      ans++;
      sel1 = i;
      flag = false;
    }
  }
  int sel;
  if (!flag) {
    sel = sel1;
    ans--;
  } else
    sel = sel2;
  cout << ans << endl;
  for (int i = 1; i <= n; ++i) {
    if (father[i] == i)
      printf("%d ", sel);
    else
      printf("%d ", num[i]);
  }
  cout << endl;
  return 0;
}
