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 = 1 << 28;
const long long LINF = 1ll << 61;
inline long long getnum() {
  register long long r = 0;
  register bool ng = 0;
  register char c;
  c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') ng = 1, c = getchar();
  while (c != ' ' && c != '\n') r = r * 10 + c - '0', c = getchar();
  if (ng) r = -r;
  return r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline void putsp() { putchar(' '); }
inline void putendl() { putchar('\n'); }
inline char mygetchar() {
  register char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
int n;
int head[200111], nxt[400111], to[400111], tot = 1;
bool vis[200111];
int p[200111];
int X, Y;
void dfs(int x, int pre) {
  vis[x] = 1;
  for (int i = head[x]; i; i = nxt[i]) {
    if (!vis[to[i]]) {
      dfs(to[i], i / 2);
    } else if (i / 2 != pre) {
      X = x;
      Y = to[i];
    }
  }
}
int main() {
  n = getnum();
  int ans = 0, fb = 0;
  for (int i = 1; i <= n; i++) {
    p[i] = getnum();
    nxt[++tot] = head[i];
    head[i] = tot;
    to[tot] = p[i];
    nxt[++tot] = head[p[i]];
    head[p[i]] = tot;
    to[tot] = i;
    if (i == p[i]) fb = i;
  }
  if (fb) dfs(fb, -1);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      X = Y = -1;
      dfs(i, -1);
      if (p[Y] == X) swap(X, Y);
      if (!fb) {
        ans++;
        p[X] = X, fb = X;
      } else {
        ans++;
        p[X] = fb;
      }
    }
  }
  putnum(ans), putendl();
  for (int i = 1; i <= n; i++) putnum(p[i]), putsp();
  return 0;
}
