#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

vector<int> sz;
vector<int> parent;
void make_set(int v) {
	parent[v] = v;
	sz[v] = 1;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	else
	{
		auto par = find_set(parent[v]);
		parent[v] = par;
		return par;
	}
}

void merge(int a, int b) {
	find_set(a);
	find_set(b);

	a = find_set(a);
	b = find_set(b);

	if (a != b) {
		if (sz[a] < sz[b])
			swap(a, b);
		parent[b] = a;
		sz[a] += sz[b];
	};
}

int const MOD = 998244353;

int mul(int a, int b) {
	return (a * 1LL * b) % MOD;
}

int add(int a, int b) {
	int s = (a + b);
	if (s >= MOD) s -= MOD;
	return s;
}

int sub(int a, int b) {
	int s = (a + MOD - b);
	if (s >= MOD) s -= MOD;
	return s;
}

ll fast_exp(ll base, ll exp) {
	ll res = 1;
	while (exp > 0) {
		if (exp & 1)
			res = (res * base) % MOD;
		base = (base * base) % MOD;
		exp >>= 1;
	}
	return res;
}

int main() {
	/*freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);*/
	int n;
	cin >> n;
	parent.resize(n);
	sz.resize(n);
	for (int i = 0; i < n; i++) make_set(i);
	vector<int> adjList(n);
	for (int i = 0; i < n; i++) {
		cin >> adjList[i];
		adjList[i]--;
	}
	int cnt_cycles = 0;
	for (int i = 0; i < n; i++) {
		if (find_set(i) == find_set(adjList[i]))
			cnt_cycles++;
		else
			merge(i, adjList[i]);
	}
	cout << sub(fast_exp(2, cnt_cycles), 1);
}
#include<bits/stdc++.h>
using namespace std;
 
int n, f;
bool used[200002];
vector<int> g[200002];
main(){
  cin >> n;
  int ans=1;
  for(int i=0;i<n;i++)cin>>f,f--,g[i].push_back(f),g[f].push_back(i);
  for(int i=0;i<n;i++){
    if(used[i])continue;
    queue<int>q;
    q.push(i);
    used[i]=1;
    while(!q.empty()){
      int v=q.front();
      q.pop();
      for(auto to:g[v])
        if(!used[to])
          q.push(to),used[to]=1;
    }
    ans=(ans+ans);
    if(ans>=998244353)ans-=998244353;
  }
  ans+=998244352;
  if(ans>998244353) ans-=998244353;
  cout << ans;
}