#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
vector<vector<int> > graph;
int especial = -1;
void dfs(int atual, vector<int> &usados, int color) {
  usados[atual] = color;
  for (int v : graph[atual])
    if (usados[v] == 0)
      dfs(v, usados, color);
    else if (usados[v] == color)
      especial = v;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  int n;
  cin >> n;
  graph.resize(n);
  vector<int> v(n);
  vector<int> ind(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    v[i]--;
  }
  for (int i = 0; i < n; i++)
    if (i != v[i]) {
      graph[v[i]].push_back(i);
      ind[i]++;
    }
  vector<int> root;
  vector<int> cicle;
  vector<int> usados(n, 0);
  for (int i = 0; i < n; i++) {
    if (ind[i] == 0) {
      dfs(i, usados, 1);
      root.push_back(i);
    }
  }
  int color = 2;
  for (int i = 0; i < n; i++)
    if (usados[i] == 0 and graph[i].size() > 0 and ind[i] > 0) {
      dfs(i, usados, color++);
      if (especial != -1) cicle.push_back(especial);
      especial = -1;
    }
  if (root.size() == 0) {
    cout << cicle.size() << "\n";
    v[cicle[0]] = cicle[0];
    for (int i = 1; i < cicle.size(); i++) v[cicle[i]] = cicle[0];
    for (int X = 0; X < v.size(); X++) cout << v[X] + 1 << " ";
    cout << "\n";
    ;
  } else {
    cout << root.size() - 1 + cicle.size() << "\n";
    for (int i = 1; i < root.size(); i++) v[root[i]] = root[0];
    for (int i = 0; i < cicle.size(); i++) v[cicle[i]] = root[0];
    for (int X = 0; X < v.size(); X++) cout << v[X] + 1 << " ";
    cout << "\n";
    ;
  }
  return 0;
}
