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>
#include <queue>
#include <stack>
using namespace std; 


typedef pair<long long int,long long int> pa;
#define resize(A) A.resize(unique(A.begin(), A.end()) - A.begin())
#define pb push_back
#define  MAX 200005

long long int MOD=1e9+9;
long long int INF=1e18;
long long int jj;

long long int A[MAX];

long long  int modulo(long long int a,long long  int b,long long  int n)
{
    long long int  x=1, y=a; 
    y=y%n;
    
    while (b > 0) {
        if (b%2 == 1) {
            x = (x*y) % n;  // multiplying with base
        }
        y = (y*y) % n;     // squaring the base
        b /= 2;
    }
    return x % n;
}
void dfs(vector<long long int>adj[],long long int i,bool visited[],long long int parent[])
{
   
    visited[i]=true;
    for(auto j:adj[i])
    {
        if(visited[j]==false)
        {
            parent[j]=i;
            dfs(adj,j,visited,parent);
            
        }
        else if(parent[i]!=j)
        {
          
            jj=j;
        }
    }
}



 
int main()
{
         ios_base::sync_with_stdio(false); 
         cin.tie(NULL);
         cout.tie(NULL);
         long long int i,j,k=0,l=0,r=0,m=0,n,c,p=0,cnt=0,cnt1=0,x,y,z=0,a,b,low,mid,high,ans=0,maxi=0,mini=INF,t,x1,y1;
         string s,s1;
         cin>>n;
       
    vector<long long int>adj[n+1];
    bool visited[n+1]={0};
    long long int parent[n+1];
    for(i=0;i<=n;i++)
    {
        visited[i]=false;
        parent[i]=i;
    }
      for(i=0;i<n;i++)
    {
        cin>>x;
        adj[i+1].pb(x);
        adj[x].pb(i+1);
        A[i+1]=x;
    }
    
    
     x=-1;
    
    for(i=1;i<=n;i++)
    {
        if(A[i]==i && visited[i]==false)
        {
          
            dfs(adj,i,visited,parent);
            if(x==-1)
            {
                x=i;
            }
            else
            {
                A[i]=x;    
                cnt++;
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        if(visited[i]==false)
        {
          
            
            dfs(adj,i,visited,parent);
            
            if(x!=-1)
                A[jj]=x;
                else
                    A[jj]=jj;
           
            
            cnt++;
        }
    }
        cout<<cnt<<endl;
    for(i=1;i<=n;i++)
        cout<<A[i]<<" ";
    
  
}