#include using namespace std; using ll = long long; constexpr ll mod = 998244353; template struct Mint { using M=Mint; ll v; M& put(ll x) { v=(x>=1; } return res; } M inv() { return pow(mod-2); } }; using mint = Mint; struct UnionFind{ int n; vector par; UnionFind(int n) : n(n), par(n, -1){} int find(int x){return par[x] < 0 ? x : find(par[x]);} bool Unite(int x, int y){ x = find(x), y = find(y); if(x == y)return false; // size[x] < size[y] if(par[x] > par[y])swap(x, y); par[x] += par[y]; par[y] = x; return true; } }; namespace std { template struct hash> { size_t operator()(pair const &val) const { return hash{}(val.first)*1337^hash{}(val.second); }}; } int main(){ int n; cin >> n; vector a(n); for(int i = 0; i < n; ++i){ cin >> a[i]; } int cn = 0; for(int i = 0; i < n; ++i){ if(a[i] == 1 && a[(i + 1) % n] == 0){ ++cn; } } cout << (mint(cn) * mint(n).inv()).v << endl; }