#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
template<class T> using V = vector<T>;
template<typename T> using posteriority_queue = priority_queue<T,vector<T>,greater<T>>;
#define rep(i,n) for (int i = 0; i < (int)(n) ; i++)
#define rep2(i,a,b) for (int i = (a); i < (int)(b); i++)
#define repR(i,n) for (int i = (int)(n)-1; i >= 0; i--)
#define repR2(i,a,b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ENDL '\n'
#define pb push_back
#define SIZE(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define UNIQUE(a) a.erase(unique(all(a)),a.end());
#define debug(x) cout<<(#x)<<" is : "<<(x)<<endl;
#define debugc(vec) {cout<<(#vec)<<" is below; -------"<<endl;for(auto elements:(vec))cout<<elements<<" ";cout<<endl<<"------------------"<<endl;}
inline string rev(string s) {string t(s.rbegin(), s.rend()); return t;}
template<class T> inline bool chmin(T &a, T b) { if(a>b) {a=b; return 1;} return 0;}
template<class T> inline bool chmax(T &a, T b) { if(a<b) {a=b; return 1;} return 0;}
const ll INF = (1LL<<30)-1;
const ll INFLL = (1LL<<62)-1;
const ld PI = 3.14159265358979323846L;

const ll MOD = 998244353;

ll modpow(ll x,ll y,ll mod) { //繰り返し二乗法
    if(mod==1) return 1;//特殊処理
    if(y==0) return 1;
    if(y==1) return x%mod;
    if(y%2==1) return x*modpow(x,y-1,mod)%mod;
    ll rt = modpow(x,y/2,mod);
    return rt*rt%mod;
}

int main() {
    cout << fixed << setprecision(15);
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll n, cnt=0; cin>>n;
    V<ll> edge(n), seen(n);
    rep(i, n) {
        cin>>edge[i];
        edge[i]--;
    }
    rep(i, n) {
        if(seen[i]) continue;
        seen[i]=i+1;
        ll now = i;
        while(1) {
            ll to = edge[now];
            if(seen[to]) {
                if(seen[to]==i+1) cnt++;
                break;
            }
            seen[to]=i+1;
            now = to;
        }
    }
    cout << modpow(2,cnt,MOD)-1 << endl; 
}
#include<bits/stdc++.h>
using namespace std;
vector<int>f(200009),sz(200009,0);
inline int getf(int x) {
	if(x!=f[x]) return f[x]=getf(f[x]);
	else return x;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	long long ans=0;
	cin>>n;
	vector<int>a(n);
	for(int i=1;i<=200008;i++) f[i]=i;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n/2;i++)
		f[getf(a[i])]=getf(a[n-i-1]);
	for(int i=1;i<=200008;i++)
		sz[getf(i)]++;
	for(int i=1;i<=200008;i++)
		if(i==getf(i))
			ans+=sz[i]-1;
	cout<<ans<<endl;
	return 0;
}