#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}

const int MAX_N = 200100;
int par[MAX_N]; // 親
int rank_[MAX_N]; // 木の深さ
int cnt_[MAX_N]; // 属する頂点の個数(親のみ正しい)

// n要素で初期化
void UFinit(){
    for(int i=0;i<MAX_N;i++){
        par[i] = i;
        rank_[i] = 0;
        cnt_[i] = 1;
    }
}

// 木の根を求める
int find(int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を併合
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank_[x] < rank_[y]){
        par[x] = y;
        cnt_[y] += cnt_[x];
    }else{
        par[y] = x;
        cnt_[x] += cnt_[y];
        if(rank_[x] == rank_[y]) rank_[x]++;
    }
}

// xとyが同じ集合に属するか否か
bool same(int x, int y){
    return find(x) == find(y);
}

ll mod_pow(ll x, ll n, ll mod){ // x ^ n % mod
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    UFinit();
    int n;
    cin >> n;
    int f[n] = {};
    rep(i,n){
        cin >> f[i];
        f[i]--;
        unite(i,f[i]);
    }
    ll cnt = 0;
    rep(i,n){
        if(find(i) == i) cnt++;
    }
    const ll MOD = 998244353;

    ll ans = mod_pow(2,cnt,MOD) + MOD - 1;
    ans %= MOD;

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <random>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

const int mod = 998244353;
int n;
int w[100];
int fact[101];
int dp[101][101][5101];

signed main() {
	int i, j, k;
	
	cin >> n;
	rep(i, n) cin >> w[i];
	
	fact[0] = 1;
	for (i = 1; i <= n; i++) {
		fact[i] = fact[i - 1] * i % mod;
	}
	
	int sumW = 0;
	rep(i, n) sumW += w[i];
	if (sumW % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}
	
	dp[0][0][0] = 1;
	rep(i, n) {
		for (j = 0; j <= i; j++) {
			rep(k, 5001) {
				dp[i + 1][j][k] += dp[i][j][k];
				dp[i + 1][j][k] %= mod;
				dp[i + 1][j + 1][k + w[i]] += dp[i][j][k];
				dp[i + 1][j + 1][k + w[i]] %= mod;
			}
		}
	}
	
	int ans = 0;
	for (i = 1; i < n; i++) {
		int res = dp[n][i][sumW / 2];
		ans += res * fact[i] % mod * fact[n - i] % mod;
		ans %= mod;
	}
	
	cout << ans << endl;
	return 0;
}