func_code_string: #include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double EPS = 1E-8;   const long double PI = 3.1415926535897932384626433832795;   const int MAXN = 5200;   const int MAXF = 1001000;   long long d1[MAXN], d[MAXN], D[MAXN][MAXN], p;   long long f[MAXF], a[MAXF];   vector<long long> l;   int n, m;   long long get(int n, int c) {     if (n == 0 && c == 0) return 1;     if (n == 0 || c == 0) return 0;     long long &ans = D[n][c];     if (ans != -1) return ans;     ans = (get(n - 1, c - 1) + get(n - 1, c) * (c - 1)) % p;     return ans;   }   int main() {     cin >> n >> m >> p;     f[0] = a[0] = 1;     for (int i = 1; i < MAXF; i++) {       f[i] = (f[i - 1] * i) % p;       a[i] = (a[i - 1] * (m - i + 1)) % p;     }     int prev = -1;     long long sum = 0;     memset(D, 255, sizeof D);     for (int step = 0; step < (int)(n); step++) {       int l;       scanf( %d , &l);       for (int i = 1; i <= l; i++)         if (prev == -1) {           long long cur = get(l, i) % p;           cur = (cur * a[i]) % p;           d1[i] = cur;         } else {           long long cur = get(l, i) % p;           cur = (cur * a[i]) % p;           cur = (cur * sum) % p;           long long ppp = 0;           if (i <= prev) {             ppp = get(l, i) % p;             ppp = (ppp * f[i]) % p;             ppp = (ppp * d[i]) % p;           }           d1[i] = (cur - ppp + p) % p;         }       sum = 0;       for (int i = 0; i < (int)(l + 1); i++) {         sum = (sum + d1[i]) % p;         d[i] = d1[i];       }       prev = l;     }     long long ans = 0;     for (int i = 0; i < (int)(prev + 1); i++) ans = (ans + d[i]) % p;     cout << ans << endl;     return 0;   }   