#include <bits/stdc++.h>
using namespace std;
vector<int> cc, fuck;
vector<bool> flag(200005);
bool dfs_num[200005];
int a[200005], cycle[200005];
int cnt = 0;
void dfs(int u) {
  dfs_num[u] = 1;
  flag[u] = 1;
  int v = a[u];
  if (flag[v] == 1 && a[v] != v) {
    cycle[u] = 1;
    ++cnt;
  } else if (dfs_num[v] == 0)
    dfs(v);
  flag[u] = 0;
}
int main() {
  int n, own = 0, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == i) {
      fuck.push_back(i);
      ++own;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] != i && dfs_num[i] == 0)
      dfs(i);
    else if (a[i] == i && dfs_num[i] == 0) {
      dfs_num[i] = 1;
    }
  }
  if (!own)
    own = 1;
  else if (!own && !cnt)
    own = 2;
  ans = cnt + own;
  --ans;
  cout << ans << endl;
  if (fuck.size() == 0) {
    for (int i = 1; i <= n; i++) {
      if (cycle[i] == 1) {
        fuck.push_back(i);
        break;
      } else if (!cnt) {
        fuck.push_back(i);
        break;
      }
    }
  }
  if (!own && !cnt) {
    for (int i = 1; i <= n; i++) {
      if (fuck[0] == i)
        cout << i << " ";
      else
        cout << a[i] << " ";
    }
  }
  for (int i = 1; i <= n; i++) {
    if (cycle[i] != 1 && a[i] != i)
      cout << a[i] << " ";
    else if (a[i] == i || cycle[i] == 1)
      cout << fuck[0] << " ";
  }
}
