#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define ALL(v) v.begin(),v.end()
#define sz(v) (ll)v.size()
const ll INF = 1e18;
const ll MOD = 998244353; 
// const ll MOD = 1000000007;
ll dx[] = {1, 0, -1, 0};
ll dy[] = {0, 1, 0, -1};
const double PI = acos(-1.0);

//--------------------------------------------------
//--------------------------------------------------

struct UnionFind{
    vector<int> rank, p;
    UnionFind(int N){
        rank.resize(N, 0);
        p.resize(N, 0);
        for(int i=0; i < N; i++) makeSet(i);
    }
    void makeSet(int x){
        p[x] = x;
        rank[x] = 0;
    }
    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }
    void unite(int x, int y){
        link(findSet(x), findSet(y));
    }
    void link(int x, int y){
        if(rank[x] > rank[y]){
            p[y] = x;
        }else{
            p[x] = y;
            if(rank[x] == rank[y]){
                rank[y]++;
            }
        }
    }
    int findSet(int x){
        if(x != p[x]){
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};


int main() {
    ll n; cin >> n;
    UnionFind uf = UnionFind(n);
    for(ll i = 0; i < n; i++){
        ll f; cin >> f; f--;
        uf.unite(i, f);
    }
    set<ll> st;
    for(ll i = 0; i < n; i++) st.insert(uf.findSet(i));
    ll ans = 1;
    for(ll i = 0; i < sz(st); i++) ans = (ans * 2) % MOD;
    cout << ans-1 << endl;

    return 0;
} 

#include<stdio.h>
#include<math.h>
 
#define ni(n) ((n) * (n))
#define rep(i,n) for(i=0;i<n;i++)
#define X(a,n) (a<=n)?a+n:a-n
#define N

int main(void){
	char str[6] = "ZONe";
	char s[100];
	int ans = 0;
	int count = 0;
	scanf("%s",s);
	int i;
	rep(i,12){
		if(s[i] == str[0]){
			int j;
			rep(j,4){
				if(s[i+j] == str[j]) count++;
			}
			if(count == 4) ans++;
		}
		count = 0;
	}
	printf("%d",ans);
	return 0;
}