malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   long long dp[12][65][1024], dp0[12][65][1024];   void upd(long long &a, long long b) { a = (a + b); }   int get_next(int a, int b) {     if ((a & (1 << b)) == 0) {       a += (1 << b);     } else {       a -= (1 << b);     }     return a;   }   void precalc() {     for (int i = 2; i <= 10; ++i) {       dp[i][0][0] = 1;       dp0[i][0][0] = 1;     }     for (int osn = 2; osn <= 10; ++osn) {       for (int len = 0; len <= 62; ++len) {         for (int mask = 0; mask < (1 << osn); ++mask) {           for (int next = 0; next < osn; ++next) {             upd(dp[osn][len + 1][get_next(mask, next)], dp[osn][len][mask]);             if (next == 0 && len == 0) {               continue;             }             upd(dp0[osn][len + 1][get_next(mask, next)], dp0[osn][len][mask]);           }         }       }     }   }   int digits[1000];   int cur[10];   int build(int x) {     int ans = 0;     for (int i = x - 1; i >= 0; --i) {       ans = ans * 2 + cur[i] % 2;     }     return ans;   }   long long f(long long n, long long x) {     int cnt = 0;     if (n == 0) {       return 0;     }     while (n > 0) {       ++cnt;       digits[cnt] = n % x;       n /= x;     }     reverse(digits + 1, digits + cnt + 1);     memset(cur, 0, sizeof cur);     long long answer = 0;     for (int i = 1; i <= cnt; ++i) {       for (int new_digit = 0; new_digit < x; ++new_digit) {         if (new_digit == 0 && i == 1) continue;         if (new_digit < digits[i]) {           ++cur[new_digit];           int cur_mask = build(x);           answer = answer + dp[x][cnt - i][cur_mask];           --cur[new_digit];         } else {           ++cur[new_digit];           break;         }       }     }     int cur_mask = build(x);     if (cur_mask == 0) ++answer;     for (int i = 1; i < cnt; ++i) {       answer += dp0[x][i][0];     }     return answer;   }   void solve(long long b, long long l, long long r) {     long long ans = f(r, b) - f(l - 1, b);     cout << ans << endl;   }   int main() {     precalc();     ios_base::sync_with_stdio(0);     int test;     cin >> test;     for (int tst = 1; tst <= test; ++tst) {       long long b, l, r;       cin >> b >> l >> r;       solve(b, l, r);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3610, mod = 998244353;   template <typename T>   void read(T &x) {     int ch = getchar();     x = 0;     for (; ch <  0  || ch >  9 ; ch = getchar())       ;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;   }   void qmo(int &x) { x += x >> 31 & mod; }   int ksm(int a, int b) {     int res = 1;     for (; b; b >>= 1, a = (long long)a * a % mod)       if (b & 1) res = (long long)res * a % mod;     return res;   }   int n, m, k, cnt1, cnt2, f[N][N >> 1], g[N][N >> 1], fac[N], inv[N], ans;   bool vis1[N], vis2[N];   void init(int n) {     fac[0] = 1;     for (int i = 1; i <= n; ++i) fac[i] = (long long)fac[i - 1] * i % mod;     inv[n] = ksm(fac[n], mod - 2);     for (int i = n; i; --i) inv[i - 1] = (long long)inv[i] * i % mod;   }   int main() {     read(n);     read(m);     read(k);     for (int i = 1, a1, b1, a2, b2; i <= k; ++i) {       read(a1);       read(b1);       read(a2);       read(b2);       vis1[a1] = vis1[a2] = vis2[b1] = vis2[b2] = true;     }     init(max(n, m));     for (int i = 0; i <= n; ++i) f[i][0] = 1;     for (int i = 1; i <= n; ++i)       if (!vis1[i]) ++cnt1;     for (int i = 0; i <= m; ++i) g[i][0] = 1;     for (int i = 1; i <= m; ++i)       if (!vis2[i]) ++cnt2;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= (i >> 1); ++j) {         f[i][j] = f[i - 1][j];         if (j && !vis1[i] && !vis1[i - 1]) qmo(f[i][j] += f[i - 2][j - 1] - mod);       }     for (int i = 1; i <= m; ++i)       for (int j = 1; j <= (i >> 1); ++j) {         g[i][j] = g[i - 1][j];         if (j && !vis2[i] && !vis2[i - 1]) qmo(g[i][j] += g[i - 2][j - 1] - mod);       }     for (int i = 0; (i << 1) <= cnt1; ++i)       for (int j = 0; (i << 1) + j <= cnt1 && (j << 1) + i <= cnt2; ++j)         ans = (ans + (long long)f[n][i] * g[m][j] % mod * fac[cnt2 - (j << 1)] %                          mod * inv[cnt2 - (j << 1) - i] % mod *                          fac[cnt1 - (i << 1)] % mod * inv[cnt1 - (i << 1) - j]) %               mod;     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void chmin(T &t, const T &f) {     if (t > f) t = f;   }   template <class T>   void chmax(T &t, const T &f) {     if (t < f) t = f;   }   int main() {     long long int n, a, c1, c2, m, len = 0, prev = 0, ans = 0, rlow, rlen, rind,                                    ret[100005];     vector<pair<long long int, long long int> > v;     vector<long long int> sum;     scanf( %I64d %I64d %I64d %I64d %I64d , &n, &a, &c1, &c2, &m);     for (long long int i = 0; i < n; ++i) {       long long int x;       scanf( %I64d , &x);       v.push_back(make_pair(x, i));     }     if (n == 1) {       long long int maxi = min(a, v[0].first + m);       printf( %I64d n , c1 * (maxi == a ? 1 : 0) + maxi * c2);       printf( %I64d  , maxi);       return 0;     }     sort(v.begin(), v.end());     sum.push_back(0);     for (int i = 1; i < n; ++i)       sum.push_back((v[i].first - v[i - 1].first) * i + sum[i - 1]);     while (len <= n) {       if (len - 1 >= 0) prev += a - v[n - len].first;       if (prev > m) break;       long long int newm = m - prev;       long long int ind = upper_bound(sum.begin(), sum.end(), newm) - sum.begin();       ind = max(0ll, min((long long int)ind - 1, (long long int)n - len - 1));       newm -= sum[ind];       long long int low = min(v[ind].first + (newm / (ind + 1)), a);       if (ans < len * c1 + low * c2) {         ans = len * c1 + low * c2;         rlow = low;         rind = ind;         rlen = len;       }       len++;     }     for (int i = 0; i < n; ++i) ret[v[i].second] = v[i].first;     for (int i = 0; i <= rind; ++i) ret[v[i].second] = max(v[i].first, rlow);     for (int i = n - 1; i >= n - rlen; --i) ret[v[i].second] = a;     printf( %I64d n , ans);     for (int i = 0; i < n; ++i) printf( %I64d  , ret[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int max_of_num;   int n, test_Q, point_num[100005], f_delp[100005][2];   vector<int> vc[100005];   bool flag = false;   void search1(int u, int fa) {     for (int i = 0; i < vc[u].size(); i++) {       int v = vc[u][i];       if (v != fa) {         if (point_num[v] == 1) {           if (f_delp[u][0]) {             flag = true;           }           f_delp[u][1] = true;         } else {           search1(v, u);           if (f_delp[v][1] && f_delp[u][1]) {             flag = true;           }           if (f_delp[v][0] && f_delp[u][0]) {             flag = true;           }           f_delp[u][0] = f_delp[u][0] | f_delp[v][1];           f_delp[u][1] = f_delp[u][1] | f_delp[v][0];         }       }     }   }   void connect_add(int u = 0, int v = 0) {     scanf( %d%d , &u, &v);     point_num[u]++;     point_num[v]++;     vc[u].push_back(v);     vc[v].push_back(u);   }   void search2(int u, int fa) {     int qaq = 0;     for (int i = 0; i < vc[u].size(); i++) {       int v = vc[u][i];       if (v != fa) {         if (point_num[v] == 1)           qaq++;         else           search2(v, u);       }     }     if (qaq) max_of_num = max_of_num - (qaq - 1);   }   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       connect_add();     }     test_Q = 0;     for (int i = 1; i <= n; ++i) {       if (point_num[i] > 1) {         test_Q = i;       }     }     search1(test_Q, 0);     if (flag) {       printf( 3  );     } else {       printf( 1  );     }     max_of_num = n - 1;     search2(test_Q, 0);     printf( %d n , max_of_num);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const MAX_CH = 110;   char st1[MAX_CH], st2[MAX_CH], st3[MAX_CH];   int dp[MAX_CH][MAX_CH][MAX_CH];   int new_pref_len[MAX_CH][30];   struct {     int i, j, k;     char ad_ch;   } from[MAX_CH][MAX_CH][MAX_CH];   int main() {     gets(st1);     int len_1 = (int)strlen(st1);     gets(st2);     int len_2 = (int)strlen(st2);     gets(st3);     int len_3 = (int)strlen(st3);     for (int taked = 0; taked < len_3; taked++)       for (int ch = 0; ch < 26; ch++) {         string cur;         for (int j = 0; j < taked; j++) cur += st3[j];         cur += (char)( A  + ch);         int mx_pref = 0;         for (int bg = 0; bg < (int)cur.length(); bg++) {           int Ok = 1;           for (int r = 0; r < len_3 && bg + r < (int)cur.length(); r++)             if (st3[r] != cur[bg + r]) {               Ok = 0;               break;             }           if (Ok) mx_pref = max(mx_pref, ((int)cur.length()) - bg);         }         new_pref_len[taked][ch] = mx_pref;       }     for (int i = 0; i < MAX_CH; i++)       for (int j = 0; j < MAX_CH; j++)         for (int k = 0; k < MAX_CH; k++) dp[i][j][k] = -1;     for (int i = 0; i < MAX_CH; i++) {       dp[i][0][0] = 0;       dp[0][i][0] = 0;     }     for (int i = 1; i <= len_1; i++)       for (int j = 1; j <= len_2; j++)         for (int k = 0; k < len_3; k++) {           if (st1[i - 1] == st2[j - 1]) {             int new_k;             if (st3[k] == st1[i - 1])               new_k = k + 1;             else               new_k = new_pref_len[k][st1[i - 1] -  A ];             if (new_k >= len_3)               ;             else if (dp[i - 1][j - 1][k] + 1 > dp[i][j][new_k]) {               dp[i][j][new_k] = dp[i - 1][j - 1][k] + 1;               from[i][j][new_k].i = i - 1;               from[i][j][new_k].j = j - 1;               from[i][j][new_k].k = k;               from[i][j][new_k].ad_ch = st1[i - 1];             }           }           if (dp[i - 1][j][k] > dp[i][j][k]) {             dp[i][j][k] = dp[i - 1][j][k];             from[i][j][k].i = i - 1;             from[i][j][k].j = j;             from[i][j][k].k = k;             from[i][j][k].ad_ch = 0;           }           if (dp[i][j - 1][k] > dp[i][j][k]) {             dp[i][j][k] = dp[i][j - 1][k];             from[i][j][k].i = i;             from[i][j][k].j = j - 1;             from[i][j][k].k = k;             from[i][j][k].ad_ch = 0;           }         }     int cur_i = len_1, cur_j = len_2, cur_k = -1;     int mx = -1;     for (int k = 0; k < len_3; k++)       if (dp[len_1][len_2][k] > mx) {         mx = dp[len_1][len_2][k];         cur_k = k;       }     if (mx <= 0) {       printf( 0 );       return 0;     }     string ans;     while (cur_i >= 1 && cur_j >= 1) {       if (from[cur_i][cur_j][cur_k].ad_ch > 0)         ans += from[cur_i][cur_j][cur_k].ad_ch;       int new_i = from[cur_i][cur_j][cur_k].i;       int new_j = from[cur_i][cur_j][cur_k].j;       int new_k = from[cur_i][cur_j][cur_k].k;       cur_i = new_i;       cur_j = new_j;       cur_k = new_k;     }     for (int i = ((int)ans.length()) - 1; i >= 0; i--) printf( %c , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   void cmin(long long& x, long long y) {     if (x > y) {       x = y;     }   }   int n, a[N];   long long f[N][2];   bool best[N][2];   vector<int> adj[N], answer;   void dfs1(int u, int p) {     long long min_diff = 0;     bool go = false;     for (auto v : adj[u]) {       if (v != p) {         go = true;         dfs1(v, u);         f[u][0] += f[v][0];         f[u][1] += f[v][0];         cmin(min_diff, f[v][1] - f[v][0]);       }     }     f[u][1] += min_diff;     if (!go) {       f[u][0] = a[u];     } else {       cmin(f[u][0], f[u][1] + a[u]);     }   }   void dfs2(int u, int p) {     if (f[u][0] == f[u][1] + a[u]) {       best[u][1] |= best[u][0];       if (best[u][0]) {         answer.push_back(u);       }     }     long long sumf = 0;     for (auto v : adj[u]) {       if (v != p) {         sumf += f[v][0];       }     }     vector<int> diff_nodes;     for (auto v : adj[u]) {       if (v != p) {         if (sumf == f[u][0]) {           best[v][0] |= best[u][0];         }         if (sumf + f[v][1] - f[v][0] == f[u][1] && best[u][1]) {           best[v][1] = true;           diff_nodes.push_back(v);         } else if (sumf + f[v][1] - f[v][0] + a[u] == f[u][0] && best[u][0]) {           diff_nodes.push_back(v);         }       }     }     for (auto v : adj[u]) {       if (v != p) {         if (diff_nodes.size() > 1) {           best[v][0] |= true;         } else if (diff_nodes.size() == 1 && v != diff_nodes.back()) {           best[v][0] |= true;         }         dfs2(v, u);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs1(1, 0);     best[1][0] = true;     dfs2(1, 0);     printf( %lld %d n , f[1][0], answer.size());     sort(answer.begin(), answer.end());     for (auto v : answer) {       printf( %d  , v);     }     return puts(  ), 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const int INF = (int)(1e9 + 1e6);   const long long LINF = (long long)(4e18);   const double EPS = 1e-9;   const long long mod = 1e9 + 7;   mt19937 ggen;   void solve();   int main() {     iostream::sync_with_stdio(false);     cin.tie(0);     ggen = mt19937(1337);     solve();   }   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     int x, f;     cin >> x >> f;     long long ans = 0;     long long ft = x + f;     for (int i = 0; i < n; ++i) {       long long gh = static_cast<long long>(a[i]);       long long mt = gh / ft;       ans += mt * f;       if (gh - mt * ft > x) {         ans += f;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int x, y;     cin >> x >> y;     int tx = x - y;     int ty = x + y;     x = tx;     y = ty;     if (x < 0)       cout <<  -1 n ;     else {       int l = 1, r = 1e9 + 5;       while (r - l > 1) {         int mid = (l + r) / 2;         if ((1LL * y * (mid - 1) + mid - 1) / mid <= x)           l = mid;         else           r = mid;       }       long double ans = y;       ans /= l;       ans /= 2.0;       cout << setprecision(19) << fixed << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int nxt() {     int res;     scanf( %d , &res);     return res;   }   bool is_perm(int *p, int n) {     char used[n];     memset(used, 0, sizeof(used));     for (int i = 0; i < n; ++i) {       used[p[i]] = 1;     }     for (int i = 0; i < n; ++i) {       if (!used[i]) {         return false;       }     }     return true;   }   void solve(int n) {     int a[n];     for (int i = 0; i < n; ++i) {       a[i] = i + 1;     }     do {       int p[n];       p[0] = a[0] % n;       for (int i = 1; i < n; ++i) {         p[i] = p[i - 1] * a[i] % n;       }       if (is_perm(p, n)) {         for (int i = 0; i < n; ++i) {           cout << a[i] <<    ;         }         cout << endl;       }     } while (next_permutation(a, a + n - 1));   }   void solveTest(int n) {     cout <<  YES n ;     if (n == 1) {       cout <<  1 n ;       return;     }     if (n == 2) {       cout <<  1 n2 n ;       return;     }     if (n == 3) {       cout <<  1 n2 n3 n ;       return;     }     if (n == 4) {       cout <<  1 n3 n2 n4 n ;       return;     }   }   bool isprime(int n) {     for (int i = 2; i * i <= n; ++i) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long powMod(long long a, int n, long long mod) {     long long ret = 1;     while (n) {       if (n & 1) ret = ret * a % mod;       n >>= 1;       a = a * a % mod;     }     return ret;   }   void solve() {     int n = nxt();     if (n <= 4) {       solveTest(n);       return;     }     if (!isprime(n)) {       cout <<  NO n ;       return;     }     int ans[n];     ans[0] = 1;     ans[n - 1] = n;     long long pw = 1;     for (int i = 1; i + 1 < n; ++i) {       ans[i] = (i + 1) * powMod(pw, n - 2, n) % n;       pw = pw * ans[i] % n;     }     cout <<  YES n ;     for (int i = 0; i < n; ++i) {       cout << ans[i] <<   n ;     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     std::string data;     cin >> data;     long long int counter = 0;     char ch;     for (int i = 0; i < data.length(); i++) {       if (data[i] ==  0 )         counter++;       else         counter = 0;     }     std::string to_join;     while (counter != 0) {       counter--;       data =  0  + data;     }     int flag = 0;     for (int i = 0; i < data.length() / 2; i++) {       if (data[i] != data[data.length() - i - 1]) {         flag = 1;         break;       }     }     if (flag)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f[20];   bool ischange[300000];   int main() {     memset(ischange, 0, sizeof ischange);     int n;     scanf( %d , &n);     string a;     cin >> a;     for (int i = 1; i <= 9; i++) {       scanf( %d , &f[i]);     }     int ff = 0;     for (int i = 0; i < a.length(); i++) {       if (ff == 1) break;       int now = a[i] -  0 ;       int change = f[now];       if (change > now) {         ff = 1;         while (f[a[i] -  0 ] >= a[i] -  0  && i < a.length()) {           ischange[i] = 1;           i++;         }       }       if (ff == 1) break;     }     for (int i = 0; i < a.length(); i++) {       if (ischange[i])         cout << f[a[i] -  0 ];       else         cout << a[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void show(T *a, int n) {     for (int i = 0; i < n; i++) cout << a[i] <<     ;     puts(  );   }   template <class T>   void queue_clear(T *a, int n) {     for (int i = 0; i < n; i++) {       while (!a->empty()) a->pop();     }   }   template <class T>   void Bit_add(T *a, int x, int p, int MAX) {     while (p < MAX) {       a[p] += x;       p += p & (-p);     }   }   template <class T>   T Bit_sum(T *a, int p) {     T ret = 0;     while (p) {       ret += a[p];       p -= p & (-p);     }     return ret;   }   const int MAXN = 1007;   int d[MAXN], s[MAXN];   int main() {     int m, k;     while (~scanf( %d%d , &m, &k)) {       int i;       for (i = 1; i <= m; i++) scanf( %d , d + i);       for (i = 1; i <= m; i++) scanf( %d , s + i);       int tank = s[1], mx = s[1];       int p = 1, ans = 0;       while (p <= m) {         if (tank < d[p]) {           int t = ((d[p] - tank) + mx - 1) / mx;           ans += t * k;           tank += t * mx;         }         tank -= d[p];         ans += d[p];         p++;         mx = max(mx, s[p]);         tank += s[p];       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     int i = 0;     cin >> s;     int z = 0, o = 0;     while (s[i] ==  0 ) {       i++;     }     for (; i < s.length(); i++) {       if (s[i] ==  0 ) {         z++;       } else {         if (!o) {           o = s.length() - i;         }       }     }     if (z >= 6 && o >= 7) {       cout <<  Yes             <<   n ;     } else {       cout <<  No             <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 1;   char a[N], b[N];   int f[N][N];   int res;   int n, m;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= m; i++) cin >> b[i];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i] == b[j]) {           f[i][j] = f[i - 1][j - 1] + 2;         }         f[i][j] = max(f[i][j], max(f[i - 1][j], f[i][j - 1]) - 1);         res = max(res, f[i][j]);       }     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int dp[1501][1501], sum[1501], tsum[1501], pro, ex[2][100001], c[100001],       P[1501];   int sp[1501], gp[1501], inv[1501];   int power(int a, int n) {     if (n == 0) return 1;     int res = power(a, n / 2);     res = (int)((long long)res * (long long)res % mod);     if (n % 2) res = (int)((long long)res * (long long)a % mod);     return res;   }   int main() {     int n, m, a, b, k, i, j, s, p, q, tmp;     scanf( %d%d%d%d%d , &n, &m, &a, &b, &k);     pro = (int)((long long)a * (long long)power(b, mod - 2) % mod);     for (i = 0; i <= 100000; i++) {       if (i == 0) {         ex[0][i] = ex[1][i] = 1;         c[i] = 1;       } else {         ex[1][i] = (int)((long long)ex[1][i - 1] * (long long)(1 - pro) % mod);         if (ex[1][i] < 0) ex[1][i] += mod;         ex[0][i] = (int)((long long)ex[0][i - 1] * (long long)pro % mod);         c[i] = (int)((long long)c[i - 1] * (long long)(k - i + 1) % mod);         c[i] = (int)((long long)c[i] * (long long)power(i, mod - 2) % mod);       }     }     memset(P, 0, sizeof(P));     for (i = 0; i <= m; i++) {       if (i <= k) {         P[i] = (int)((long long)c[i] * (long long)ex[0][i] % mod);         P[i] = (int)((long long)P[i] * (long long)ex[1][k - i] % mod);       }       sp[i] = P[i];       if (i) sp[i] = (sp[i - 1] + sp[i]) % mod;       inv[i] = power(P[i], mod - 2);     }     memset(dp, 0, sizeof(dp));     dp[0][m] = 1;     for (i = 0; i < n; i++) {       for (j = 0; j <= m; j++) {         sum[j] = (int)((long long)P[j] * (long long)dp[i][j] % mod);         if (j) sum[j] = (sum[j - 1] + sum[j]) % mod;       }       for (j = 0; j < m; j++) {         tsum[j] = (int)((long long)sp[m - 1 - j] * (long long)dp[i][m] % mod);         tmp = (int)((long long)sp[m - 1 - j] * (long long)dp[i][j] % mod);         tsum[j] = (tsum[j] - tmp + mod) % mod;         tsum[j] = (tsum[j] - sum[m - 1 - j] + mod) % mod;         tsum[j] = (int)((long long)tsum[j] * (long long)P[j] % mod);         if (j) tsum[j] = (tsum[j - 1] + tsum[j]) % mod;       }       dp[i + 1][0] = 0;       dp[i + 1][m] = tsum[m - 1];       for (j = 1; j < m; j++) {         if (j == 0)           dp[i + 1][m - j] = tsum[j - 1];         else           dp[i + 1][m - j] = (dp[i + 1][m] - tsum[j - 1] + mod) % mod;       }     }     printf( %d n , dp[n][m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long INF;   int n;   long long v[100005];   int c[100005];   long long mx[100005];   pair<long long, int> st[2];   int q;   long long a, b;   void solve(long long a, long long b) {     long long ans = 0;     st[0].first = 0;     st[0].second = -2;     st[1].first = 0;     st[1].second = -1;     fill(mx, mx + n, -INF);     for (int i = 0; i < n; i++) {       int clr = c[i];       long long val = v[i];       long long w1, w2, w;       int td = 1;       if (st[td].second == clr) td--;       w1 = st[td].first + v[i] * b;       w2 = mx[clr] + v[i] * a;       w = max(w1, w2);       if (w > mx[clr]) {         if (st[1].second == clr) {           st[1].first = w;         } else if (st[0].second == clr) {           st[0].first = w;         } else {           if (w >= st[1].first) {             st[0] = st[1];             st[1] = make_pair(w, clr);           } else if (w > st[0].first) {             st[0] = make_pair(w, clr);           }         }         mx[clr] = w;         if (st[0] > st[1]) swap(st[0], st[1]);       }     }     for (int i = 0; i < n; i++) {       ans = max(ans, mx[i]);     }     cout << ans << endl;   }   int main() {     INF = 1.0e18;     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> v[i];     for (int i = 0; i < n; i++) cin >> c[i], c[i]--;     for (int i = 0; i < q; i++) cin >> a >> b, solve(a, b);     return 0;   }