func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 5010;   const int inf = 1e9;   const int mo = 1e9 + 7;   int s[N], num[N][N], ans[N], gra[N][N];   int main() {     int n, m;     cin >> n >> m;     for (auto i = (1); i <= (n); ++i) {       cin >> s[i];     }     memset(num, 0, sizeof(num));     memset(gra, 0, sizeof(gra));     memset(ans, -1, sizeof(ans));     for (auto i = (1); i <= (n); ++i) {       for (auto j = (i); j <= (n); ++j) {         gra[s[i]][j]++;       }     }     for (auto i = (1); i <= (m); ++i) {       int f, h;       cin >> f >> h;       for (auto j = (h); j <= (n); ++j) {         num[f][j]++;       }     }     for (auto i = (0); i <= (n); ++i) {       int cntl = gra[s[i]][i], cntr = gra[s[i]][n] - gra[s[i]][i];       if (i && !(num[s[i]][cntl] - num[s[i]][cntl - 1])) continue;       long long cur = 0, tmp = 1;       if (i) cur++;       int sr = num[s[i]][cntr];       if (cntr >= cntl) sr--;       if (sr >= 1) {         cur++;         tmp *= sr;       }       for (auto j = (1); j <= (n); ++j) {         if (j == s[i]) continue;         int cntl = gra[j][i - 1], cntr = gra[j][n] - gra[j][i];         int sl = num[j][cntl], sr = num[j][cntr];         if (!sr && !sl)           continue;         else if (!sl) {           tmp = (tmp * sr) % mo;           cur++;         } else if (!sr) {           tmp = (tmp * sl) % mo;           cur++;         } else if (sl == 1 && sr == 1) {           cur += 1;           tmp = tmp * 2 % mo;         } else {           cur += 2;           tmp = (tmp * (sl * sr - min(sl, sr))) % mo;         }       }       if (ans[cur] == -1) ans[cur] = 0;       ans[cur] = (ans[cur] + tmp) % mo;     }     ans[0] = 1;     for (auto i = (n); i >= (0); --i) {       if (ans[i] != -1) {         cout << i <<     << ans[i];         break;       }     }     return 0;   }   