#include <bits/stdc++.h>
namespace IO {
  #define iL (1 << 20)
  char ibuf[iL], *iS = ibuf + iL, *iT = ibuf + iL;
  #define gc() ((iS == iT) ? (iT = (iS = ibuf) + fread(ibuf, 1, iL, stdin), iS == iT ? EOF : *iS ++) : *iS ++)
  template<class T> inline void read(T &x) {
    x = 0;int f = 0;char ch = gc();
    for (; !isdigit(ch); f |= ch == '-', ch = gc());
    for (; isdigit(ch); x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc());
    x = (f == 1 ? ~ x + 1 : x);
  }
  char Out[iL], *iter = Out;
  #define flush() fwrite(Out, 1, iter - Out, stdout), iter = Out
  template<class T> inline void write(T x, char ch = '\n') {
    T l, c[35];
    if (x < 0) *iter ++ = '-', x = ~ x + 1;
    for (l = 0; !l || x; c[l] = x % 10, l++, x /= 10);
    for (; l; -- l, *iter ++ = c[l] + '0');*iter ++ = ch;
    flush();
  }
}
using namespace IO;
#define N 200005
#define ll long long
#define MOD 998244353
#define DEBUG
using namespace std;

int n, fa[N];

int Find(int x) {
	return (fa[x] == x) ? x : fa[x] = Find(fa[x]);
}

int Qpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = 1ll * res * a % MOD;
		a = 1ll * a * a % MOD, b >>= 1;
	}
	return res;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#endif
	read(n);
	for (int i = 1; i <= n; i++) fa[i] = i;
	for (int i = 1, f; i <= n; i++) {
		read(f);
		int a = Find(i), b = Find(f);
		if (a != b) fa[a] = b;
	}
	int ans = 0; 
	for (int i = 1; i <= n; i++) {
		if (fa[i] == i) ans = (ans + 1) % MOD;
	}
//	write(((ans - 1) * ans % MOD + 1) % MOD);
	write((Qpow(2, ans) % MOD - 1) % MOD);
  return 0;
}
#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;
}