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 

//#pragma GCC optimize("trapv")
#pragma GCC optimize("O2")
//#pragma GCC target("avx,avx2,sse,sse2,tune=native,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pi>;
const int maxn = 2e5 + 30;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
int n, a[maxn];
vector<vi> g;
bitset<maxn> vis;
int ans = 0;
int r = -1;
void dfs(int v, int p) {
	vis[v] = 1;
	for(auto i : g[v])
		if(!vis[i])
		dfs(i, v);
		else if(v!=p)
		a[i] = r, ans++;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	g.resize(n+1);
	for(int t, i = 1; i <= n; i++){
		cin >> a[i];
		if(a[i]==i) r = i;
	}
	if(r==-1) {
		ans++;
		a[1] = r = 1;
	}
	for(int i = 1; i <= n; i++){
		if(i==r) continue;
		if(a[i]==i) a[i] = r, ans++;
		g[a[i]].pb(i);
	}
	dfs(r, -6969);
	for(int i = 1; i <= n; i++)
		if(!vis[i]) {
			dfs(i, -6969), ans++;
		}
	cout << ans << "\n";
	for(int i = 1; i <= n; i++) cout << a[i] << " ";

}
