#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
typedef int64_t ll;
#define PA pair<ll,ll>
#define TU tuple<ll,ll,ll>
#define vi vector<ll>
#define vii vector<vector<ll> >
#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define rep2(i,m,n) for(ll (i)=(m); (i)<(ll)(n); (i)++)
const ll INF = 1ll<<60;
const ll INF2 = 1ll<<32;
const ll MOD = 998244353;


void cycle(vi &v,ll state, vector<bool> &b,ll &pts) {
  ll ser = state;
  set<ll> s;
  while(!b.at(ser)) {
    s.insert(ser);
    b.at(ser) = true;
    ser = v.at(ser);
  } 
  if(s.count(ser)) pts++;
}

int main() {
  ll n;
  cin >>n;
  vi v(n);
  rep(i,n) {
    cin >>v.at(i);
    v.at(i)--;
  }
  
  vector<bool> b(n,false);
  ll pts =0;
  
  rep(i,n) {
    cycle(v,i,b,pts);
  } 
  
  ll ans =1;
  
  rep(i,pts) {
    ans *= 2;
    ans %= MOD;
  }
  ans--;
  ans %= MOD;
  
  cout <<ans <<endl;
}
using namespace std;
#include <bits/stdc++.h>
const int N=105,mo=998244353;
typedef long long ll;
int n,sum;
int w[N];
int f[N*N][N];
ll fac[N];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		scanf("%d",&w[i]),sum+=w[i];
	if (sum&1){
		printf("0\n");
		return 0;
	}
	sum/=2;
	f[0][0]=1;
	for (int i=1;i<=n;++i)
		for (int s=sum;s>=w[i];--s)
			for (int c=1;c<=i;++c)
				(f[s][c]+=f[s-w[i]][c-1])%=mo;
	fac[0]=1;
	for (int i=1;i<=n;++i)
		fac[i]=fac[i-1]*i%mo;
	ll ans=0;
	for (int c=0;c<=n;++c)
		ans=(ans+f[sum][c]*fac[c]%mo*fac[n-c])%mo;
	printf("%lld\n",ans);
	return 0;
}





