#include <bits/stdc++.h>
using namespace std;
int n, vis1[200007], a[200007], vis[200007], k, r, f, i1 = -1;
vector<int> v[200007], ans;
void DFS(int x) {
  cout << x << " ";
  vis[x] = 1e7;
  for (int i = 0; i < v[x].size(); i++) {
    if (!vis[v[x][i]]) DFS(v[x][i]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    v[i].push_back(a[i]);
    v[a[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    int x = i;
    while (!vis1[x]) {
      vis1[x] = i;
      x = a[x];
    }
    if (i != vis1[x]) continue;
    k++;
    ans.push_back(x);
  }
  for (int i = 0; i < ans.size(); i++) {
    if (a[ans[i]] == ans[i]) {
      i1 = i;
      break;
    }
  }
  if (i1 == -1) {
    a[ans[0]] = ans[0];
    i1 = 0;
    k++;
  }
  for (int i = 0; i < ans.size(); i++) {
    if (i == i1) continue;
    a[ans[i]] = ans[i1];
  }
  cout << k - 1 << endl;
  for (int i = 1; i <= n; i++) cout << a[i] << " ";
}
