#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;

const int maxn=2e5+10;
const int mod=998244353;

int n,ans=1,now,f[maxn],v[maxn];

int read(int x=0,bool f=0,char ch=getchar()){
	for(;ch<'0' || ch>'9';ch=getchar()) f=ch=='-';
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+(ch&15);
	return f?-x:x;
}

int main(){
	n=read();
	for(int i=1;i<=n;++i) f[i]=read();
	for(int i=1;i<=n;++i){
		if(!v[i]){
			++now;
			int x=i;
			while(!v[x]) v[x]=now,x=f[x];
			if(v[x]==now) ans=ans*2%mod;
		}
	}
	printf("%d\n",(ans+mod-1)%mod);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

template <int MOD>
struct ModInt {
  int _v;

  ModInt(int64_t v = 0) {
    if (v < 0) v = v % MOD + MOD;
    if (v >= MOD) v %= MOD;
    _v = int(v);
  }

  ModInt(uint64_t v) {
    if (v >= MOD) v %= MOD;
    _v = int(v);
  }

  ModInt(int v) : ModInt(int64_t(v)) {}
  ModInt(unsigned v) : ModInt(uint64_t(v)) {}

  ModInt& operator++() {
    ++_v;
    if (_v == MOD) _v = 0;
    return *this;
  }

  ModInt& operator--() {
    if (_v == 0) _v = MOD;
    --_v;
    return *this;
  }

  ModInt& operator+=(const ModInt& rhs) {
    _v += rhs._v;
    if (_v >= MOD) _v -= MOD;
    return *this;
  }

  ModInt& operator-=(const ModInt& rhs) {
    _v -= rhs._v;
    if (_v < 0) _v += MOD;
    return *this;
  }

  ModInt& operator*=(const ModInt& rhs) {
    int64_t z = _v;
    z *= rhs._v;
    _v = z % MOD;
    return *this;
  }

  ModInt operator++(int) { ModInt before = *this; ++*this; return before; }
  ModInt operator--(int) { ModInt before = *this; --*this; return before; }

  friend ModInt operator*(const ModInt &a, const ModInt &b) { return ModInt(a) *= b; }
  friend ModInt operator+(const ModInt &a, const ModInt &b) { return ModInt(a) += b; }
  friend ModInt operator-(const ModInt &a, const ModInt &b) { return ModInt(a) -= b; }

  friend bool operator==(const ModInt &a, const ModInt &b) { return a.val == b.val; }
  friend bool operator!=(const ModInt &a, const ModInt &b) { return a.val != b.val; }
  friend bool operator<(const ModInt &a, const ModInt &b) { return a.val < b.val; }
  friend bool operator>(const ModInt &a, const ModInt &b) { return a.val > b.val; }
  friend bool operator<=(const ModInt &a, const ModInt &b) { return a.val <= b.val; }
  friend bool operator>=(const ModInt &a, const ModInt &b) { return a.val >= b.val; }

  friend ostream& operator<<(ostream &os, const ModInt& a) { return os << a._v; }
};
 
const int MOD = 998244353;
using mod_int = ModInt<MOD>;

int main() {
  int N;
  cin >> N;
  vector<vector<int>> g(N);
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    --x;  // Convert to 0-based indexing.
    g[i].push_back(x);
    g[x].push_back(i);
  }

  function<void(int, vector<bool>&)> visitComponentDFS;
  visitComponentDFS = [&] (int u, vector<bool>& visited) {
    visited[u] = true;
    for (int v : g[u]) {
      if (!visited[v]) {
        visitComponentDFS(v, visited);
      }
    }
  };

  mod_int num = 1;
  vector<bool> visited(N, false);
  int num_cc = 0;
  for (int i = 0; i < N; ++i) {
    if (!visited[i]) {
      ++num_cc;
      visitComponentDFS(i, visited);
    }
  }

  while (num_cc > 0) {
    num *= 2;
    --num_cc;
  }

  num -= 1;
  cout << num << endl;
}