#include<bits/stdc++.h>

using namespace std;

#define ll long long

const int N = 2e5+10;

int n,f[N],p=998244353,fa[N],ans;

ll quickpow(ll a,ll b)
{
	ll ans = 1;
	while(b){
		if(b&1) ans *= a;
		a *= a;
		ans %= p; a %= p;
		b>>=1; 
	}
	return ans;
}

int find_fa(int x)
{
	if(fa[x] == x) return x;
	else return fa[x] = find_fa(fa[x]);
}

void merge(int x,int y)
{
	int fx=find_fa(x),fy=find_fa(y);
	if(fx != fy){
	 	fa[x] = y; ans--;
	}	
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%lld",&f[i]);
		fa[i] = i;
	}
	ans = n;
	for(int i=1;i<=n;i++){
		merge(i,f[i]);
	}	
	cout<<quickpow(2,ans)-1;
	
	return 0;
}
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	bool flag=1;
	int x=0;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
			flag=0;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return (flag?x:~(x-1));
}
int n,ans=1,fa[200001],sz[200001];
int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)
		fa[i]=i;
	for(int i=1;i<=n;i++)
	{
		int x=read();
		fa[find(i)]=find(x);
	}
	for(int i=1;i<=n;i++)
		sz[(find(i))]++;
	for(int i=1;i<=n;i++)
		if(sz[i])
			ans=(ans<<1)%998244353;
	cout<<(ans+998244352)%998244353;
	return 0;
}
