#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ii=pair<int, int>;
#define vi vector<int>
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
#define f first
#define s second
const ll mod=998244353;
const int inf=1e9;
const int N=2e5+10;
vector<int> g[N];
bool vis[N];

ll pow_fast (ll a,ll b){
  ll ans = 1, x = a;
  while (b!=0){
    if (b&1) ans = ((ans % mod) * x) % mod;
    x = ((x % mod) * x) % mod;
    b>>= 1;
  }
  return ans % mod;
}

void dfs(int u){
    vis[u]=true;
    for(auto v:g[u]){
        if(!vis[v]) dfs(v);
    }
}

int main(){
    fast
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        g[i].push_back(x);
        g[x].push_back(i);
    }
    ll cnt=0;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(i);
            cnt++;
        }
    }
    cout<<pow_fast(2,cnt)-1<<'\n';
    return 0;
}
#include <bits/stdc++.h>

int main() {
	using namespace std;
	ios_base::sync_with_stdio(false), cin.tie(nullptr);

	int N; cin >> N;
	vector<int> F(N); for (auto& f : F) { cin >> f; f--; }

	vector<int> par(N, -1);
	auto get_par = [&](int a) -> int {
		while (par[a] >= 0) {
			if (par[par[a]] >= 0) par[a] = par[par[a]];
			a = par[a];
		}
		return a;
	};
	auto merge = [&](int a, int b) -> bool {
		a = get_par(a), b = get_par(b);
		if (a == b) return false;
		if (par[a] > par[b]) swap(a, b);
		par[a] += par[b];
		par[b] = a;
		return true;
	};

	int num_CC = N;
	for (int i = 0; i < N; i++) {
		num_CC -= merge(i, F[i]);
	}

	const int MOD = 998244353;
	int ans = 1;
	for (int i = 0; i < num_CC; i++) {
		ans = ans * 2 % MOD;
	}
	ans--;
	cout << ans << '\n';

	return 0;
}

// Permutation iff composed of cycles
// There's 1 cycle per connected component of the functional graph
// We just need 2^(# ccs) - 1
