#include <bits/stdc++.h>
using namespace std;
#define ll long long

const ll mod = 998244353;

long long modpow(long long a, long long x) {
    long long tmp = x;
    long long val = a;
    long long ret = 1LL;
    while (tmp>0) {
        if (tmp%2 == 1) ret = ret*val%mod;
        val = val*val%mod;
        tmp /= 2;
    }
    return ret;
}

int N;
vector<int> f;
ll cycles = 0;
map<int, int> mp;
ll cnt = 0;

void dfs(int idx) {
	if (mp.count(idx) > 0) {
		if (mp[idx] != cnt) return;
		cycles++;
	} else {
		mp[idx] = cnt;
		dfs(f[idx]-1);
	}
	return;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> N;
	f = vector<int>(N);
	for (int i=0;i<N;i++) cin >> f[i];

	for (int i=0;i<N;i++) {
		cnt++;
		dfs(i);
	}

	cout << modpow(2LL, cycles)-1 << "\n";
	return 0;
}
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn=2e5+5;
const ll mod=998244353;
int f[maxn],sz[maxn];
int find(int x)
{
    return f[x]==x?x:f[x]=find(f[x]);
}
bool merge(int u,int v)
{
    int u_=find(u),v_=find(v);
    if(u_==v_) return false;
    if(sz[u_]>sz[v_]) swap(u_,v_);
    sz[v_]+=sz[u_]; f[u_]=v_;
    return true;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        f[i]=i;
        sz[i]=1;
    }
    int times=n;
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        times-=merge(x,i);
    }
    ll ans=1;
    for(int i=1;i<=times;i++)
        ans=ans*2%mod;
    ans-=1; ans+=(ans<0)*mod;
    printf("%lld\n",ans);
    return 0;
}
/*
2
2 1
 
2
1 1

3
1 2 3
 */
