#include <iostream>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <random>
#include <cassert>

typedef long long ll;
using namespace std;

constexpr ll mod = 1000000007;
constexpr ll mod998 = 998244353;


int N, F[200000], T[200000], cnt;

int par(int x) {
	if (T[x] == x)return x;
	else return T[x] = par(T[x]);
}

void uni(int x, int y) {
	x = par(x);
	y = par(y);
	T[x] = y;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> F[i];
		F[i]--;
		T[i] = i;
	}
	for (int i = 0; i < N; i++) {
		uni(i, F[i]);
	}
	for (int i = 0; i < N; i++) {
		if (i == T[i])cnt++;
	}
	ll res = 1;
	for (int i = 0; i < cnt; i++) {
		res *= 2;
		res %= mod998;
	}
	cout << (res - 1 + mod998) % mod998 << endl;
}
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=998244353 ;


struct UnionFind{
   vector<int> par;
   UnionFind(int n):par(n,-1){}
   int find(int x){
       if(par[x]<0)return x;
       return par[x]=find(par[x]);
   }
   bool unite(int x,int y){
       x=find(x);
       y=find(y);
       if(x==y)return false;
       if(par[x]>par[y]){
           par[y]+=par[x];
           par[x]=y;
       }
       else{
           par[x]+=par[y];
           par[y]=x;
       }
       return true;
   }

   bool same(int x,int y){
       return find(x)==find(y);
   }
   int size(int x){
       return -par[find(x)];
   }
};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    UnionFind uf(n);
    rep(i,n){
        int x;
        cin>>x;
        uf.unite(i,x-1);
    }
    ll ans = 1;
    rep(i,n){
        if(uf.find(i)==i)ans=ans*2%mod;
    }
    cout<<ans-1<<endl;
    return 0;
}