#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<cmath>
#define SYNC ios::sync_with_stdio(0),cin.tie(0)
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define MOD 998244353
#define EPS 1e-6
#define endl '\n'
using namespace std;
const int MAXN = 214514;

int n;
int f[MAXN];
int visted[MAXN], step;
long long pw;

bool find(int x){
	while(!visted[x]){
		visted[x] = step;
		x = f[x];
	}
	return visted[x] == step;	
}
int ksm(long long a, long long p){
	long long res = 1;
	while(p){
		if(p & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		p >>= 1;
	}
	return res % MOD;
}
void solve(){
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> f[i];
	for(int i = 1; i <= n; ++i){
		++step;
		if(!visted[i] && find(i))
			++pw;
	}
	cout << ksm(2, pw) - 1<< endl;
}
int main(){
	SYNC;
	solve();
}


#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#define LOG(FMT...) fprintf(stderr, FMT);
#define rep(i, j, k) for(int i = j; i <= k; ++ i)
#define per(i, j, k) for(int i = j; i >= k; -- i)
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 mt(std::chrono::system_clock::now().time_since_epoch().count());
uniform_int_distribution<ll> ran(0, 1ll << 62);
void ucin() { ios::sync_with_stdio(0); cin.tie(0); }
template<class T> inline void chkmax(T &x, const T &y) { if(x < y) x = y; }
template<class T> inline void chkmin(T &x, const T &y) { if(x > y) x = y; }
inline ll sqr(ll x) { return x * x; }
inline ll cub(ll x) { return x * x * x; }

const int N = 2e5 + 10;
const int mod = 998244353;
int n, out[N], f[N], sz[N];
bool cir[N];
int find(int x) {
  return x == f[x] ? x : f[x] = find(f[x]);
}
int main() {
  scanf("%d", &n);
  rep(i, 1, n) {
    scanf("%d", out + i);
  }
  rep(i, 1, n) {
    f[i] = i; cir[i] = 0;
  }
  rep(i, 1, n) {
    int x = find(i), y = find(out[i]);
    if(x == y) cir[x] = 1;
    else {
      cir[x] |= cir[y];
      f[y] = x;
    }
  }
  rep(i, 1, n) sz[find(i)] ++;
  int ans = 1;
  rep(i, 1, n) if(find(i) == i) {
    ans = 1ll * ans * (cir[i] ? 2 : sz[i] + 1) % mod;
  }
  ans = ans ? ans - 1 : mod - 1;
  printf("%d\n", ans);
  return 0;
}