#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
int vis[200100], r[200100], rs = 0;
void dfs(int u, int p) {
  vis[u] = 1;
  for (int j = 0; j < (int)g[u].size(); j++) {
    int v = g[u][j];
    if (vis[v] == 0) {
      dfs(v, u);
    } else if (vis[v] == 1 && v != p) {
      r[u] = -1;
    }
  }
  vis[u] = 2;
}
int main(int argc, char const* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, a[200100], sol = 0, root = -1;
  cin >> n;
  g.assign(n + 1, vector<int>());
  memset(a, 0, sizeof a);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (i == a[i]) {
      r[i] = -2;
      continue;
    } else if (i == a[a[i]]) {
      r[i] = -1;
      continue;
    } else
      r[i] = a[i];
    g[i].push_back(a[i]);
    g[a[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    if (vis[i] == 0) {
      dfs(i, -1);
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (r[i] == -2 && root == -1) {
      root = i;
      r[i] = i;
    } else if (r[i] == -2) {
      r[i] = root;
      ++sol;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (r[i] == -1 && root == -1) {
      root = i;
      ++sol;
      r[i] = i;
    } else if (r[i] == -1) {
      r[i] = root;
      ++sol;
    }
  }
  cout << sol << "\n";
  for (int i = 1; i <= n; ++i) {
    cout << r[i] << ' ';
  }
  cout << endl;
  return 0;
}
