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<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset> 
#include<unordered_map> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include "boost/algorithm/string.hpp"
// RAJJI KI MEHER 
#define fio ios_base::sync_with_stdio(false)
//#define mod 1000000007
#define mod1 mod
#define mod2 100000009
#define li long long int
#define ll int
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%lld",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 100000000000000005
#define MINN -10000000000000000
#define INTMAX 1000001000
#define pii pair<li,li>
#define pdd pair<double,double>
#define pic pair<int,char>
//#define N 5005
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20
using namespace std;li a[200005];li p[200005];li n;
li sp(li i){if(a[i]==i) return(i);
else{return(a[i]=sp(a[i]));}}
void unite(li i,li j){i=sp(i);j=sp(j);
    a[i]=j;//t=t+r[j]*r[i];r[j]=r[j]+r[i];
    }

int main(){li i,j,x,y,ans=0,r=0,c=0;readl(n);vector<li>v;for(i=1;i<=n;i++){a[i]=i;}
for(i=1;i<=n;i++){readl(p[i]);x=sp(i);y=sp(p[i]);
if(x!=y){unite(x,y);}
else if(i==p[i]){r=i;c++;v.pb(i);}
else{c++;v.pb(i);}
}
if(r>0){for(i=0;i<c;i++){p[v[i]]=r;}cout<<(c-1)<<endl;
for(i=1;i<=n;i++) printf("%lld ",p[i]);
}
else{if(c>0) r=v[0];cout<<r<<" ";
for(i=0;i<c;i++){p[v[i]]=r;}cout<<(c)<<endl;
for(i=1;i<=n;i++) printf("%lld ",p[i]);
}
}