#include <bits/stdc++.h>
using namespace std;
int par[200005], vis[200005], tree[200005];
set<pair<int, int> > par_change;
void dfs(int u, vector<int> next[], int dfs_par) {
  vis[u] = 1;
  if (par[u] == u) {
    par_change.insert({1, u});
  }
  for (int i = 0; i < next[u].size(); ++i) {
    int v = next[u][i];
    if (!vis[v]) {
      dfs(v, next, u);
    } else if (v != dfs_par) {
      if (par[u] == v) {
        par_change.insert({2, u});
      } else {
        par_change.insert({2, v});
      }
    }
  }
  vis[u] = 2;
}
int main() {
  int n, cnt = 0;
  scanf("%d", &n);
  vector<int> next[n + 5];
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &par[i]);
    tree[i] = par[i];
    if (i != par[i]) {
      next[i].push_back(par[i]);
      next[par[i]].push_back(i);
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      dfs(i, next, 0);
    }
  }
  int flag = 0;
  tree[par_change.begin()->second] = par_change.begin()->second;
  auto it1 = par_change.begin(), it2 = ++it1;
  it1 = par_change.begin();
  for (; it2 != par_change.end(); ++it2, ++it1) {
    tree[it2->second] = it1->second;
  }
  for (int i = 1; i <= n; ++i) {
    if (tree[i] != par[i]) {
      ++cnt;
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= n; ++i) {
    printf("%d ", tree[i]);
  }
  return 0;
}
