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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()
#define ff first
#define ss second

const double pi=3.1415926535897932384626433832795;
const int inf=1e9;
const ll inf2=1e18;
const int mod=998244353;

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N=2e5+5;
vi nxt(N,0),vis(N,0);

bool found=false;

void dfs(int u){
    vis[u]=1;
    int v=nxt[u];
    if((!found) && vis[v]==0){
        dfs(v);
    }
    else if(vis[v]==1){
        found=true;
    }
    vis[u]=2;
}

inline ll exp(ll x, ll n, ll m = mod) {
    ll r = 1;
    while(n) {
        if(n & 1) r = r * x % m;
        x = x * x % m, n >>= 1;
    }
    return r;
}

void solve(){
    int n;
    cin>>n;
    int cnt=0;
    for(int i=1;i<=n;i++){
        cin>>nxt[i];
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            found=false;
            dfs(i);
            if(found)
                cnt++;
        }
    }
    ll ans=exp(2,cnt);
    ans=(ans-1LL +mod)%mod;
    cout<<ans<<endl;
    return;
}

int main()
{
    boost();
    
    int tc=1;
    //cin>>tc;
    while(tc--)
        solve();
    return 0;
}
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

//-------------------------------------------------

const int N_MAX = 2e5;
vi G[N_MAX];

bool seen[N_MAX];
void dfs(int v)
{
    seen[v]=true;
    for(auto u:G[v]){
        if (seen[u]) continue;
        dfs(u);
    }
}

const ll mod = 998244353;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vi f(N);
    rep(i,N) cin>>f[i], f[i]--;
    rep(i,N){
        G[i].pb(f[i]);
        G[f[i]].pb(i);
    }
    ll ans=1;
    rep(v,N){
        if (!seen[v]){
            dfs(v);
            (ans*=2)%=mod;
        }
    }
    ans = (ans-1+mod)%mod;
    cout<<ans<<"\n";
    return 0;
}
