#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;
vector<long long> par;
long long root(long long x) {
	//xの属する木の根を求める
	if(par[x] == x) return x;
	else return par[x] = root(par[x]);
}
int same(long long x, long long y) {
	if(root(x) == root(y)) return 1;
	else return 0;
}
void unite(long long x, long long y) {
	x = root(x);
	y = root(y);
	if(x == y) return;
	par[x] = y;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(void){
	long long n,i,x,ans=0;
	vector<long long> f;
	vector<bool> visited;
	cin >> n;
	par.resize(n+1);
	for(i=1;i<=n;i++) par[i]=i;
	//f.resize(n+1);
	//visited.resize(n+1);
	for(i=1;i<=n;i++) {
		cin >> x;
		unite(i,x);
	}
	for(i=1;i<=n;i++) {
		if(root(i) == i) ans++;
	}
	cout << modpow(2,ans,998244353)-1 << '\n';
}

#include<cstdio>
#include<algorithm>
#include<cstring>

#define ll long long
#define fo(i,x,y) for(i=x;i<=y;i++)

using namespace std;
const ll mod=998244353;
const int N=2e5+10;
ll n,m,i,j,k,tot,ans,s,t,x,y,z;
ll a[N];
ll d[N];

bool bz[N];

ll ksm(ll i,ll j) {
	ll re=1;
	while (j>0) {
		if (j&1) re=re*i%mod;
		j/=2; i=i*i%mod;
	}
	return re;
}

void dg(int i) {
	d[a[i]]--; 
	bz[i]=true;
	if (d[a[i]]==0) dg(a[i]);
}

void dg2(int i) {
	bz[i]=true;
	if (!bz[a[i]]) dg2(a[i]);
}

int main() {
	scanf("%lld",&n);
	fo(i,1,n) {
		scanf("%lld",&a[i]);
		d[a[i]]++;
	}
	
	fo(i,1,n) 
		if (!bz[i]&&d[i]==0) dg(i);
		
	t=0;
	fo(i,1,n) 
		if (!bz[i]) {dg2(i); t++;}
		
	ans=(ksm(2,t)+mod-1)%mod;
	
	printf("%lld\n",ans);
}