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 N = 1e6 + 7;
const int M = 20;
const int inf = 1e9 + 7;
const long long linf = 1e18 + 7;
const double pi = acos(-1);
const double eps = 1e-7;
const bool multipleTest = false;
int status[N];
int n;
int nxt[N];
set<int> list;
void dfs(int u) {
  if (status[u] == 2) {
    status[u] = 3;
    list.insert(u);
    return;
  }
  status[u] = 2;
  int v = nxt[u];
  dfs(v);
  status[u] = 3;
}
void solve() {
  cin >> n;
  int r = -1;
  for (int i = (1); i < (n + 1); i++) {
    scanf("%d", &nxt[i]);
    if (nxt[i] == i) r = i;
  }
  for (int i = (1); i < (n + 1); i++)
    if (status[i] == 0) dfs(i);
  if (r != -1) {
    cout << list.size() - 1 << "\n";
    for (__typeof((list).begin()) it = (list).begin(); it != (list).end(); it++)
      nxt[*it] = r;
  } else {
    cout << list.size() << "\n";
    r = *list.begin();
    for (__typeof((list).begin()) it = (list).begin(); it != (list).end(); it++)
      nxt[*it] = r;
  }
  for (int i = (1); i < (n + 1); i++) printf("%d ", nxt[i]);
}
int main() {
  int Test = 1;
  if (multipleTest) {
    cin >> Test;
  }
  for (int i = 0; i < Test; ++i) {
    solve();
  }
}
