#include<bits/stdc++.h>
using namespace std;

const int N=2e5+1e3+7;

int T,n,fa[N];

int find(int x)
{
    return x==fa[x]?x:fa[x]=find(fa[x]);
}

signed main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        fa[find(x)]=find(i);
    }
    int cnt=1;
    for(int i=1;i<=n;i++)
        if(fa[i]==i)
            cnt=cnt*2%998244353;
    cnt=(cnt-1+998244353)%998244353;
    printf("%d\n",cnt);
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define P pair<ll,ll>
using Graph = vector<vector<P>>;

//累乗 aのb乗、正しmを法として求める
long long pw(long long a,int b,int m){
    if(b==0) return 1;
    else if(b%2==0){
        long long x = pw(a,b/2,m);
        return (x*x)%m;
    }
    else{
        long long x = pw(a,b-1,m);
        return (a*x)%m;
    }
}

int main(){
    int N; cin >> N;
    int f[N+1]; bool remain[N+1];
    int vis1[N+1];
    rep(i,N){
        cin >> f[i+1];
        remain[i+1] = true;
        vis1[i+1] = 0;
    }
    int loop = 0;
    rep(i,N){
        if(!remain[i+1]) continue;
        int st = i+1;
        while(vis1[st]==0){
            vis1[st] = i+1;
            remain[i+1] = false;
            st = f[st];
        }
        if(vis1[st]==i+1) loop++;
    }
    int m = 998244353;
    cout << (pw(2LL,loop,m) - 1+m)%m << endl;
}