#include<bits/stdc++.h>

using namespace std;

#define rg register
#define In inline
#define ll long long

const int N = 2e5;
const ll mod = 998244353;

namespace IO{
	In ll read(){
		ll s = 0,ww = 1;
		char ch = getchar();
		while(ch < '0' || ch > '9'){if(ch == '-')ww = -1;ch = getchar();}
		while('0' <= ch && ch <= '9'){s = 10 * s + ch - '0';ch = getchar();}
		return s * ww;
	}
	In void write(ll x){
		if(x < 0)putchar('-'),x = -x;
		if(x > 9)write(x / 10);
		putchar('0' + x % 10);
	}
};
using namespace IO;

namespace ModCalc{
	In void Inc(ll &x,ll y){
		x += y;if(x >= mod)x -= mod;
	}
	In void Dec(ll &x,ll y){
		x -= y;if(x < 0)x += mod;
	}
	In ll Add(ll x,ll y){
		Inc(x,y);return x;
	}
	In ll Sub(ll x,ll y){
		Dec(x,y);return x;
	}
};
using namespace ModCalc;

int n;
bool vis[N+5];
vector<int> vc;
vector<int> E[N+5];//i[N+5],Eo[N+5];
queue<int> Q;

In ll power(ll a,ll n){
	ll s = 1,x = a;
	while(n){
		if(n & 1) s = s * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return s;
}
void bfs(int s){
	Q.push(s);vis[s] = 1;
//	vc.resize(0);
	while(!Q.empty()){
		int u = Q.front();
		Q.pop();vc.push_back(u);
		for(auto v : E[u]){
			if(vis[v])continue;
			vis[v] = 1;
			Q.push(v);
		}
	}
/*	int d = vc.size(),en = 0;
	for(auto u : vc)en += E[u].size();
	en >>= 1;
cout<<"d="<<d<<" en="<<en<<endl;
	if(en == d)return 2;else return power(2,d);*/
}

int main(){
//	freopen("B.in","r",stdin);
//	freopen("B.out","w",stdout);
	n = read();
	for(rg int i = 1;i <= n;i++){
		int f = read();
		if(f == i)continue;
		else E[i].push_back(f),E[f].push_back(i);
	}
	ll ans = 1;
	for(rg int i = 1;i <= n;i++)if(!vis[i])bfs(i),ans = ans * 2 % mod;
	write(Sub(ans,1)),putchar('\n');
	return 0;
}
#line 1 "a.cpp"
#include<iostream>
using namespace std;
#line 1 "/home/kotatsugame/library/datastructure/UF.cpp"
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
#line 4 "a.cpp"
const long mod=998244353;
int N,P[2<<17];
main()
{
	cin>>N;
	UF uf(N);
	int cnt=N;
	for(int i=0;i<N;i++)
	{
		cin>>P[i];
		P[i]--;
		cnt-=uf.unite(i,P[i]);
	}
	long ans=1;
	for(;cnt--;)ans=ans*2%mod;
	cout<<(ans+mod-1)%mod<<endl;
}
