#include using namespace std; using mint = atcoder::modint998244353; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, s = 0; cin >> n; vector A(n + 1); string str; for(int i = 1; i <= n; i++){ cin >> A[i]; str += string(A[i] - A[i - 1], '1') + "0"; } auto f = [&](int start){ mint div = 1; vector tb(1001); for(int i = start, cnt = 0; i < str.size(); i += 2){ if(str[i] == '0'){ s += cnt; for(int j = 0; j < cnt; j++) div *= cnt - j + tb[j]++; }else cnt++; } return div; }; mint ans = 1 / (f(0) * f(1)); if(2 * s != accumulate(A.begin(), A.end(), 0)){ cout << 0 << '\n'; return 0; } for(int i = 1; i <= s; i++)ans *= i; cout << ans.val() << '\n'; }