#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
vector<pair<int, int> > adj[MAXN];
int n;
bool mark[MAXN];
int p[MAXN];
int curv;
void dfs(int v, int ind = -1) {
  mark[v] = 1;
  for (int i = 0; i < adj[v].size(); i++) {
    pair<int, int> u = adj[v][i];
    if (!mark[u.first]) {
      dfs(u.first, u.second);
    } else if (u.second != ind) {
      curv = u.first;
    }
  }
}
int main() {
  cin >> n;
  int x;
  int d = -1;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x == i) {
      d = i;
    }
    p[i] = x;
    adj[i].push_back({x, i});
    adj[x].push_back({i, i});
  }
  int cnt = 0;
  vector<int> ve;
  for (int i = 1; i <= n; i++) {
    if (!mark[i]) {
      dfs(i);
      cnt++;
      ve.push_back(curv);
    }
  }
  if (d != -1) {
    cout << cnt - 1 << '\n';
    for (int i = 0; i < ve.size(); i++) {
      p[ve[i]] = d;
    }
    for (int i = 1; i <= n; i++) {
      cout << p[i] << ' ';
    }
    return 0;
  }
  cout << cnt << '\n';
  for (int i = 0; i < ve.size(); i++) {
    p[ve[i]] = ve[0];
  }
  for (int i = 1; i <= n; i++) {
    cout << p[i] << ' ';
  }
}
