#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

struct UnionFind{
    vector<int> p,r;
    UnionFind(int n){
        p.resize(n, -1);
        r.resize(n,  1);
    }

    int find(int x){
        if(p[x] == -1) return x;
        else return p[x] = find(p[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(r[x] > r[y]) swap(x,y);
        if(r[x] == r[y]) r[y]++;
        p[x] = y;
    }
};

ll mod = 998244353;
ll modpow(ll a,ll b){
    ll ans = 1;
    a %= mod;
    while(b){
        if(b&1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    int N; cin >> N;
    UnionFind uf(N);
    vector<int> f(N);
    rep(i,N){
        cin >> f[i];
        f[i]--;
        uf.unite(i, f[i]);
    }
    set<ll> se;
    rep(i,N) se.insert(uf.find(i));
    ll cnt = se.size();
    cout << modpow(2, cnt) - 1 << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn
#define per(i,n,a) for (int i=a-1;i>=n;i--)//iをnからa
#define db(x) cout << #x << " = " << x << endl//デバッグ用
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define pb push_back
#define F first
#define S second
typedef long long ll;
//sort(all(a)); ソート
//sort(all(a),greater<int>()); 逆順ソート
//a.erase(unique(all(a)), a.end()); ソート後に重複を削除
//cout<< std::fixed << std::setprecision(15)<<0.000001<<endl; 小数点以下を表示させる
//vector<vector<int>> data(3, vector<int>(4)); int型の2次元配列(3×4要素の)の宣言

int main() {
    ll ans=1;
    ll loopnum=0;
    int n;
    cin>>n;
    vector<int> f(n);
    vector<bool> isLooked(n);
    
    int fff;
    rep(i,0,n){
        cin>>fff;
        f.at(i)=fff-1;
    }
    
    
    rep(i,0,n){
    if(isLooked.at(i)){continue;}
    int nowplace=i;
    //db(i);
    set<int> iFoundedPlace;
    while(true){
    
    //db(nowplace);
    
    iFoundedPlace.insert(nowplace);
    //db(iFoundedPlace.size());
    nowplace=f.at(nowplace);
    
    if(isLooked.at(nowplace)){
        for(auto x : iFoundedPlace) {
        isLooked.at(x)=true;
        }
        break;
    }
    
    if(iFoundedPlace.count(nowplace)==1){
        for(auto x : iFoundedPlace) {
        isLooked.at(x)=true;
        }
        loopnum++;
        break;
    }
    
    }
    
    }
    rep(i,0,loopnum){
        ans*=2;
        ans%=998244353;
    }
    cout<<(ans%998244353)-1<<endl;
    
    
    
    return 0;
}