#include<bits/stdc++.h>

using namespace std;

#define fastio            ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ifs               freopen("aa.in","r",stdin);
#define ofs               freopen("aa.out","w",stdout);
#define iof               ifs ofs
#define ll                long long
#define ld                long double
#define da(x,i)           cout << #x << "[" << i << "]=" << x[i] << "\n";
#define da2(x,i,y,j)      cout << #x << "[" << i << "]=" << x[i] << " ! " << #y << "[" << j << "]=" << y[j] << "\n";
#define d2a(x,i,j)        cout << #x << "[" << i << "][" << j << "]=" << x[i][j] << "\n";
#define db(x)             cout << #x << "=" << (x) << "\n";
#define db2(x,y)          cout << #x << "=" << (x) << " ! " << #y << "=" << (y) << "\n";
#define db3(x,y,z)        cout << #x << "=" << (x) << " ! " << #y << "=" << (y) << " ! " << #z << "=" << (z) << "\n";
#define db4(w,x,y,z)      cout << #w << "=" << (w) << " ! " << #x << "=" << (x) << " ! " << #y << "=" << (y) << " ! " << #z << "=" << (z) << "\n";
#define inf               LLONG_MAX
#define fr                first
#define sc                second
#define all(a)            a.begin(),a.end()

const ll M=998244353,N=1e6+7;;
vector<ll> p(N,-1),g[N],f=p;
ll n,i,j,k,A,z;

void join(ll a,ll b)
{
    if(a==b)
        return;
    ll sa,sb;
    sa=(ll)g[a].size();
    sb=(ll)g[b].size();
    if(sa<sb)
        swap(a,b);
    for(ll i : g[b]){
        p[i]=a;
        g[a].push_back(i);
    }
    g[b]={};
}

ll bmod(ll n=j)
{
    if(n==0)
        return 1;
    if(n==1)
        return 2;
    if(n%2)
        return (2*bmod(n-1))%M;
    ll R=bmod(n/2);
    return (((R%M)*(R%M))%M+2*M)%M;
}

int main()
{
    cin>>n;
    for(i=1; i<=n; i++){
        g[i]={i};
        p[i]=i;
    }
    for(i=1,k=0; i<=n; i++){
        cin>>j;
        join(p[j],p[i]);
    }
    for(i=1,j=0; i<=n; i++){
        z=(ll)g[i].size();
        if(z)
            j++;
    }
    A=bmod();
    A=(A+3*M)%M;
    cout<< A-1 <<"\n";
}















































#include<iostream>
#include<cstdio>
#include<ctime>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<vector>
#include<iomanip>
#include<fstream>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<sstream>
using namespace std;
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
//string::npos

const double pi = 3.141592653589;
const int maxn = 200002;
const int maxm = 26;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
typedef long long ll;

ll ksm(int a, int k){
    ll res = 1;
    while(k){
        if(k&1) res = (ll)res*a%mod;
        a = (ll)a*a%mod;
        k >>= 1;
    }
    return res;
}
int nxt[maxn];
int vis[maxn];
int ans, p, ring, n;

void solve(){
    for(int i = 1; i <= n; ++i){
        if(vis[i]) continue;
        p = i;
        ++ring;
        while(vis[p] == 0){
            vis[p] = ring;
            p = nxt[p];
            if(vis[p] == ring) ++ans;
        }
    }
}


int main(){
    sync;

    cin >> n;
    ring = 1;
    for(int i = 1; i <= n; ++i){
        cin >> nxt[i];
        if(nxt[i] == i){
            vis[i] = ring++;
            ans++;
        }
    }
    solve();
    cout << ksm(2, ans)-1 << endl;


    return 0;
}



