#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long long ll;
#define G getchar()
int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
#define fi first
#define se second

const int mod=998244353;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,const int &y){x=upd(x+y-mod);}
inline void iadd(int &x,const int &y){x=upd(x-y);}
int qpow(int x,int y){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) res=1LL*res*x%mod;
	return res;
}

//typedef pair<int,int> P;
#define rep(i,l,r) for (int i(l);i<=int(r);i++)
#define per(i,l,r) for (int i(r);i>=int(l);i--)
#define all(x) (x).begin(),(x).end()

int n,p[200010];
int f[200010];
int find(int x){
	return f[x]?f[x]=find(f[x]):x;
}
void merge(int x,int y){
	x=find(x),y=find(y);
	if (x^y) f[y]=x;
}
void solve(){
	n=read();
	rep(i,1,n) p[i]=read(),merge(i,p[i]);
	int tot=0;
	rep(i,1,n) tot+=find(i)==i;
	printf("%d\n",qpow(2,tot)-1);
}
int main()
{
	for (int T=1;T--;) solve();
	return 0;
}
#include<iostream>
#include<cstdio>
#include<queue>
#define ll long long

struct P{
	ll to,next;
}e[400005];

int s = 0,t;

int out[200005],in[200005];

int cnt,head[200005];

int vis[200005];

void add(int a,int b){
	e[++cnt].to = b;
	e[cnt].next = head[a];
	head[a] = cnt;
}

ll n,ans = 1;

bool last[200005];

ll dcnt;

void dfs(ll now){
	if(!vis[now])
	vis[now] = 1;
	else{
		dcnt ++ ;
		return ;
	}
	for(int i = head[now];i;i = e[i].next){
		if(!last[e[i].to] || (e[i].to == now))
		dfs(e[i].to);
		last[now] = 1;
	}
}

ll mod = 998244353;

ll pow(ll now){
	ll ans = 1;
	ll a = 2;
	while(now){
		if(now & 1) ans = ans * a % mod;
		a = a * a % mod;
		now >>= 1;
	}
	return ans;
}

int main(){
	scanf("%lld",&n);
	t = n + 1;
	for(int i = 1;i <= n;++i){
		ll a;
		scanf("%lld",&a);
		add(i,a);
	}
	for(int i = 1;i <= n;++i)
	if(!vis[i])
	dfs(i);
	std::cout<<pow(dcnt) - 1<<std::endl;
}