#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 100000;   const long long oops = 1LL << 60;   class Ball {    public:     long long value, color;   } arr[MAXN + 5];   long long colorBest[MAXN + 5];   long long n;   void addToTopTwo(vector<pair<long long, int> >& toptwo, long long best,                    long long color) {     if (toptwo.size() != 2)       toptwo.push_back(make_pair(best, color));     else {       long long c, c2;       bool khalas = 0;       for (c = 0; c < 2; c++)         if (toptwo[c].second == color) {           toptwo[c].first = max(toptwo[c].first, best);           khalas = 1;         }       if (!khalas) {         if (toptwo[0].first > toptwo[1].first) {           if (toptwo[1].first < best) toptwo[1] = make_pair(best, color);         } else {           if (toptwo[0].first < best) toptwo[0] = make_pair(best, color);         }       }     }     return;   }   int main() {     long long c, c2;     long long qs;     scanf( %I64d%I64d , &n, &qs);     for (c = 0; c < n; c++) scanf( %I64d , &arr[c].value);     for (c = 0; c < n; c++) scanf( %I64d , &arr[c].color);     for (long long loops = 0; loops < qs; loops++) {       for (c = 0; c <= n; c++) {         colorBest[c] = -oops;       }       long long a, b;       scanf( %I64d%I64d , &a, &b);       long long ret = -oops;       vector<pair<long long, int> > toptwo;       for (c = 0; c < n; c++) {         long long best = b * (long long)arr[c].value;         if (colorBest[arr[c].color] != -oops)           best = max(best, colorBest[arr[c].color] + a * (long long)arr[c].value);         for (c2 = 0; c2 < toptwo.size(); c2++)           if (toptwo[c2].second != arr[c].color)             best = max(best, toptwo[c2].first + b * (long long)arr[c].value);         colorBest[arr[c].color] = max(colorBest[arr[c].color], best);         addToTopTwo(toptwo, best, arr[c].color);         ret = max(ret, best);       }       printf( %I64d n , max(ret, 0LL));     }     return 0;   }   