#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
	char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
	in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
	in int read()
	{
		int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
		x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
	}
	in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
	in int gs(char *s) {char c,*t=s;while(c=gc(),c<=32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
	in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
	in void flush() {if(C>1<<22) ot();}
	template <typename T>
	in void write(T x,char t)
	{
		int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
		if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
	}
	in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
#define pb push_back
const int N=1e6+5,p=998244353;
int n,m,ans=1,L,R,siz[N],a[N],vis[N],q[N],inq[N];vector<int>e[N];in void add(int u,int v) {e[u].pb(v),e[v].pb(u);}
in void M(int &x) {x-=p;x+=x>>31&p;}
void dfs1(int u,int fa)
{
	vis[u]=1;
	for(int v:e[u]) if(!vis[v]) dfs1(v,u);
	else !inq[v]?L=u,R=v,inq[u]=inq[v]=1:inq[u]=1;
}
void get(int u,int fa) {siz[u]=1;for(int v:e[u])if(v^fa&&!inq[v])get(v,u),siz[u]+=siz[v];}
void dfs2(int u,int fa)
{
	for(int v:e[u]) if(v^fa&&inq[v]&&(u^L||(u==R&&v^L))) dfs2(v,u);
	get(u,0);m=1ll*m*siz[u]%p;
}
int main()
{
	n=read();for(int i=1;i<=n;i++) a[i]=read(),add(i,a[i]);
	for(int i=1;i<=n;i++) if(!vis[i]) m=1,dfs1(i,0),dfs2(L,R),ans=1ll*ans*(m+1)%p;
	write((ans+p-1)%p,'\n');
	return ot(),0;
}
//Author: disangan233
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <sstream>
#include <ostream>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <iomanip>
#include <set>
#include <bitset>
#include<unordered_map>
#define INT_MINs -2000000000
#define INT_MAXs 1000000001
#define MID int mid=(l+r)/2
#define REP1(i,x,y) for(int i=x;i<y;i++)
#define REP2(i,x,y) for(int i=x;i<=y;i++)
#define ls (2*k)
#define rs (2*k+1)
#define lson l,mid,2*k
#define rson mid+1,r,2*k+1
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define IOS ios::sync_with_stdio(0);cin.tie(NULL);
#define pb(a) push_back(a)
#define pi acos(-1)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=998244353;
const ll ba=131;
ll qk(ll x,ll y){ll ans=1;while(y){if(y&1) ans=ans*x%mod;y>>=1;x=x*x%mod;}return ans;}
const int dx[8] = { 0,-1,0,1,-1,-1,1,1}, dy[8] = { -1,0,1,0,-1,1,-1,1};
const int dxx[8]= {2,1,-1,-2,-2,-1, 1, 2},dyy[8]= {1,2,2,1, -1,-2,-2,-1};
int a[200005];
ll ans=0;
int vis[200005];
int f[200005];
int finds(int x){
    return f[x]==x?f[x]:f[x]=finds(f[x]);
}
void solve()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        f[i]=i;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        vis[a[i]]=1;
    }
    for(int i=1;i<=n;i++){
        //if(vis[i]) continue;
        f[finds(i)]=finds(finds(a[i]));
    }
    for(int i=1;i<=n;i++){
        if(vis[i]&&f[i]==i)
            ans++;
    }
    cout<<qk(1ll*2,ans)-1<<endl;
}

int main()
{
    //IOS;
    solve();
    return 0;
}
