#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int mod=998244353;
const int maxn=2e5+7;
int fa[maxn];
int Find(int x)
{
    return x==fa[x]?x:fa[x]=Find(fa[x]);
}
void Union(int x,int y)
{
    x=Find(x),y=Find(y);
    fa[y]=x;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    for(int i=0;i<n;i++) fa[i]=i;
    vi f(n);
    for(int i=0;i<n;i++)
    {
        cin>>f[i];
        f[i]--;
        Union(i,f[i]);
    }
    int cc=0;
    for(int i=0;i<n;i++)
    {
        if(fa[i]==i) cc++;
    }
    int ans=1;
    for(int i=0;i<cc;i++) ans=ans*2%mod;
    ans=(ans-1+mod)%mod;
    print(ans);
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
struct edge {
    ll to;     // 辺の行き先
    ll weight; // 辺の重み
    edge(ll t, ll w) : to(t), weight(w) { }
};
typedef vector<vector<ll> > Graph;
typedef vector<vector<edge> > WGraph;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep3(i, k, n) for(int i = k; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define vout(v) for(int index_now=0; index_now < v.size(); i++) cout<<v[index_now]<<' '
#define blank cout<<endl
#define newvar(n) ll n; cin >> n
const ll MOD = 998244353;
const ll INF = MOD*MOD+1;
ll powmod(ll x, ll n, ll mod){
    ll ret=1;
    while(n>0){
        if(n&1) ret = (ret * x)%mod;
        x = (x*x)%mod;
        n >>= 1;
    }
    return ret;
}



int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vl f(n+1);
    rep(i,n) cin >> f[i+1];
    vl seen(n+1, 0);
    ll cnt = 0;
    rep3(i, 1, n+1){
        if(seen[f[i]]==2) continue;
        //cout << i << endl;
        ll now = i;
        bool check = true; //すでに見られたことがあるかどうか
        if(seen[now] == 2) check = false; //スタート地点が既訪だったら、なにもしない
        queue<ll> que;
        que.push(now);
        while(seen[now] == 0){ //今回の道が、既訪頂点に続いているか
            seen[now] = 1; //1は、この仮シミュレーションで訪れた場所
            now = f[now]; //つぎ
            if(seen[now] == 2) check = false; //かつて訪れていたら、なにもしない
            que.push(now);
        }
        if(!check){
            while(!que.empty()){
                seen[que.front()] = 2;
                que.pop();
            }
            continue;
        }
        now = i;
        while(seen[now] != 2){
            seen[now] = 2;
            now = f[now];
        }
        seen[now] = 2;
        cnt++;
    }
    cout << powmod(2, cnt, MOD) - 1;

    return 0;
}