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

void check(long long &a, vector<int> &v, vector<int> &c, int i, int &lc){
  if(c.at(i) == lc){
    a++;
    return;
  }
  if(c.at(i) != -1){
    return;
  }
  c.at(i) = lc;
  check(a, v, c, v.at(i), lc);
}

int main(){
  int N;
  long long a = 0;
  cin >> N;
  vector<int> v(N);
  rep(i, N){
    cin >> v.at(i);
    v.at(i)--;
  }
  vector<int> c(N, -1);
  for(int i = 0; i < N; i++){
    if(c.at(i) == -1){
      check(a, v, c, i, i);
    }
  }
  long long ans = 1;
  rep(i, a){
    ans *= 2;
    ans %= 998244353;
  }
  cout << ans - 1 << endl;
}
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define forin(in ,n) for(ll i=0; i<n; i++) cin>>in[i]
#define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>

#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
// constexpr ll mod = 1000000007;
constexpr ll mod = 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void pt(T val) {
    cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];

        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}
ll mypow(ll a, ll n) {
    ll ret = 1;
    if(n==0) return 1;
    if(a==0) return 0;
    rep(i, n) {
        if (ret > (ll)(1e18 + 10) / a) return -1;
        ret *= a;
    }
    return ret;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll dig(ll n) {//桁数
    ll res = 0;
    while(n > 0) {
        res ++;
        n /= 10;
    }
    return res;
}
vector<bool> seen;
void dfs(vvll &G, ll v){
    seen[v]=true;
    for(auto next:G[v]){
        if(seen[next]) continue;
        dfs(G,next);
    }
}

int main() {
    ll n,x,ans=1;
    cin>>n;
    vvll G(n);
    vll a(n);
    rep(i,n){
        cin>>x;
        x--;
        G[i].push_back(x);
        G[x].push_back(i);
    }
    seen.assign(n,false);
    rep(i,n){
        if(seen[i]) continue;
        dfs(G,i);
        ans*=2;
        ans%=mod;
    }
    cout<<(mod+ans-1)%mod<<endl;
}