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;
inline int Read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') {
      f = -1;
    }
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
inline void Wte(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) {
    Wte(x / 10);
  }
  putchar(x % 10 + '0');
}
inline void Write(int x) {
  Wte(x);
  putchar(' ');
}
const int MAXN = 200010;
int N;
bool vis[MAXN];
int a[MAXN], ans[MAXN];
bool cmp(int x, int y) { return abs(x - a[x]) < abs(y - a[y]); }
void solve() {
  int cost = 0;
  N = Read();
  for (int i = 0; i < N; i++) {
    a[i] = Read() - 1;
    ans[i] = a[i];
  }
  vector<int> v;
  for (int i = 0; i < N; i++) {
    set<int> st;
    int j;
    for (j = i; !vis[j]; j = a[j]) {
      vis[j] = 1;
      st.insert(j);
    }
    if (!st.count(j)) {
      continue;
    }
    v.push_back(j);
  }
  sort(v.begin(), v.end(), cmp);
  for (int i = 0; i < v.size(); i++) {
    ans[v[i]] = v[0];
  }
  for (int i = 0; i < N; i++) {
    cost += (ans[i] != a[i]);
  }
  Write(cost);
  puts("");
  for (int i = 0; i < N; i++) {
    Write(ans[i] + 1);
  }
  puts("");
}
void Times(int T) {
  while (T--) {
    solve();
  }
}
int main() {
  int T;
  T = 1;
  Times(T);
  return 0;
}
