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;
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] << ' ';
  }
}
