#include <cstdio>
#include <cstring>
#define mo 998244353
#define N 200010

using namespace std;

int f[N], jl, n;
bool bz1[N], bz2[N];

void dfs(int x){
	bz2[x]=1;
	if (!bz2[f[x]]) dfs(f[x]);
	else if (!bz1[f[x]]) jl++;
	bz1[x]=1;
}

int ksm(int x, int y){
	int ans=1;
	while (y){
		if (y&1) ans=1ll*ans*x%mo;
		x=1ll*x*x%mo;
		y>>=1;
	}
	return ans;
}

int main(){
//	freopen("funny.in", "r", stdin);
	scanf("%d", &n);
	for (int i=1; i<=n; i++) scanf("%d", &f[i]);
	for (int i=1; i<=n; i++){
		if (!bz2[i]) dfs(i);
	}
	printf("%d\n", ksm(2, jl)-1);
	
	return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int MAXX = 2e5 + 10, MOD = 998244353;
long long n, tmp, ans = 1;
vector <int> adj[MAXX];
bool vis[MAXX];

void dfs(int v) {
	vis[v] = 1;
	for(auto x : adj[v])
		if(!vis[x])
			dfs(x);
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> tmp;
		adj[i].push_back(tmp), adj[tmp].push_back(i);
	}
	for(int i = 1; i <= n; i++)
		if(!vis[i])
			dfs(i), ans = (ans * 2) % MOD;
	return cout << (((ans - 1) % MOD) + MOD) % MOD << endl, 0;
}
