3
2 1 1
 6
6 2 6 2 4 2
 2
1 2
 8
2 1 2 2 6 5 6 6
 18
2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18
 7
1 2 3 4 5 6 7
 7
4 3 2 6 3 5 2
 7
7 5 3 1 2 1 5
 7
1 6 4 4 5 6 7

1
2 2 1  0
6 2 6 2 4 2  1 
1 1 
 2 
2 2 2 2 6 2 6 6 
 5 
2 3 4 5 11 7 8 9 10 11 11 11 14 15 11 17 18 11 
 6 
1 1 1 1 1 1 1 
 1
4 3 3 6 3 5 2  1
7 5 3 1 3 1 5  4 
1 6 4 1 1 1 1 

#include <bits/stdc++.h>
using namespace std;
long long n = 2 * 1e5 + 1;
long long root = 0;
vector<vector<long long>> adj(n);
vector<long long> c, vi(n);
vector<bool> visited(n);
void dfs(long long s, long long anc) {
  if (visited[s]) return;
  visited[s] = true;
  for (auto u : adj[s]) {
    if (visited[u] == true && u != anc && u != s && vi[s] == 0) {
      c.push_back(u);
      vi[u] = 1;
    }
    dfs(u, s);
  }
}
int main() {
  long long m;
  cin >> m;
  long long res = -1;
  vector<long long> a(m);
  for (long long i = 0; i < m; i++) {
    cin >> a[i];
    adj[a[i]].push_back(i + 1);
    adj[i + 1].push_back(a[i]);
    if (a[i] == i + 1 && root == 0) root = a[i];
  }
  for (long long i = 1; i < m + 1; i++) {
    if (visited[i] == false) {
      dfs(i, a[i - 1]);
      res++;
    }
  }
  if (res == 0 && root == 0) {
    res++;
    a[c[0] - 1] = c[0];
  } else if (res > 0 && root == 0) {
    res++;
    root = c[0];
    for (long long i = 0; i < c.size(); i++) a[c[i] - 1] = root;
  } else if (res > 0 && root > 0) {
    for (long long i = 0; i < m; i++) {
      if (a[i] == i + 1 && a[i] != root) a[i] = root;
    }
    for (long long i = 0; i < c.size(); i++) a[c[i] - 1] = root;
  }
  cout << res << endl;
  for (auto i = a.begin(); i != a.end(); i++) {
    cout << *i << " ";
  }
  cout << "\n";
  ;
  return 0;
}
