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 = 200005;
int n, ans, a[N], size[N], dfn[N], low[N], s[N], top, dep, cnt, c[N];
bool used[N], vis[N], wzp[N], flag;
struct info {
  int to, nxt;
} e[N << 1];
int head[N], opt;
void add(int x, int y) {
  e[++opt] = (info){y, head[x]};
  head[x] = opt;
}
void tarjan(int u) {
  dfn[u] = low[u] = ++dep;
  used[u] = 1;
  s[++top] = u;
  for (int i = head[u]; i; i = e[i].nxt) {
    int k = e[i].to;
    if (!dfn[k])
      tarjan(k), low[u] = min(low[k], low[k]);
    else if (used[k])
      low[u] = min(low[u], dfn[k]);
  }
  if (low[u] == dfn[u]) {
    used[u] = 0;
    size[++cnt] = 1;
    c[u] = cnt;
    while (s[top] != u) {
      size[cnt]++;
      used[s[top]] = 0;
      c[s[top--]] = cnt;
    }
    top--;
  }
}
int main() {
  int rt = -1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] != i)
      add(a[i], i);
    else
      rt = i, flag = 1;
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i);
  for (int i = 1; i <= n; i++) {
    if (size[c[i]] > 1 && !vis[c[i]]) {
      vis[c[i]] = 1;
      wzp[i] = 1;
      if (rt == -1) rt = i;
    }
    if (i == a[i]) wzp[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (wzp[i] && a[i] != rt) ans++;
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    if (wzp[i])
      printf("%d ", rt);
    else
      printf("%d ", a[i]);
  }
  return 0;
}
