#include using namespace std; #include using mint = atcoder::modint998244353; #pragma region Math ACL Combination const int CombMAX = 3000000; std::vector fac(CombMAX + 1), finv(CombMAX + 1), inv(CombMAX + 1); struct Combinationinit { Combinationinit() { const int MOD = mint::mod(); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i <= CombMAX; i++) { fac[i] = fac[i - 1] * i; inv[i] = (mint)MOD - inv[MOD % i] * (MOD / i); finv[i] = finv[i - 1] * inv[i]; } } } Combinationinit_; //nCk mint COM(int n, int k) { if(n < k or n < 0 or k < 0) return 0; assert(n <= CombMAX); return fac[n] * finv[k] * finv[n - k]; } mint bigCOM(int n, int k) { if(n < k or n < 0 or k < 0) return 0; mint res = finv[k]; for(int i = 1; i <= k; ++i) res *= (n + 1 - i); return res; } //nPk mint PER(int n, int k) { if(n < k or n < 0 or k < 0) return 0; assert(n <= CombMAX); return fac[n] * finv[n - k]; } //nHk mint HOM(int n, int k) { assert(n <= CombMAX); return COM(n + k - 1, k); }; #pragma endregion int n, m, a[2000]; int main() { scanf("%d%d", &n, &m); for(int i = 0; i < m; i++) scanf("%d", &a[i]); vector dp(m + 1, vector(0, vector(0, mint(0)))); vector sub(m + 1, vector(n + 1, mint(0))); for(int k = 0; k < m; k++) { int len_i = (k ? a[k] - a[k - 1] : a[0]); int len_j = (k ? a[k - 1] : 0); dp[k].assign(len_i + 1, vector(len_j + 1, mint(0))); for(int i = 0; i <= len_i; i++) { for(int j = 0; j <= len_j; j++) { if(!i and !j) continue; auto &now = dp[k][i][j]; now = (mint)a[k]; if(j) now += dp[k][i][j - 1] * j; if(i >= 2) now += dp[k][i - 1][j] * i; if(i == 1 and k) { now += sub[k - 1][j] * i; } now *= inv[i + j]; } } for(int i = 0; i <= a[k]; i++) { if(k) { sub[k][i] = sub[k - 1][i] * COM(a[k - 1], i) / COM(a[k], i); for(int z = 1; z <= a[k] - a[k - 1] and i - z >= 0; z++) sub[k][i] += dp[k][z][i - z] * COM(a[k] - a[k - 1], z) * COM(a[k - 1], i - z) / COM(a[k], i); } else if(i) sub[k][i] = sub[k][i - 1] + (mint)a[0] / i; } } cout << dp[m - 1][a[m - 1] - a[m - 2]][a[m - 2]].val() << endl; }