#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
using pint = pair<ll, ll>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const ll mod = 998244353;

int n;
bool seen[200200];
vector<vector<int>> g(200200);

int dfs(int a) {
    if (seen[a]) return a;
    seen[a] = 1;
    for (auto b : g[a]) {
        seen[b] = 1;
        return dfs(b);
    }
}

ll modpow(ll n, ll m) {
    ll ans = 1;
    while (n > 0) {
        if (n & 1) ans = ans * m % mod;
        m = m * m % mod;
        n >>= 1;
    }
    return ans;
}

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}  //親は-1

    int root(int x) {
        if (par[x] < 0)
            return x;  //自身が親
        else
            return par[x] = root(par[x]);  //再帰
    }

    bool same(int x, int y) { return root(x) == root(y); }

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;  //既に同じ根
        // xとyのサイズの大きいほうにまとめたい
        if (size(x) < size(y)) swap(x, y);
        par[x] += par[y];  //根のparは-(要素数)になる
        par[y] = x;        //親を更新
        return;
    }

    int size(int x) { return -par[root(x)]; }
};

int main() {
    cin >> n;
    vector<int> f(n);
    vector<int> pp;
    UnionFind tree(n);
    rep(i, 0, n) {
        cin >> f[i];
        f[i]--;
        g[i].push_back(f[i]);
        if (i == f[i]) {
            pp.push_back(i);
        }
        tree.merge(i, f[i]);
    }
    int cnt = 0;
    set<int> st;
    rep(i, 0, n) st.insert(tree.root(i));
    cnt = st.size();
    ll ans = modpow(cnt, 2) - 1;
    cout << ans << "\n";
}

#include <bits/stdc++.h>
using namespace std;
const long long INF = 10000000000000007;
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
  int n,num=0;
  cin >> n;

  vector<int>f(n);
  for (int i = 0; i < n; i++) {
    int f_;
    cin >> f_;
    f_--;
    f[i] = f_;
  }

  vector<bool>seen(n+1,0);

  for (int i = 0; i < n; i++) {
    if (seen[i]==1) continue;
    else {
      int k = f[i];
      set<int>seen2;
      while(1) {
        if (seen2.count(k)) {
          num++;
          break;
        }
        if (seen[k]) {
          break;
        }
        seen[k] = 1;
        seen2.insert(k);
        k = f[k]; 
      }
    }
  }
  ll ans = 1;
  while(num) {
    ans *= 2;
    ans %= 998244353;
    num--;
  }
  cout << ans - 1 << endl;
}
 