#include<bits/stdc++.h>
#define int long long
using namespace std;
int const MOD=998244353,N=233333;
int n,f[N],vis[N],cnt;
inline int find(int x){
	return x==f[x]?x:f[x]=find(f[x]);
}
inline int qpow(int x,int y){
	return !y?1:qpow(x,y-1)*x%MOD;
}
signed main(){
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++)f[i]=i;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		int fx=find(x),fy=find(i);
		if(fx!=fy)f[fx]=fy;
	}
	for(int i=1;i<=n;i++)vis[find(i)]=1;
	for(int i=1;i<=n;i++)cnt+=vis[i]; 
	cout<<((qpow(2,cnt)+MOD-1)%MOD);
} 
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
const int mod = 998244353;
int n, a[N], vis[N];
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> a[i];
    int ans = 1;
    for(int i = 1;i <= n;i++) {
        int x = i;
        while(vis[x] == 0)
            vis[x] = 1, x = a[x];
        if(vis[x] == 1)
            ans = (ans + ans) % mod;
        x = i;
        while(vis[x] == 1)
            vis[x] = 2, x = a[x];
    }
    ans = (ans + mod - 1) % mod;
    cout << ans;
    return 0;
}