#include using namespace std; typedef long long ll; typedef long double ld; typedef pair PP; // #define MOD 1000000007 #define MOD 998244353 #define INF 2305843009213693951 //#define INF 810114514 #define PI 3.141592653589 #define setdouble setprecision #define REP(i,n) for(ll i=0;i<(n);++i) #define OREP(i,n) for(ll i=1;i<=(n);++i) #define RREP(i,n) for(ll i=(n)-1;i>=0;--i) #define ORREP(i,n) for(ll i=(n);i>=1;--i) #define rep(i,a,b) for(ll i=(a);i<=(b);++i) #define ALL(v) (v).begin(), (v).end() #define GOODBYE do { cout << "-1" << endl; return 0; } while (false) #define MM <<" "<< #define Endl endl #define debug true #define debug2 false // void solve(vector R){ // ll N = R.size(); // ll sum = 0; // REP(j,N){ // sum += R[j]; // } // REP(i,10){ // cout << i << ": "; // REP(j,N){cout << R[j] << " ";}cout << endl; // vector tmp(N,0); // REP(j,N){ // if(R[j]==0 && R[(j-1+N)%N]==1)tmp[j] = 1; // if(R[j]==1 && R[(j+1+N)%N]==1)tmp[j] = 1; // } // swap(R,tmp); // ll num = 0; // REP(j,N){ // num += R[j]; // } // assert(sum==num); // } // cout << endl; // } long long inverse(long long b){ // Copyright (c) 2023 0214sh7 // https://github.com/0214sh7/library/ long long r=1,e=MOD-2; while(e){ if(e&1){ r=(r*b)%MOD; } b=(b*b)%MOD; e >>=1; } return r; } int main(void){ //cin.tie(nullptr); //ios::sync_with_stdio(false); // rep(i,2,6){ // REP(j,1< s(i,0); // REP(k,i){s[k]=(j>>k)%2;} // solve(s); // } // } ll N; cin >> N; ll one = 0; REP(i,N){ ll a; cin >> a; if(a==1)one++; } vector B(N,0); REP(i,min(one,N/2)){ B[2*i] = 1; } REP(i,min(one-N/2,(N+1)/2)){ B[min(2*i+1,N-1)] = 1; } ll Ans = 0; REP(i,N){ Ans += B[(i+1)%N]*(1-B[i]); } Ans = (Ans*inverse(N))%MOD; cout << Ans << endl; return 0; }