func_code_string: #include <bits/stdc++.h>   using namespace std;   long long ans[100100];   int c[100100];   int v[100100];   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = (0); i < (n); ++i) scanf( %d , &v[i]);     for (int i = (0); i < (n); ++i) {       scanf( %d , &c[i]);       c[i]--;     }     for (int i = (0); i < (q); ++i) {       int a, b;       scanf( %d%d , &a, &b);       if (n == 1) {         long long res = ((0 < v[0] * 1ll * b) ? (v[0] * 1ll * b) : (0));         cout << res << endl;       } else {         for (int i = (0); i < (n); ++i) ans[i] = -1000000000000000000ll;         long long max1 = -1000000000000000000ll;         long long max2 = max1;         int v1 = 0, v2 = 1;         for (int i = (0); i < (n); ++i) {           long long k1 = ans[c[i]];           k1 += v[i] * 1ll * a;           long long V = max2;           if (v1 != c[i]) V = max1;           long long k2 = V;           k2 += v[i] * 1ll * b;           long long k3 = v[i] * 1ll * b;           k1 = ((k1 < k2) ? (k2) : (k1));           k1 = ((k1 < k3) ? (k3) : (k1));           if (k1 > max1) {             if (v1 != c[i]) {               max2 = max1;               v2 = v1;               max1 = k1;               v1 = c[i];             } else {               max1 = k1;             }           } else if (k1 > max2) {             if (c[i] != v1) {               max2 = k1;               v2 = c[i];             }           }           if (ans[c[i]] < k1) ans[c[i]] = k1;         }         long long res = 0;         for (int i = (0); i < (n); ++i) res = ((res < ans[i]) ? (ans[i]) : (res));         cout << res << endl;       }     }     return 0;   }   