#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200003];
int visit[200003];
const int mod = 1000000007;
long long mod_mult(long long a, long long b) {
  return ((a % mod) * (b % mod)) % mod;
}
long long mult(long long x, long long y) {
  long long prod = 1;
  while (y > 0) {
    if (y & 1) prod = mod_mult(prod, x);
    x = mod_mult(x, x);
    y /= 2;
  }
  return prod;
}
vector<int> parr;
vector<int> ind;
void dfs(int cur) {
  if (visit[cur]) return;
  visit[cur] = 1;
  for (auto it : adj[cur]) {
    if (visit[it] == 1)
      ind.push_back(it);
    else
      dfs(it);
  }
  visit[cur] = 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, i, t, a, m;
  cin >> n;
  int parr[200005];
  for (long long i = 0; i < n; i += 1)
    cin >> a, adj[a].push_back(i + 1), parr[i + 1] = a;
  for (long long j = 1; j <= n; j += 1) {
    if (parr[j] == j) dfs(j), ind.push_back(j);
  }
  for (long long j = 1; j <= n; j += 1) {
    if (!visit[j]) {
      dfs(j);
    }
  }
  int c = 0;
  for (int i = 0; i < ind.size(); i++) {
    if (parr[ind[i]] != ind[0]) parr[ind[i]] = ind[0], c++;
  }
  cout << c << endl;
  for (int i = 1; i <= n; i++) cout << parr[i] << " ";
  return 0;
}
