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 long long INF = long long(1e9 + 7);
const long long MOD = long long(1e9 + 7);
template <typename T, typename U>
inline void AMIN(T &x, U y) {
  if (x > y) x = y;
}
template <typename T, typename U>
inline void AMAX(T &x, U y) {
  if (x < y) x = y;
}
int p[(int)(2e5 + 5)], used[(int)(2e5 + 5)], put[(int)(2e5 + 5)];
vector<int> g[(int)(2e5 + 5)];
vector<int> selfconn, cycleconn;
void dfs(int p, int v) {
  used[v] = 1;
  for (int u : g[v]) {
    if (u == p) continue;
    if (used[u] && put[u]) continue;
    if (used[u]) {
      if (u == v)
        selfconn.push_back(v);
      else
        cycleconn.push_back(v);
      put[v] = 1;
      continue;
    }
    dfs(v, u);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= int(n); i++) {
    int a;
    cin >> a;
    p[i] = a;
    g[i].push_back(a);
    g[a].push_back(i);
  }
  for (int i = 1; i <= int(n); i++) {
    if (!used[i]) dfs(0, i);
  }
  int num = 0, conn;
  if (selfconn.size())
    conn = selfconn.back(), selfconn.pop_back();
  else if (cycleconn.size())
    conn = cycleconn.back(), num++, cycleconn.pop_back();
  num += selfconn.size() + cycleconn.size();
  for (int u : selfconn) p[u] = conn;
  for (int u : cycleconn) p[u] = conn;
  cout << num << endl;
  for (int i = 1; i <= int(n); i++) cout << p[i] << " ";
  cout << endl;
  return 0;
}
