func_code_string: #include <bits/stdc++.h>   using namespace std;   int l[1000005], n, m;   long long f[5005][5005], g[2][5005], fa[5005], fac[5005], p, sum;   inline int read() {     int ret = 0;     char fa = getchar();     while (!isdigit(fa)) fa = getchar();     while (isdigit(fa)) {       ret = (ret << 1) + (ret << 3) + fa -  0 ;       fa = getchar();     }     return ret;   }   inline void Aireen() {     n = read();     m = read();     p = (long long)(read());     for (int i = 1; i <= n; ++i) l[i] = read();     fa[0] = fac[0] = 1ll;     for (int i = 1, j = m; i < 5005 && j; ++i, --j) {       fa[i] = fa[i - 1] * (long long)(i) % p;       fac[i] = fac[i - 1] * (long long)(j) % p;     }     f[0][0] = 1ll;     for (int i = 1; i < 5005; ++i)       for (int j = min(m, i); j; --j)         f[i][j] = (f[i - 1][j - 1] + f[i - 1][j] * (long long)(j - 1) % p) % p;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= l[i + 1]; ++j) g[i & 1][j] = 0ll;       if (i == 1) {         for (int j = min(l[i], m); j; --j) g[i][j] = fac[j] * f[l[i]][j] % p;       } else {         sum = 0ll;         for (int j = min(l[i - 1], m); j; --j) sum = (sum + g[i & 1 ^ 1][j]) % p;         for (int j = min(l[i], m); j; --j) {           g[i & 1][j] = (fac[j] * sum % p - fa[j] * g[i & 1 ^ 1][j] % p + p) % p *                         f[l[i]][j] % p;         }       }     }     sum = 0ll;     for (int j = min(l[n], m); j; --j) sum = (sum + g[n & 1][j]) % p;     cout << sum << endl;   }   int main() {     Aireen();     fclose(stdin);     fclose(stdout);     return 0;   }   