#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
const int N = 2e5;
const int mod = 998244353;
using namespace std;
int n,a[N + 5],fa[N + 5];
int mypow(int a,int x){int s = 1;for (;x;x & 1 ? s = 1ll * s * a % mod : 0,a = 1ll * a * a % mod,x >>= 1);return s;}
int find(int x)
{
    if (x == fa[x])
        return x;
    return fa[x] = find(fa[x]);
}
int main()
{
    scanf("%d",&n);
    for (int i = 1;i <= n;i++)
        scanf("%d",&a[i]);
    for (int i = 1;i <= n;i++)
        fa[i] = i;
    for (int i = 1;i <= n;i++)
    {
        int X = find(i),Y = find(a[i]);
        if (X != Y)
            fa[X] = Y;
    }
    int sm = 0;
    for (int i = 1;i <= n;i++)
        if (fa[i] == i)
            sm++;
    cout<<((mypow(2,sm) - 1) % mod + mod) % mod<<endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define vec(a, y, x) vector<vector<char>> a(y, vector<char>(x))
using P = pair<int, int>;
using T = tuple<int, int, int>;
const double PI = 3.14159265358979323846;
const in MOD = 998244353;
const in INF = 1e18 + 7;
const int inf = 1e9 + 7;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
//cout << fixed << setprecision(10);

int main(void)
{
    int n;
    cin>>n;
    vector<int>graph(n);
    set<int> seen;//観たら消去
    int kazu=0;//サイクルの個数 

    rep(i,n){
        int f;
        cin>>f;
        f--;
        graph.at(i)=f;
    }
    rep(i,n){
        seen.insert(i);
    }

    while(!seen.empty()){
        int start = *begin(seen);
        set<int> mita;//見たやつを入れていく

        mita.insert(start);
        int now=start;
        seen.erase(start);

        while(1){
            now=graph.at(now);
            if(mita.count(now)){
                kazu++;
                break;
            }
            if(!seen.count(now))
                break;
            seen.erase(now);
            mita.insert(now);
        }
    }
    in ans = 1;
    rep(i,kazu){
        ans*=2;
        ans=ans%MOD;
    }
    ans--;
    cout<<ans<<endl;
}