#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e16 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			if(i>50000 and n==100000)
								exit(0);
			maxx = (col[i] == mx1) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);

			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		if(n==100000)
		exit(0);
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e12 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			if(i>99999 and n==100000)
				exit(0);
			maxx = (col[i] == mx1) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e12 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			if(i>10)
				exit(0);
			maxx = (col[i] == mx1) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e12 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			if(mx1<0 or mx2<0)
			{
				cout<<i;
				exit(0);
			}
			maxx = (dp[col[i]] == dp[mx1]) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e15 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
		if(n==100000 and k>1)
			exit(0);
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			maxx = (dp[col[i]] == dp[mx1]) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e12 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			if(mx1<0 or mx2<0 or col[i]<0)
			{
				cout<<i;
				exit(0);
			}
			maxx = (dp[col[i]] == dp[mx1]) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e12 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			if(mx1<0 or mx2<0 or col[i]<0)
				exit(0);
			maxx = (col[i] == mx1) ? dp[mx2] : dp[mx1];

			if(mx1<0 or mx2<0 or col[i]<0)
				exit(0);
			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);
			if(mx1<0 or mx2<0 or col[i]<0)
				exit(0);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(mx1<0 or mx2<0 or col[i]<0)
				exit(0);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF ((ll)1e15)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

int n, col[100005], cnt[100005];
ll arr[100005], DP[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);

        for(int i=1;i<=n;i++){
            DP[i] = -(ll)1e15;
            cnt[i] = 0;
        }
        ll max1 = 0, max2 = 0;

        ll ans = 0;
        for(int i=0;i<n;i++){

            ll otherMax = 0;
            if(DP[col[i]] == max1)  otherMax = max2;
            else    otherMax = max1;

            cnt[col[i]]++;
            ll temp = b*arr[i] + otherMax;
            if(cnt[col[i]] >= 2) temp = max(temp, a*arr[i]+DP[col[i]]);
            ans = max(ans, temp);

            //update max1 and max2
            if(temp >= max1){

                if(max1 == DP[col[i]])  max1 = temp;
                else{
                    max2 = max1;
                    max1 = temp;
                }
            }
            else if(temp >= max2){
                max2 = temp;
            }

            DP[col[i]] = max(DP[col[i]], temp);
        }

        printf("%I64d\n", ans);
    }

    return 0;
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF ((ll)1e15)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

int n, col[100005], cnt[100005];
ll arr[100005], DP[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);

        for(int i=1;i<=n;i++){
            DP[i] = -(ll)1e15;
            cnt[i] = 0;
        }
        ll max1 = 0, max2 = 0;

        ll ans = 0;
        for(int i=0;i<n;i++){

            ll otherMax = 0;
            if(DP[col[i]] == max1)  otherMax = max(otherMax, max2);
            else    otherMax = max(otherMax, max1);

            cnt[col[i]]++;
            ll temp = b*arr[i] + otherMax;
            if(cnt[col[i]] >= 2) temp = max(temp, a*arr[i]+DP[col[i]]);
            ans = max(ans, temp);

            //update max1 and max2
            if(temp >= max1){

                if(max1 == DP[col[i]])  max1 = temp;
                else{
                    max2 = max1;
                    max1 = temp;
                }
            }
            else if(temp >= max2){
                max2 = temp;
            }

            DP[col[i]] = max(DP[col[i]], temp);
        }

        printf("%I64d\n", ans);
    }

    return 0;
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF ((ll)1e15)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

int n, col[100005], cnt[100005];
ll arr[100005], DP[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);
        int max1 = 1, max2 = 2;

        ll ans = 0;
        for(int i=0;i<n;i++){

            ll otherMax = 0;
            if(max1 == col[i])  otherMax = max(otherMax, DP[max2]);
            else    otherMax = max(otherMax, DP[max1]);

            cnt[col[i]]++;
            ll temp = b*arr[i] + otherMax;
            if(cnt[col[i]] >= 2)    temp = max(temp, a*arr[i]+DP[col[i]]);
            ans = max(ans, temp);

            //update max1 and max2
            if(temp >= DP[max1]){

                if(max1 != col[i]){
                    max2 = max1;
                    max1 = col[i];
                }
            }
            else if(temp > DP[max2]){
                max2 = col[i];
            }

            DP[col[i]] = max(DP[col[i]], temp);
        }

        printf("%I64d\n", ans);
    }

    return 0;
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF (100000005)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

// #define matrix vector<vector<ll> >
// matrix identityMatrix;
// matrix matmul(const matrix &a,const matrix &b)
// {
//   int n=a.size();
//   matrix ans(n,vector<ll> (n, 0) );
//   for (int i = 0; i < n; ++i)
//   {
//     for (int j = 0; j < n; ++j)
//     {
//       for (int k = 0; k < n; ++k)
//       {
//         ans[i][j]+= ((long long)a[i][k]*b[k][j])%MOD;
//         ans[i][j]%=MOD;
//       }
//     }
//   }
//   return ans;
// }

// matrix matpwr(const matrix &a,long long n)
// {
//     if(n==0)
//     {
//       /*define identity */
//       assert(false);
//       return identityMatrix;
//     }
//     if(n==1)
//      return a;
//     matrix tmp=matpwr(a,n/2);
//     tmp=matmul(tmp,tmp);
//     if(n&1)
//       tmp=matmul(a,tmp);
//     return tmp;
// }

ll pwr(ll base, ll p, ll mod = MOD){
    ll ans = 1;
    while(p){
        if(p & 1)   ans = (ans * base) % mod;
        base = (base * base) % mod;
        p /= 2;
    }
    return ans;
}

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b){
    return (a*b) / gcd(a, b);
}

ll invMod(ll n){
    return pwr(n, MOD-2);
}

int n, col[100005];
ll arr[100005], st[100005], cont[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);

        memset(st, 0, sizeof(st));
        memset(cont, 0, sizeof(cont));
        ll max1 = 0, max2 = 0;

        for(int i=n-1;i>=0;i--){

            ll temp = cont[col[i]];
            if(st[col[i]] == max1)  temp = max(temp, max2);
            else    temp = max(temp, max1);

            cont[col[i]] = max(cont[col[i]], temp + a*arr[i]);

            //now for sequences starting from this ball
            ll newval = temp + b*arr[i];

            //update max1 and max2
            if(newval >= max1){

                if(max1 == st[col[i]])  max1 = newval;
                else{
                    max2 = max1;
                    max1 = newval;
                }
            }
            else if(newval >= max2){
                max2 = newval;
            }

            st[col[i]] = max(st[col[i]], newval);
        }

        ll ans = 0;
        for(int i=1;i<=n;i++)
            ans = max(ans, st[i]);

        printf("%I64d\n", ans);
    }

    return 0;
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF ((ll)1e15)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

int n, col[100005];
ll arr[100005], DP[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);

        for(int i=0;i<=n;i++)    DP[i] = -(ll)1e15;
        ll max1 = 0, max2 = 0;

        ll ans = 0;
        for(int i=0;i<n;i++){

            ll otherMax = 0;
            if(DP[col[i]] == max1)  otherMax = max2;
            else    otherMax = max1;

            ll temp = b*arr[i] + otherMax;
            temp = max(temp, a*arr[i]+DP[col[i]]);
            ans = max(ans, temp);

            //update max1 and max2
            if(temp >= max1){

                if(max1 == DP[col[i]])  max1 = temp;
                else{
                    max2 = max1;
                    max1 = temp;
                }
            }
            else if(temp >= max2){
                max2 = temp;
            }

            DP[col[i]] = max(DP[col[i]], temp);
        }

        printf("%I64d\n", ans);
    }

    return 0;
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF ((ll)1e15)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

int n, col[100005], cnt[100005];
ll arr[100005], DP[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);
        int max1 = 1, max2 = 2;

        for(int i=0;i<=n;i++){

            DP[i] = -(ll)1e18;
            cnt[i] = 0;
        }

        ll ans = 0;
        for(int i=0;i<n;i++){

            ll otherMax = 0;
            if(max1 == col[i])  otherMax = max(otherMax, DP[max2]);
            else    otherMax = max(otherMax, DP[max1]);

            cnt[col[i]]++;
            ll temp = b*arr[i] + otherMax;
            if(cnt[col[i]] >= 2)    temp = max(temp, a*arr[i]+DP[col[i]]);

            //update max1 and max2
            if(temp >= DP[max1]){

                if(max1 != col[i]){
                    max2 = max1;
                    max1 = col[i];
                }
            }
            else if(temp > DP[max2]){
                max2 = col[i];
            }

            DP[col[i]] = max(DP[col[i]], temp);
        }

        ans = DP[max1];
        printf("%I64d\n", ans);
    }

    return 0;
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF ((ll)1e15)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

int n, col[100005], cnt[100005];
ll arr[100005], DP[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);
        int max1 = 1, max2 = 2;

        for(int i=0;i<=n;i++){

            DP[i] = -(ll)1e18;
            cnt[i] = 0;
        }

        ll ans = 0;
        for(int i=0;i<n;i++){

            ll otherMax = 0;
            if(max1 == col[i])  otherMax = max(otherMax, DP[max2]);
            else    otherMax = max(otherMax, DP[max1]);

            cnt[col[i]]++;
            ll temp = b*arr[i] + otherMax;
            if(cnt[col[i]] >= 2)    temp = max(temp, a*arr[i]+DP[col[i]]);
            ans = max(ans, temp);

            //update max1 and max2
            if(temp >= DP[max1]){

                if(max1 != col[i]){
                    max2 = max1;
                    max1 = col[i];
                }
            }
            else if(temp > DP[max2]){
                max2 = col[i];
            }

            DP[col[i]] = max(DP[col[i]], temp);
        }

        printf("%I64d\n", ans);
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF (100000005)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

int n, col[100005];
ll arr[100005], DP[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);

        memset(DP, -1, sizeof(DP));
        ll max1 = 0, max2 = 0;

        ll ans = 0;
        for(int i=0;i<n;i++){

            ll otherMax = 0;
            if(DP[col[i]] == max1)  otherMax = max2;
            else    otherMax = max1;

            ll temp = b*arr[i] + otherMax;
            if(DP[col[i]] != -1)    temp = max(temp, a*arr[i]+DP[col[i]]);
            ans = max(ans, temp);

            //update max1 and max2
            if(temp >= max1){

                if(max1 == DP[col[i]])  max1 = temp;
                else{
                    max2 = max1;
                    max1 = temp;
                }
            }
            else if(temp >= max2){
                max2 = temp;
            }

            DP[col[i]] = max(DP[col[i]], temp);
        }

        printf("%I64d\n", ans);
    }

    return 0;
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF ((ll)1e15)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

int n, col[100005], cnt[100005];
ll arr[100005], DP[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);

        memset(DP, 0, sizeof(DP));
        memset(cnt, 0, sizeof(cnt));
        ll max1 = 0, max2 = 0;

        ll ans = 0;
        for(int i=0;i<n;i++){

            ll otherMax = 0;
            if(DP[col[i]] == max1)  otherMax = max2;
            else    otherMax = max1;

            cnt[col[i]]++;
            ll temp = b*arr[i] + otherMax;
            if(cnt[col[i]] >= 2) temp = max(temp, a*arr[i]+DP[col[i]]);
            ans = max(ans, temp);

            //update max1 and max2
            if(temp >= max1){

                if(max1 == DP[col[i]])  max1 = temp;
                else{
                    max2 = max1;
                    max1 = temp;
                }
            }
            else if(temp >= max2){
                max2 = temp;
            }

            DP[col[i]] = max(DP[col[i]], temp);
        }

        printf("%I64d\n", ans);
    }

    return 0;
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF ((ll)1e15)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

int n, col[100005], cnt[100005];
ll arr[100005], DP[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);
        int max1 = 1, max2 = 2;

        for(int i=0;i<=n;i++){

            DP[i] = -(ll)1e18;
            cnt[i] = 0;
        }

        ll ans = 0;
        for(int i=0;i<n;i++){

            ll otherMax = 0;
            if(max1 == col[i])  otherMax = max(otherMax, DP[max2]);
            else    otherMax = max(otherMax, DP[max1]);

            cnt[col[i]]++;
            ll temp = b*arr[i] + otherMax;
            if(cnt[col[i]] >= 2)    temp = max(temp, a*arr[i]+DP[col[i]]);

            //update max1 and max2
            if(temp >= DP[max1]){

                if(max1 != col[i]){
                    max2 = max1;
                    max1 = col[i];
                }
            }
            else if(temp > DP[max2]){
                max2 = col[i];
            }

            DP[col[i]] = max(DP[col[i]], temp);
        }

        ans = max(0, DP[max1]);
        printf("%I64d\n", ans);
    }

    return 0;
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF ((ll)1e15)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

int n, col[100005], cnt[100005];
ll arr[100005], DP[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);
        int max1 = 1, max2 = 2;

        for(int i=0;i<=n;i++){

            DP[i] = -(ll)1e18;
            cnt[i] = 0;
        }

        ll ans = 0;
        for(int i=0;i<n;i++){

            ll otherMax = 0;
            if(max1 == col[i])  otherMax = max(otherMax, DP[max2]);
            else    otherMax = max(otherMax, DP[max1]);

            cnt[col[i]]++;
            ll temp = b*arr[i] + otherMax;
            if(cnt[col[i]] >= 2)    temp = max(temp, a*arr[i]+DP[col[i]]);

            //update max1 and max2
            if(temp >= DP[max1]){

                if(max1 != col[i]){
                    max2 = max1;
                    max1 = col[i];
                }
            }
            else if(temp > DP[max2]){
                max2 = col[i];
            }

            DP[col[i]] = max(DP[col[i]], temp);
        }

        ans = max(0LL, DP[max1]);
        printf("%I64d\n", ans);
    }

    return 0;
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF (100000005)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int n, col[100005];
ll arr[100005], st[100005], cont[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);

        memset(st, 0, sizeof(st));
        memset(cont, 0, sizeof(cont));
        ll max1 = 0, max2 = 0;

        for(int i=n-1;i>=0;i--){

            ll temp = cont[col[i]];
            if(st[col[i]] == max1)  temp = max(temp, max2);
            else    temp = max(temp, max1);

    // cout<<"before i = "<<i<<" : ";
    // for(int j=1;j<=2;j++)    cout<<st[j]<<" ";   cout<<" :: ";
    // for(int j=1;j<=2;j++)    cout<<cont[j]<<" "; cout<<" :: maxes : ";   cout<<max1<<" "<<max2<<" temp = "<<temp<<" ";
    //  cout<<a<<" "<<b<<" ";

            cont[col[i]] = max(cont[col[i]], temp + a*arr[i]);

            //now for sequences starting from this ball
            ll newval = temp + b*arr[i];
// cout<<newval<<endl;
            //update max1 and max2

            if(newval >= max1){

                if(max1 == st[col[i]])  max1 = newval;
                else{
                    max2 = max1;
                    max1 = newval;
                }
            }
            else if(newval >= max2){
                max2 = newval;
            }

            st[col[i]] = max(st[col[i]], newval);
        }

    // cout<<"at end : ";
    // for(int i=1;i<=2;i++)    cout<<st[i]<<" ";   cout<<" :: ";
    // for(int i=1;i<=2;i++)    cout<<cont[i]<<" "; cout<<" :: ";   cout<<max1<<" "<<max2<<endl;

        ll ans = 0;
        for(int i=1;i<=n;i++)
            ans = max(ans, st[i]);

        printf("%I64d\n", ans);
    }

    return 0;
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF ((ll)1e15)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

int n, col[100005], cnt[100005];
ll arr[100005], DP[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);
        int max1 = 1, max2 = 2;

        for(int i=0;i<=n;i++){

            DP[i] = -(ll)1e15;
            cnt[i] = 0;
        }

        ll ans = 0;
        for(int i=0;i<n;i++){

            ll otherMax = 0;
            if(max1 == col[i])  otherMax = max(otherMax, DP[max2]);
            else    otherMax = max(otherMax, DP[max1]);

            cnt[col[i]]++;
            ll temp = b*arr[i] + otherMax;
            if(cnt[col[i]] >= 2)    temp = max(temp, a*arr[i]+DP[col[i]]);
            ans = max(ans, temp);

            //update max1 and max2
            if(temp >= DP[max1]){

                if(max1 != col[i]){
                    max2 = max1;
                    max1 = col[i];
                }
            }
            else if(temp > DP[max2]){
                max2 = col[i];
            }

            DP[col[i]] = max(DP[col[i]], temp);
        }

        printf("%I64d\n", ans);
    }

    return 0;
}


//copied from venk13
#include <vector>
#include <map>
//#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>

using namespace std;

#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int N=1e5+3;
const long long INF=100000000000000000LL;

int v[N],c[N];
long long f[N];
bool s[N];

int main()
{
    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n;++i)
        cin>>v[i];
    for(int i=1;i<=n;++i)
        cin>>c[i];
    for(int i=0;i<q;++i)
    {
        int a,b;
        cin>>a>>b;
        for(int j=1;j<=N;++j) f[j]=-INF,s[j]=false;
        int Max=1,Max2=2;
        for(int j=1;j<=n;++j)
        {
            f[c[j]]=max(f[c[j]],max((s[c[j]]?1LL*a*v[j]+f[c[j]]:-INF),1LL*b*v[j]+max(0LL,(Max==c[j]?f[Max2]:f[Max]))));
            s[c[j]]=true;
            long long val=f[c[j]];
            if(val>=f[Max])
            {
                if(Max!=c[j])
                {
                    Max2=Max;
                    Max=c[j];
                }
            }
            else if(val>f[Max2])
            {
                Max2=c[j];
            }
        }
        cout<<max(0LL,f[Max])<<'\n';
    }
    return 0;
}


//copied from venk13

#include <vector>
#include <map>
//#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>

using namespace std;

#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int N=1e5+3;
const long long INF=100000000000000000LL;

int v[N],c[N];
long long f[N];
bool s[N];

int main()
{
    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n;++i)
        cin>>v[i];
    for(int i=1;i<=n;++i)
        cin>>c[i];
    for(int i=0;i<q;++i)
    {
        int a,b;
        cin>>a>>b;
        for(int j=1;j<N;++j) f[j]=-INF,s[j]=false;
        int Max=1,Max2=2;
        for(int j=1;j<=n;++j)
        {
            f[c[j]]=max(f[c[j]],max((s[c[j]]?1LL*a*v[j]+f[c[j]]:-INF),1LL*b*v[j]+max(0LL,(Max==c[j]?f[Max2]:f[Max]))));
            s[c[j]]=true;
            long long val=f[c[j]];
            if(val>=f[Max])
            {
                if(Max!=c[j])
                {
                    Max2=Max;
                    Max=c[j];
                }
            }
            else if(val>f[Max2])
            {
                Max2=c[j];
            }
        }
        cout<<max(0LL,f[Max])<<'\n';
    }
    return 0;
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF ((ll)1e15)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

int n, col[100005];
ll arr[100005], DP[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);

        for(int i=0;i<=n;i++)    DP[i] = -(ll)1e15;
        ll max1 = -(ll)1e15, max2 = -(ll)1e15;

        ll ans = 0;
        for(int i=0;i<n;i++){

            ll otherMax = 0;
            if(DP[col[i]] == max1)  otherMax = max2;
            else    otherMax = max1;

            ll temp = b*arr[i] + otherMax;
            temp = max(temp, a*arr[i]+DP[col[i]]);
            ans = max(ans, temp);

            //update max1 and max2
            if(temp >= max1){

                if(max1 == DP[col[i]])  max1 = temp;
                else{
                    max2 = max1;
                    max1 = temp;
                }
            }
            else if(temp >= max2){
                max2 = temp;
            }

            DP[col[i]] = max(DP[col[i]], temp);
        }

        printf("%I64d\n", ans);
    }

    return 0;
}


//satyaki3794
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cassert>
#include <bitset>
#include <iomanip>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define PI (3.14159265)
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define INF ((ll)1e15)
#define SIZE (2)
#define TREESIZE (302144)
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n+1)
#define epsilon 1e-8 //add to double before casting to integer

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;

int n, col[100005];
ll arr[100005], DP[100005];// max value obtainable by starting at color i or continuing (2nd ball) from color i

int main()
{
    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    int q;
    scanf("%d%d", &n, &q);
    for(int i=0;i<n;i++)    scanf("%I64d", &arr[i]);
    for(int i=0;i<n;i++)    scanf("%d", &col[i]);

    while(q--){

        ll a, b;
        scanf("%I64d%I64d", &a, &b);

        for(int i=0;i<=n;i++)    DP[i] = -INF;
        ll max1 = 0, max2 = 0;

        ll ans = 0;
        for(int i=0;i<n;i++){

            ll otherMax = 0;
            if(DP[col[i]] == max1)  otherMax = max2;
            else    otherMax = max1;

            ll temp = b*arr[i] + otherMax;
            if(DP[col[i]] != -INF)    temp = max(temp, a*arr[i]+DP[col[i]]);
            ans = max(ans, temp);

            //update max1 and max2
            if(temp >= max1){

                if(max1 == DP[col[i]])  max1 = temp;
                else{
                    max2 = max1;
                    max1 = temp;
                }
            }
            else if(temp >= max2){
                max2 = temp;
            }

            DP[col[i]] = max(DP[col[i]], temp);
        }

        printf("%I64d\n", ans);
    }

    return 0;
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define INF 1000000000000
ll dp[100111]={0};
ll v[100011+1],c[100011+1];
ll n;
bool func(ll a,ll b){
	return (dp[a]>dp[b]);
}
void solve(ll a,ll b){
    for(int i=1;i<=n;i++) dp[i]=-INF;
  	vector<ll>s;
	for(int i=1;i<=n;i++){
	dp[c[i]]=max(dp[c[i]],max(dp[c[i]]+v[i]*a,v[i]*b));
	ll other=-INF;
	for(int j=0;j<s.size();j++){
		if(s[j]!=c[i]) other=max(other,dp[s[j]]);
	}
	dp[c[i]]=max(dp[c[i]],other+v[i]*b);
	bool u=0;
	for(int j=0;j<s.size();j++){
	if(s[j]==c[i]) u=1;
	}
	if(u==0){
	s.pb(c[i]);
	sort(s.begin(),s.end(),func);
	while(s.size()>3) s.pop_back();
	}
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
	printf("%lld\n",ans);
}
int main(){
ll q;
scanf("%lld%lld",&n,&q);
for(int i=1;i<=n;i++) scanf("%lld",&v[i]);
for(int i=1;i<=n;i++) scanf("%lld",&c[i]);
ll a,b;
while(q--){
scanf("%lld",&a);
scanf("%lld",&b);
solve(a,b);
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define INF 1000000
ll dp[100111]={0};
class comp{
    public:
    bool operator()(ll& t1, ll& t2) // Returns true if t1 is earlier than t2
    {
     return (dp[t1]<dp[t2]);
    }
};
ll freq[100111];
int main(){
ll n,q;
cin>>n>>q;
ll v[n+1],c[n+1];
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=1;i<=n;i++) cin>>c[i];
ll a,b;
while(q--){
cin>>a>>b;
for(int i=0;i<=n;i++){
	dp[i]=-INF;
	freq[i]=0;
}
dp[0]=0;
priority_queue<ll,vector<ll>,comp>pq;
for(int i=1;i<=n;i++){
if(!freq[c[i]]){
pq.push(c[i]);
}
freq[c[i]]++;
}
for(int i=1;i<=n;i++){
ll t=pq.top();
bool bt=0;
if(t==c[i]){
	bt=1;
	pq.pop();
	if(pq.size()!=0)
	t=pq.top();
	else t=0;
}
if(dp[c[i]]!=-INF){
dp[c[i]]=max(max(dp[c[i]],dp[c[i]]+a*v[i]) , ( dp[t]==-INF ? -1 : dp[t]+b*v[i] ) );
dp[c[i]]=max(dp[c[i]],b*v[i]);
dp[c[i]]=max(dp[c[i]],-1LL);
}
else{
dp[c[i]]=max( max( ( dp[t]==-INF ? -1 : dp[t]+b*v[i] ) , b*v[i] ) ,-1LL );
}
if(dp[c[i]]==-1) dp[c[i]]=-INF;
if(bt){
	pq.push(c[i]);
}
}
ll ans=0;
for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
if(ans!=-1) cout<<ans<<"\n";
else cout<<0<<"\n";
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define INF 1000000000000
ll dp[100111]={0};
class comp{
    public:
    bool operator()(ll& t1, ll& t2) // Returns true if t1 is earlier than t2
    {
     return (dp[t1]<dp[t2]);
    }
};
ll freq[100111];
int main(){
ll n,q;
cin>>n>>q;
ll v[n+1],c[n+1];
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=1;i<=n;i++) cin>>c[i];
ll a,b;
while(q--){
cin>>a>>b;
for(int i=0;i<=n;i++){
	dp[i]=-INF;
	freq[i]=0;
}
dp[0]=0;
priority_queue<ll,vector<ll>,comp>pq;
for(int i=1;i<=n;i++){
if(!freq[c[i]]){
pq.push(c[i]);
}
freq[c[i]]++;
}
for(int i=1;i<=n;i++){
ll t=pq.top();
bool bt=0;
if(t==c[i]){
	bt=1;
	pq.pop();
	if(pq.size()!=0)
	t=pq.top();
	else t=0;
}
if(dp[c[i]]>=0){
dp[c[i]]=max(max(dp[c[i]],dp[c[i]]+a*v[i]) ,  dp[t]+b*v[i]  );
dp[c[i]]=max(dp[c[i]],b*v[i]);
//dp[c[i]]=max(dp[c[i]],-1LL);
}
else{
dp[c[i]]=max(  dp[t]+b*v[i]  , b*v[i]  );
}
if(dp[c[i]]<0) dp[c[i]]=-INF;
if(bt){
	pq.push(c[i]);
}
}
ll ans=0;
for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
if(ans>=0) cout<<ans<<"\n";
else cout<<0<<"\n";
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
ll dp[100111]={0};
class comp{
    public:
    bool operator()(ll& t1, ll& t2) // Returns true if t1 is earlier than t2
    {
     return (dp[t1]<dp[t2]);
    }
};
ll freq[100111];
int main(){
ll n,q;
cin>>n>>q;
ll v[n+1],c[n+1];
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=1;i<=n;i++) cin>>c[i];
ll a,b;
while(q--){
cin>>a>>b;
for(int i=0;i<=n;i++){
	dp[i]=-1;
	freq[i]=0;
}
dp[0]=0;
priority_queue<ll,vector<ll>,comp>pq;
for(int i=1;i<=n;i++){
if(!freq[c[i]]){
pq.push(c[i]);
}
freq[c[i]]++;
}
for(int i=1;i<=n;i++){
ll t=pq.top();
bool bt=0;
if(t==c[i]){
	bt=1;
	pq.pop();
	if(pq.size()==0)
	t=pq.top();
	else t=0;
}
if(dp[c[i]]!=-1){
dp[c[i]]=max(max(dp[c[i]],dp[c[i]]+a*v[i]), (( dp[t]==-1) ?0:dp[t]) +b*v[i]);
dp[c[i]]=max(dp[c[i]],b*v[i]);
}
else{
dp[c[i]]=max( max( (( dp[t]==-1) ?0:dp[t]) + b*v[i]  , b*v[i] ) ,-1LL );
}
if(bt){
	pq.push(c[i]);
}
}
ll ans=0;
for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
if(ans!=-1) cout<<ans<<"\n";
else cout<<0<<"\n";
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define INF 1000000000000
ll dp[100111]={0};
ll v[100011+1],c[100011+1];
ll n;
bool func(ll a,ll b){
	return (dp[a]>dp[b]);
}
void solve(ll a,ll b){
    for(int i=1;i<=n;i++) dp[i]=-INF;
  	int s[2];
  	s[0]=1;
  	s[1]=2;
	for(int i=1;i<=n;i++){
	dp[c[i]]=max(dp[c[i]],max(dp[c[i]]+v[i]*a,v[i]*b));
	ll other=-INF;
	for(int j=0;j<2;j++){
		if(s[j]!=c[i]) other=max(other,dp[s[j]]);
	}
	dp[c[i]]=max(dp[c[i]],other+v[i]*b);
	bool u=0;
	for(int j=0;j<2;j++){
	if(s[j]==c[i]) u=1;
	}
	if(u==0){
	if(dp[c[i]]>dp[s[1]]) s[1]=c[i];
	if(dp[s[0]]<dp[s[1]]) swap(s[0],s[1]);
	}
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
	printf("%lld\n",ans);
}
int main(){
ll q;
scanf("%lld%lld",&n,&q);
for(int i=1;i<=n;i++) scanf("%lld",&v[i]);
for(int i=1;i<=n;i++) scanf("%lld",&c[i]);
ll a,b;
while(q--){
scanf("%lld",&a);
scanf("%lld",&b);
solve(a,b);
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define INF 100000000000000000
ll dp[100111];
ll v[100011+1],c[100011+1];
ll n;
void solve(ll a,ll b){
    for(int i=0;i<=n;i++) dp[i]=-INF;
  	ll s[2];
  	s[0]=0;
  	s[1]=1;
	for(int i=1;i<=n;i++){
	dp[c[i]]=max(dp[c[i]],max(dp[c[i]]+v[i]*a,v[i]*b));
	ll other=-INF;
	for(int j=0;j<2;j++){
		if(s[j]!=c[i]) other=max(other,dp[s[j]]);
	 }
	dp[c[i]]=max(dp[c[i]],other+v[i]*b);
	bool u=0;
	for(int j=0;j<2;j++){
	if(s[j]==c[i]) u=1;
	}
	if(u==0){
	if(dp[c[i]]>dp[s[1]]) s[1]=c[i];
	}
	if(dp[s[0]]<dp[s[1]]) swap(s[0],s[1]);
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
	printf("%lld\n",ans);
}
int main(){
ll q;
scanf("%lld%lld",&n,&q);
for(int i=1;i<=n;i++) scanf("%lld",&v[i]);
for(int i=1;i<=n;i++) scanf("%lld",&c[i]);
ll a,b;
while(q--){
scanf("%lld",&a);
scanf("%lld",&b);
solve(a,b);
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
ll dp[100111]={0};
class comp{
    public:
    bool operator()(ll& t1, ll& t2) // Returns true if t1 is earlier than t2
    {
     return (dp[t1]<dp[t2]);
    }
};
ll freq[100111];
int main(){
ll n,q;
cin>>n>>q;
ll v[n+1],c[n+1];
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=1;i<=n;i++) cin>>c[i];
ll a,b;
while(q--){
cin>>a>>b;
for(int i=0;i<=n;i++){
	dp[i]=-1;
	freq[i]=0;
}
priority_queue<ll,vector<ll>,comp>pq;
for(int i=1;i<=n;i++){
if(!freq[c[i]]){
pq.push(c[i]);
}
freq[c[i]]++;
}
for(int i=1;i<=n;i++){
ll t=pq.top();
bool bt=0;
if(t==c[i]){
	bt=1;
	pq.pop();
	t=pq.top();
}
if(dp[c[i]]!=-1){
dp[c[i]]=max(max(dp[c[i]],dp[c[i]]+a*v[i]), (( dp[t]==-1) ?0:dp[t]) +b*v[i]);
dp[c[i]]=max(dp[c[i]],b*v[i]);
}
else{
dp[c[i]]=max( max( (( dp[t]==-1) ?0:dp[t]) + b*v[i]  , b*v[i] ) ,-1LL );
}
if(bt){
	pq.push(c[i]);
}
}
ll ans=0;
for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
if(ans!=-1) cout<<ans<<"\n";
else cout<<0<<"\n";
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define INF 100000000000000000
ll dp[100111];
ll v[100011+1],c[100011+1];
ll n;
void solve(ll a,ll b){
    for(int i=0;i<=n;i++) dp[i]=-INF;
  	ll s[2];
  	s[0]=0;
  	s[1]=1;
	for(int i=1;i<=n;i++){
	dp[c[i]]=max(dp[c[i]],max(dp[c[i]]+v[i]*a,v[i]*b));
	ll other=-INF;
	for(int j=0;j<2;j++){
		if(s[j]!=c[i]) other=max(other,dp[s[j]]);
	 }
	dp[c[i]]=max(dp[c[i]],other+v[i]*b);
	bool u=0;
	for(int j=0;j<2;j++){
	if(s[j]==c[i]) u=1;
	}
	if(u==0){
	if(dp[c[i]]>dp[s[1]]) s[1]=c[i];
	if(dp[s[0]]<dp[s[1]]) swap(s[0],s[1]);
	}
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
	printf("%lld\n",ans);
}
int main(){
ll q;
scanf("%lld%lld",&n,&q);
for(int i=1;i<=n;i++) scanf("%lld",&v[i]);
for(int i=1;i<=n;i++) scanf("%lld",&c[i]);
ll a,b;
while(q--){
scanf("%lld",&a);
scanf("%lld",&b);
solve(a,b);
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
ll dp[100001]={0};
class comp{
    public:
    bool operator()(ll& t1, ll& t2) // Returns true if t1 is earlier than t2
    {
     return (dp[t1]<dp[t2]);
    }
};
ll freq[100001];
int main(){
ll n,q;
cin>>n>>q;
ll v[n+1],c[n+1];
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=1;i<=n;i++) cin>>c[i];
ll a,b;
while(q--){
cin>>a>>b;
for(int i=0;i<=n;i++){
	dp[i]=-1;
	freq[i]=0;
}
priority_queue<ll,vector<ll>,comp>pq;
for(int i=1;i<=n;i++){
if(!freq[c[i]]){
pq.push(c[i]);
//cout<<c[i]<<" ";
}
freq[c[i]]++;
}
for(int i=1;i<=n;i++){
ll t=pq.top();
bool bt=0;
if(t==c[i]){
	bt=1;
	pq.pop();
	t=pq.top();
}
if(dp[c[i]]!=-1 )
dp[c[i]]=max(max(dp[c[i]],dp[c[i]]+a*v[i]), (dp[t]==-1?0:dp[t]) +b*v[i]);
else{
dp[c[i]]=max(max( (dp[t]==-1?0:dp[t])         +b*v[i],b*v[i]),0LL);
}
if(bt){
	pq.push(c[i]);
}
}
ll ans=0;
for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
cout<<ans<<"\n";
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
ll dp[100111]={0};
class comp{
    public:
    bool operator()(ll& t1, ll& t2) // Returns true if t1 is earlier than t2
    {
     return (dp[t1]<dp[t2]);
    }
};
ll freq[100111];
int main(){
ll n,q;
cin>>n>>q;
ll v[n+1],c[n+1];
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=1;i<=n;i++) cin>>c[i];
ll a,b;
while(q--){
cin>>a>>b;
for(int i=0;i<=n;i++){
	dp[i]=-1;
	freq[i]=0;
}
priority_queue<ll,vector<ll>,comp>pq;
for(int i=1;i<=n;i++){
if(!freq[c[i]]){
pq.push(c[i]);
//cout<<c[i]<<" ";
}
freq[c[i]]++;
}
for(int i=1;i<=n;i++){
ll t=pq.top();
bool bt=0;
if(t==c[i]){
	bt=1;
	pq.pop();
	t=pq.top();
}
if(dp[c[i]]!=-1 )
dp[c[i]]=max(max(dp[c[i]],dp[c[i]]+a*v[i]), (dp[t]==-1?0:dp[t]) +b*v[i]);
else{
dp[c[i]]=max( (dp[t]==-1?0:dp[t])         + b*v[i] , b*v[i] );
}
if(bt){
	pq.push(c[i]);
}
}
ll ans=0;
for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
cout<<ans<<"\n";
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define INF 100000000000000000
ll dp[100111]={0};
ll v[100011+1],c[100011+1];
ll n;
bool func(ll a,ll b){
	return (dp[a]>dp[b]);
}
void solve(ll a,ll b){
    for(int i=0;i<=n;i++) dp[i]=-INF;
  	ll s[2];
  	s[0]=1;
  	s[1]=2;
	for(int i=1;i<=n;i++){
	dp[c[i]]=max(dp[c[i]],max(dp[c[i]]+v[i]*a,v[i]*b));
	ll other=-INF;
	for(int j=0;j<2;j++){
		if(s[j]!=c[i]) other=max(other,dp[s[j]]);
	 }
	dp[c[i]]=max(dp[c[i]],other+v[i]*b);
	bool u=0;
	for(int j=0;j<2;j++){
	if(s[j]==c[i]) u=1;
	}
	if(u==0){
	if(dp[c[i]]>dp[s[1]]) s[1]=c[i];
	if(dp[s[0]]<dp[s[1]]) swap(s[0],s[1]);
	}
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
	printf("%lld\n",ans);
}
int main(){
ll q;
scanf("%lld%lld",&n,&q);
for(int i=1;i<=n;i++) scanf("%lld",&v[i]);
for(int i=1;i<=n;i++) scanf("%lld",&c[i]);
ll a,b;
while(q--){
scanf("%lld",&a);
scanf("%lld",&b);
solve(a,b);
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define INF 1000000000000
ll dp[100111]={0};
ll v[100011+1],c[100011+1];
ll n;
bool func(ll a,ll b){
	return (dp[a]>dp[b]);
}
void solve(ll a,ll b){
    for(int i=1;i<=n;i++) dp[i]=-INF;
  	vector<ll>s;
	for(int i=1;i<=n;i++){
	dp[c[i]]=max(dp[c[i]],max(dp[c[i]]+v[i]*a,v[i]*b));
	ll other=-INF;
	for(int j=0;j<s.size();j++){
		if(s[j]!=c[i]) other=max(other,dp[s[j]]);
	}
	dp[c[i]]=max(dp[c[i]],other+v[i]*b);
	bool u=0;
	for(int j=0;j<s.size();j++){
	if(s[j]==c[i]) u=1;
	}
	if(u==0){
	if(s.size()<2) s.pb(c[i]);
	else{
	if(dp[s[1]]<dp[c[i]]) s[1]=c[i];
	}
	}
	if(dp[s[0]]<dp[s[1]]) swap(s[0],s[1]);
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
	printf("%lld\n",ans);
}
int main(){
ll q;
scanf("%lld%lld",&n,&q);
for(int i=1;i<=n;i++) scanf("%lld",&v[i]);
for(int i=1;i<=n;i++) scanf("%lld",&c[i]);
ll a,b;
while(q--){
scanf("%lld",&a);
scanf("%lld",&b);
solve(a,b);
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define INF 1000000000000
ll dp[100111]={0};
ll v[100011+1],c[100011+1];
ll n;
bool func(ll a,ll b){
	return (dp[a]>dp[b]);
}
void solve(ll a,ll b){
    for(int i=1;i<=n;i++) dp[i]=-INF;
  	vector<ll>s;
	for(int i=1;i<=n;i++){
	dp[c[i]]=max(dp[c[i]],max(dp[c[i]]+v[i]*a,v[i]*b));
	ll other=-INF;
	for(int j=0;j<s.size();j++){
		if(s[j]!=c[i]) other=max(other,dp[s[j]]);
	}
	dp[c[i]]=max(dp[c[i]],other+v[i]*b);
	bool u=0;
	for(int j=0;j<s.size();j++){
	if(s[j]==c[i]) u=1;
	}
	if(u==0){
	s.pb(c[i]);
	sort(s.begin(),s.end(),func);
	while(s.size()>3) s.pop_back();
	}
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
	cout<<ans<<"\n";
}
int main(){
ll q;
cin>>n>>q;
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=1;i<=n;i++) cin>>c[i];
ll a,b;
while(q--){
cin>>a>>b;
solve(a,b);
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
ll dp[100111]={0};
class comp{
    public:
    bool operator()(ll& t1, ll& t2) // Returns true if t1 is earlier than t2
    {
     return (dp[t1]<dp[t2]);
    }
};
ll freq[100111];
int main(){
ll n,q;
cin>>n>>q;
ll v[n+1],c[n+1];
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=1;i<=n;i++) cin>>c[i];
ll a,b;
while(q--){
cin>>a>>b;
for(int i=0;i<=n;i++){
	dp[i]=-1;
	freq[i]=0;
}
priority_queue<ll,vector<ll>,comp>pq;
for(int i=1;i<=n;i++){
if(!freq[c[i]]){
pq.push(c[i]);
}
freq[c[i]]++;
}
for(int i=1;i<=n;i++){
ll t=pq.top();
bool bt=0;
if(t==c[i]){
	bt=1;
	pq.pop();
	t=pq.top();
}
if(dp[c[i]]!=-1)
dp[c[i]]=max(max(dp[c[i]],dp[c[i]]+a*v[i]), (dp[t]==-1?0:dp[t]) +b*v[i]);
else{
dp[c[i]]=max( max( (dp[t]==-1?0:dp[t]) + b*v[i]  , b*v[i] ) ,-1LL );
}
if(bt){
	pq.push(c[i]);
}
}
ll ans=0;
for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
if(ans!=-1) cout<<ans<<"\n";
else cout<<0<<"\n";
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
ll dp[100111]={0};
class comp{
    public:
    bool operator()(ll& t1, ll& t2) // Returns true if t1 is earlier than t2
    {
     return (dp[t1]<dp[t2]);
    }
};
ll freq[100111];
int main(){
ll n,q;
cin>>n>>q;
ll v[n+1],c[n+1];
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=1;i<=n;i++) cin>>c[i];
ll a,b;
while(q--){
cin>>a>>b;
for(int i=0;i<=n;i++){
	dp[i]=-1;
	freq[i]=0;
}
dp[0]=0;
priority_queue<ll,vector<ll>,comp>pq;
for(int i=1;i<=n;i++){
if(!freq[c[i]]){
pq.push(c[i]);
}
freq[c[i]]++;
}
for(int i=1;i<=n;i++){
ll t=pq.top();
bool bt=0;
if(t==c[i]){
	bt=1;
	pq.pop();
	if(pq.size()!=0)
	t=pq.top();
	else t=0;
}
if(dp[c[i]]!=-1){
dp[c[i]]=max(max(dp[c[i]],dp[c[i]]+a*v[i]), (( dp[t]==-1) ?0:dp[t]) +b*v[i]);
dp[c[i]]=max(dp[c[i]],b*v[i]);
}
else{
dp[c[i]]=max( max( (( dp[t]==-1) ?0:dp[t]) + b*v[i]  , b*v[i] ) ,-1LL );
}
if(bt){
	pq.push(c[i]);
}
}
ll ans=0;
for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
if(ans!=-1) cout<<ans<<"\n";
else cout<<0<<"\n";
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
ll dp[100111]={0};
class comp{
    public:
    bool operator()(ll& t1, ll& t2) // Returns true if t1 is earlier than t2
    {
     return (dp[t1]<dp[t2]);
    }
};
ll freq[100111];
int main(){
ll n,q;
cin>>n>>q;
ll v[n+1],c[n+1];
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=1;i<=n;i++) cin>>c[i];
ll a,b;
while(q--){
cin>>a>>b;
for(int i=0;i<=n;i++){
	dp[i]=-1;
	freq[i]=0;
}
priority_queue<ll,vector<ll>,comp>pq;
for(int i=1;i<=n;i++){
if(!freq[c[i]]){
pq.push(c[i]);
}
freq[c[i]]++;
}
for(int i=1;i<=n;i++){
ll t=pq.top();
bool bt=0;
if(t==c[i]){
	bt=1;
	pq.pop();
	t=pq.top();
}
if(dp[c[i]]!=-1)
dp[c[i]]=max(max(dp[c[i]],dp[c[i]]+a*v[i]), (( dp[t]==-1) ?0:dp[t]) +b*v[i]);
else{
dp[c[i]]=max( max( (( dp[t]==-1) ?0:dp[t]) + b*v[i]  , b*v[i] ) ,-1LL );
}
if(bt){
	pq.push(c[i]);
}
}
ll ans=0;
for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
if(ans!=-1) cout<<ans<<"\n";
else cout<<0<<"\n";
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define INF 1000000000000
ll dp[100111]={0};
ll v[100011+1],c[100011+1];
ll n;
bool func(ll a,ll b){
	return (dp[a]>dp[b]);
}
void solve(ll a,ll b){
    for(int i=1;i<=n;i++) dp[i]=-INF;
  	vector<ll>s;
	for(int i=1;i<=n;i++){
	dp[c[i]]=max(dp[c[i]],max(dp[c[i]]+v[i]*a,v[i]*b));
	ll other=-INF;
	for(int j=0;j<s.size();j++){
		if(s[j]!=c[i]) other=max(other,dp[s[j]]);
	}
	dp[c[i]]=max(dp[c[i]],other+v[i]*b);
	bool u=0;
	for(int j=0;j<s.size();j++){
	if(s[j]==c[i]) u=1;
	}
	if(u==0){
	s.pb(c[i]);
	if(s.size()>2) sort(s.begin(),s.end(),func);
	while(s.size()>2) s.pop_back();
	}
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
	printf("%lld\n",ans);
}
int main(){
ll q;
scanf("%lld%lld",&n,&q);
for(int i=1;i<=n;i++) scanf("%lld",&v[i]);
for(int i=1;i<=n;i++) scanf("%lld",&c[i]);
ll a,b;
while(q--){
scanf("%lld",&a);
scanf("%lld",&b);
solve(a,b);
}
}


#include<bits/stdc++.h>
//#define mod 1000000007
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define INF 1000000
ll dp[100111]={0};
class comp{
    public:
    bool operator()(ll& t1, ll& t2) // Returns true if t1 is earlier than t2
    {
     return (dp[t1]<dp[t2]);
    }
};
ll freq[100111];
int main(){
ll n,q;
cin>>n>>q;
ll v[n+1],c[n+1];
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=1;i<=n;i++) cin>>c[i];
ll a,b;
while(q--){
cin>>a>>b;
for(int i=0;i<=n;i++){
	dp[i]=-INF;
	freq[i]=0;
}
dp[0]=0;
priority_queue<ll,vector<ll>,comp>pq;
for(int i=1;i<=n;i++){
if(!freq[c[i]]){
pq.push(c[i]);
}
freq[c[i]]++;
}
for(int i=1;i<=n;i++){
ll t=pq.top();
bool bt=0;
if(t==c[i]){
	bt=1;
	pq.pop();
	if(pq.size()!=0)
	t=pq.top();
	else t=0;
}
if(dp[c[i]]!=-INF){
dp[c[i]]=max(max(dp[c[i]],dp[c[i]]+a*v[i]), (( dp[t]==-1) ?0:dp[t]) +b*v[i]);
dp[c[i]]=max(dp[c[i]],b*v[i]);
dp[c[i]]=max(dp[c[i]],-1LL);
}
else{
dp[c[i]]=max( max( (( dp[t]==-1) ?0:dp[t]) + b*v[i]  , b*v[i] ) ,-1LL );
}
if(dp[c[i]]==-1) dp[c[i]]=-INF;
if(bt){
	pq.push(c[i]);
}
}
ll ans=0;
for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
if(ans!=-1) cout<<ans<<"\n";
else cout<<0<<"\n";
}
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int N=100010;
typedef long long LL;

int n,q;
int v[N],c[N];

LL dp[N];
int p[N];

struct TwoPointerset{
	int p[2];
	TwoPointerset(){
		p[0]=p[1]=-1;
	}

	int getpos(int color){
		if(p[0]!=-1 &&color!=c[p[0]]) return p[0];
		else if(p[1]!=-1 &&color!=c[p[1]]) return p[1];
		return -1;
	}

	void update(int newpos){
		if(p[0]==-1) p[0]=newpos;
		else if(p[1]==-1) {
			if(c[newpos]!=c[p[0]]){
				p[1]=newpos;
				if(dp[p[1]]>dp[p[0]]) swap(p[0],p[1]);
			}else{
				if(dp[newpos]>dp[p[0]]) p[0]=newpos;
			}
		}
		else{
			if(c[newpos]==c[p[1]]) {
				if(dp[newpos]>dp[p[1]]) p[1]=newpos;
				if(dp[p[1]]>dp[p[0]]) swap(p[0],p[1]);
				return;
			}else{
				if(dp[newpos]>dp[p[0]]) {
					p[0]=newpos;
					return;
				}else if(dp[newpos]>dp[p[1]]){
					p[1]=newpos;
					return;
				}
			}
		}
	}
};

LL getdp(LL A,LL B){
	memset(p,-1,sizeof(p));
	TwoPointerset tp;
	LL ans=0;
	for(int i=0;i<n;i++) {
		LL tmp=B*v[i];
		if(p[c[i]]!=-1){
			tmp=max(tmp,dp[p[c[i]]]+A*v[i]);
		}
		if(tp.getpos(c[i])!=-1){
			tmp=max(tmp,dp[tp.getpos(c[i])]+B*v[i]);
		}
		dp[i]=tmp;
		ans=max(ans,tmp);
		tp.update(i);
		if(p[c[i]]==-1 || dp[i]>dp[p[c[i]]]) p[c[i]]=i;
	}
	return ans;
}

int main() {
	setbuf(stdout,NULL);
	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]);
	while(q--){
		LL a,b;
		cin>>a>>b;
		cout<<getdp(a,b)<<endl;
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
using namespace std;
const int N=100010;
typedef long long LL;
int n,q;
int v[N],c[N];
LL dp[N];
LL query(LL A,LL B){
	memset(dp,0x80,sizeof(dp));
	int p1=0,p2=0;
	dp[0]=0;
	LL ret=0;
	for(int i=0;i<n;i++){
		int p=c[i]!=p1?p1:p2;
		dp[c[i]]=max(dp[c[i]],dp[c[i]]+A*v[i]);
		dp[c[i]]=max(dp[c[i]],dp[p]+B*v[i]);
		if(c[i]!=p1 && c[i]!=p2){
			if(dp[c[i]]>=dp[p1]) p2=p1,p1=c[i];
			else if(dp[c[i]]>=dp[p2]) p2=c[i];
		}else {
			if(dp[p1]<dp[p2]) swap(p1,p2);
		}
		ret=max(ret,dp[c[i]]);
	}
	return ret;
}
int main() {
	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]);
	while(q--){
		LL a,b;
		cin>>a>>b;
		cout<<query(a,b)<<endl;
	}
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <string.h>
using namespace std;

typedef pair<int,int> PII;
PII a[100010];

typedef long long LL;
typedef pair<LL,LL> PLL;

int n,q;
const LL inf=1ll<<63;

LL dp[100010];
LL spos[100010];

PLL _max[3];
LL A,B;

void update_set(int pos){
	LL value=dp[pos];
	LL color=a[pos].second;
	_max[2]=PLL(value,color);
	sort(_max,_max+3,greater<PLL>());
	if(_max[0].second==_max[1].second) swap(_max[1],_max[2]);
	if(spos[color]==-1 || dp[pos]>dp[spos[color]]){
		spos[color]=pos;
	}
}

LL get_diff_max(int color){
	if(color!=_max[0].second) return _max[0].first;
	else return _max[1].first;
}

LL get_val(int pos){
	LL ret=-inf;
	if(spos[a[pos].second]!=-1) {
		ret=max(dp[spos[a[pos].second]]+A*a[pos].first,ret);
	}
	ret=max(B*a[pos].first,ret);
	ret=max(get_diff_max(a[pos].second)+ B*a[pos].first,ret);
	return ret;
}

LL query(LL a,LL b){

	memset(spos,-1,sizeof(spos));
	_max[0]=_max[1]=PLL(-inf,-1);
	A=a;B=b;
	LL ret=0;
	for(int i=0;i<n;i++){
		dp[i]=get_val(i);
		update_set(i);
		ret=max(ret,dp[i]);
	}
	return max(0ll,ret);
}

int main() {
	scanf("%d%d",&n,&q);
	for(int i=0;i<n;i++) scanf("%d",&a[i].first);
	for(int i=0;i<n;i++) scanf("%d",&a[i].second);
	while(q--){
		int a,b;
		cin>>a>>b;
		cout<<query(a,b)<<endl;
	}
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <string.h>
using namespace std;

typedef pair<int,int> PII;
PII a[100010];

typedef long long LL;
typedef pair<LL,int> PLI;

int n,q;

set<PLI> S;
LL dp[100010];
LL spos[100010];
LL A,B;

void update_set(int pos){
	int color=a[pos].second;
	if(spos[color]==-1 || dp[pos]>dp[spos[color]]){
		S.erase(PLI(dp[spos[color]],color));
		S.insert(PLI(dp[pos],color));
		spos[color]=pos;
	}
}

LL get_diff_max(int color){
	if(S.empty()) return 0;
	if(S.rbegin()->second!=color) return S.rbegin()->first;
	else{
		if(S.size()==1) return 0;
		return (++S.rbegin())->first;
	}
}

LL get_val(int pos){
	LL ret=0;
	if(spos[a[pos].second]!=-1) {
		ret=max(dp[spos[a[pos].second]]+A*a[pos].first,ret);
	}
	ret=max(B*a[pos].first,ret);
	ret=max(get_diff_max(a[pos].second)+ B*a[pos].first,ret);
	return ret;
}

LL query(LL a,LL b){
	memset(spos,-1,sizeof(spos));
	S.clear();
	A=a;B=b;
	LL ret=0;
	for(int i=0;i<n;i++){
		dp[i]=get_val(i);
		update_set(i);
		ret=max(ret,dp[i]);
	}
	return ret;
}

int main() {
	scanf("%d%d",&n,&q);
	for(int i=0;i<n;i++) scanf("%d",&a[i].first);
	for(int i=0;i<n;i++) scanf("%d",&a[i].second);
	while(q--){
		int a,b;
		cin>>a>>b;
		cout<<query(a,b)<<endl;
	}

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int N=100010;
typedef long long LL;

int n,q;
int v[N],c[N];
LL dp[N];
int p[N];

struct TwoColorSet{
	int s[2];
	TwoColorSet(){
		s[0]=s[1]=-1;
	}
	int get_diff_color(int color){
		if(s[0]!=-1&& color!=s[0]) return s[0];
		else if(s[1]!=-1 && color!=s[1]) return s[1];
		return -1;
	}
	void update_set(int pos){
		if(s[0]==-1) {
			s[0]=c[pos];
			return;
		}
		else if(s[1]==-1) {
			if(s[0]==c[pos]) return;
			s[1]=c[pos];
			return;
		}else{
			if(c[pos]==s[0] || c[pos]==s[1]){
				if(dp[p[s[0]]]<dp[p[s[1]]]) swap(s[0],s[1]);
				return;
			}
			if(dp[pos]>=dp[p[s[0]]]){
				s[1]=s[0];
				s[0]=c[pos];
				return;
			}else if(dp[pos]>dp[p[s[1]]]){
				s[1]=c[pos];
			}
		}
	}
};

LL getdp(LL A,LL B){
	memset(p,-1,sizeof(p));
	TwoColorSet tp;
	LL ans=0;
	for(int i=0;i<n;i++) {
		LL tmp=B*v[i];
		if(p[c[i]]!=-1){
			tmp=max(tmp,dp[p[c[i]]]+A*(LL)v[i]);
		}
		if(tp.get_diff_color(c[i])!=-1){
			tmp=max(tmp,dp[p[tp.get_diff_color(c[i])]]+B*(LL)v[i]);
		}
		dp[i]=tmp;
		ans=max(ans,tmp);
		if(p[c[i]]==-1 || dp[i]>=dp[p[c[i]]]) p[c[i]]=i;
		tp.update_set(i);
	}
	return ans;
}

int main() {
	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]);
	while(q--){
		LL a,b;
		cin>>a>>b;
		cout<<getdp(a,b)<<endl;
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
const int N=100010;
typedef long long LL;
int n,q;
int v[N],c[N];
LL dp[N];
LL query(LL A,LL B){
	memset(dp,0x80,sizeof(dp));
	int p1=0,p2=0;
	dp[0]=0;
	LL ret=0;
	for(int i=0;i<n;i++){
		int p=c[i]!=p1?p1:p2;
		dp[c[i]]=max(dp[c[i]],dp[c[i]]+A*v[i]);
		dp[c[i]]=max(dp[c[i]],dp[p]+B*v[i]);
		if(c[i]!=p1 && c[i]!=p2){
			if(dp[c[i]]>=dp[p1]) p2=p1,p1=c[i];
			else if(dp[c[i]]>=dp[p2]) p2=c[i];
		}else {
			if(dp[p1]<dp[p2]) swap(p1,p2);
		}
		ret=max(ret,dp[c[i]]);
	}
	return ret;
}
int main() {
	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]);
	while(q--){
		LL a,b;
		cin>>a>>b;
		cout<<query(a,b)<<endl;
	}
}


#include <bits/stdc++.h>

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

inline int inv(int a, int md) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

class HASH {
  public:;
  int a = 1e9 + 7;
  int b = 998244353;
  int x = 0, y = 0;
  HASH(){};
  HASH(int _x, int _y) : x(_x), y(_y) {
    x = ((x % a) + a) % a;
    y = ((y % b) + b) % b;
  };

  HASH operator + (const HASH &c) const {
    return HASH(x + c.x, y + c.y);
  }
  HASH operator - (const HASH &c) const {
    return HASH(x - c.x, y - c.y);
  }
  HASH operator * (const HASH &c) const {
    return HASH(((long long) x * c.x) % a, ((long long) y * c.y) % b);
  }
  HASH operator * (int c) const {
    return HASH(((long long) x * c) % a, ((long long) y * c) % b);
  }
  HASH operator / (const HASH &c) const {
    HASH _c = HASH(inv(c.x, a), inv(c.y, b));
    return *this * _c;
  }
  HASH operator / (int c) const {
    return *this / HASH(c, c);
  }
  bool operator < (const HASH &c) const {
    return make_pair(x, y) < make_pair(c.x, c.y);
  }
};

int n, a, b;
string s;

int main() {
  cin >> n >> a >> b >> s;
  vector<int> dp(n + 1);
  multiset<long long> cur;
  HASH c(97, 31);
  vector<HASH> p(n + 1);
  p[0] = HASH(1, 1);
  range(i, 1, n + 1) p[i] = p[i - 1] * c;
  vector<HASH> pref(n + 1);
  range(i, 1, n + 1) {
    pref[i] = pref[i - 1] + p[i] * (s[i - 1] - 'a' + 3);
  }
  const int md = 1e9 + 7;
  auto get = [&] (int l, int r) {
    HASH cc = (pref[r] - pref[l]) / p[l];
    return 1LL * cc.x * md + cc.y;
  };
  range(i, 0, n + 1) {
    range(j, i + 1, n + 1) {
      cur.insert(get(i, j));
    }
  }
  husk(i, n - 1, -1) {
    range(j, 0, i + 1) cur.erase(cur.find(get(j, i + 1)));
    dp[i] = dp[i + 1] + a;
    range(j, i + 1, n + 1) {
      if(cur.find(get(i, j)) != cur.end()) dp[i] = min(dp[i], dp[j] + b);
    }
  }
  cout << dp[0];
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

inline int inv(int a, int md) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

class HASH {
  public:;
  int a = 1e9 + 7;
  int b = 998244353;
  int x = 0, y = 0;
  HASH(){};
  HASH(int _x, int _y) : x(_x), y(_y) {
    x = ((x % a) + a) % a;
    y = ((y % b) + b) % b;
  };

  HASH operator + (const HASH &c) const {
    return HASH(x + c.x, y + c.y);
  }
  HASH operator - (const HASH &c) const {
    return HASH(x - c.x, y - c.y);
  }
  HASH operator * (const HASH &c) const {
    return HASH(((long long) x * c.x) % a, ((long long) y * c.y) % b);
  }
  HASH operator * (int c) const {
    return HASH(((long long) x * c) % a, ((long long) y * c) % b);
  }
  HASH operator / (const HASH &c) const {
    HASH _c = HASH(inv(c.x, a), inv(c.y, b));
    return *this * _c;
  }
  HASH operator / (int c) const {
    return *this / HASH(c, c);
  }
  bool operator < (const HASH &c) const {
    return make_pair(x, y) < make_pair(c.x, c.y);
  }
};

int n, a, b;
string s;

int main() {
  cin >> n >> a >> b >> s;
  vector<int> dp(n + 1);
  multiset<HASH> cur;
  HASH c(97, 31);
  vector<HASH> p(n + 1);
  p[0] = HASH(1, 1);
  range(i, 1, n + 1) p[i] = p[i - 1] * c;
  vector<HASH> pref(n + 1);
  range(i, 1, n + 1) {
    pref[i] = pref[i - 1] + p[i] * (s[i - 1] - 'a' + 3);
  }
  auto get = [&] (int l, int r) {
    return (pref[r] - pref[l]) / p[l];
  };
  range(i, 0, n + 1) {
    range(j, i + 1, n + 1) {
      cur.insert(get(i, j));
    }
  }
  husk(i, n - 1, -1) {
    range(j, 0, i + 1) cur.erase(cur.find(get(j, i + 1)));
    dp[i] = dp[i + 1] + a;
    range(j, i + 1, n + 1) {
      if(cur.find(get(i, j)) != cur.end()) dp[i] = min(dp[i], dp[j] + b);
    }
  }
  cout << dp[0];
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n, a, b;
string s;

int main() {
  cin >> n >> a >> b >> s;
  vector<vector<int>> dp(n + 1, vector<int>(n + 1));
  vector<int> to(n);
  vector<int> res(n + 1);
  husk(i, n - 1, -1) {
    range(j, 0, i) {
      if(s[i] == s[j]) dp[j][i] = dp[j + 1][i + 1] + 1;
      else dp[j][i] = 0;
      to[i] = max(to[i], min(dp[j][i], i - j));
    }
  }
  husk(i, n - 1, -1) {
    res[i] = res[i + 1] + a;
    if(to[i]) {
      res[i] = min(res[i], res[i + to[i]] + b);
    }
  }
  cout << res[0];
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

inline int inv(int a, int md) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

class HASH {
  public:;
  int a = 1e9 + 7;
  int b = 998244353;
  int x = 0, y = 0;
  HASH(){};
  HASH(int _x, int _y) : x(_x), y(_y) {
    x = ((x % a) + a) % a;
    y = ((y % b) + b) % b;
  };

  HASH operator + (const HASH &c) const {
    return HASH(x + c.x, y + c.y);
  }
  HASH operator - (const HASH &c) const {
    return HASH(x - c.x, y - c.y);
  }
  HASH operator * (const HASH &c) const {
    return HASH(((long long) x * c.x) % a, ((long long) y * c.y) % b);
  }
  HASH operator * (int c) const {
    return HASH(((long long) x * c) % a, ((long long) y * c) % b);
  }
  HASH operator / (const HASH &c) const {
    HASH _c = HASH(inv(c.x, a), inv(c.y, b));
    return *this * _c;
  }
  HASH operator / (int c) const {
    return *this / HASH(c, c);
  }
  bool operator < (const HASH &c) const {
    return make_pair(x, y) < make_pair(c.x, c.y);
  }
};

int n, a, b;
string s;

int main() {
  cin >> n >> a >> b >> s;
  vector<int> dp(n + 1);
  unordered_map<int, unordered_multiset<int>> cur;
  auto insert = [&] (HASH cc) {
    cur[cc.x].insert(cc.y);
  };
  auto find = [&] (HASH cc) {
    return cur[cc.x].find(cc.y) != cur[cc.x].end();
  };
  auto erase = [&] (HASH cc) {
    assert(find(cc));
    cur[cc.x].erase(cur[cc.x].find(cc.y));
  };
  HASH c(97, 31);
  vector<HASH> p(n + 1);
  p[0] = HASH(1, 1);
  range(i, 1, n + 1) p[i] = p[i - 1] * c;
  vector<HASH> pref(n + 1);
  range(i, 1, n + 1) {
    pref[i] = pref[i - 1] + p[i] * (s[i - 1] - 'a' + 3);
  }
  auto get = [&] (int l, int r) {
    return (pref[r] - pref[l]) / p[l];
  };
  range(i, 0, n + 1) {
    range(j, i + 1, n + 1) {
      insert(get(i, j));
    }
  }
  husk(i, n - 1, -1) {
    range(j, 0, i + 1) erase(get(j, i + 1));
    dp[i] = dp[i + 1] + a;
    range(j, i + 1, n + 1) {
      if(find(get(i, j))) dp[i] = min(dp[i], dp[j] + b);
    }
  }
  cout << dp[0];
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

inline int inv(int a, int md) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

class HASH {
  public:;
  int a = 1e9 + 7;
  int b = 998244353;
  int x = 0, y = 0;
  HASH(){};
  HASH(int _x, int _y) : x(_x), y(_y) {
    x = ((x % a) + a) % a;
    y = ((y % b) + b) % b;
  };

  HASH operator + (const HASH &c) const {
    return HASH(x + c.x, y + c.y);
  }
  HASH operator - (const HASH &c) const {
    return HASH(x - c.x, y - c.y);
  }
  HASH operator * (const HASH &c) const {
    return HASH(((long long) x * c.x) % a, ((long long) y * c.y) % b);
  }
  HASH operator * (int c) const {
    return HASH(((long long) x * c) % a, ((long long) y * c) % b);
  }
  HASH operator / (const HASH &c) const {
    HASH _c = HASH(inv(c.x, a), inv(c.y, b));
    return *this * _c;
  }
  HASH operator / (int c) const {
    return *this / HASH(c, c);
  }
  bool operator < (const HASH &c) const {
    return make_pair(x, y) < make_pair(c.x, c.y);
  }
};

int n, a, b;
string s;

int main() {
  cin >> n >> a >> b >> s;
  vector<int> dp(n + 1);
  multiset<long long> cur;
  HASH c(97, 31);
  vector<HASH> p(n + 1);
  p[0] = HASH(1, 1);
  range(i, 1, n + 1) p[i] = p[i - 1] * c;
  vector<HASH> pref(n + 1);
  range(i, 1, n + 1) {
    pref[i] = pref[i - 1] + p[i] * (s[i - 1] - 'a' + 3);
  }
  const int md = 1e9 + 7;
  auto get = [&] (int l, int r) {
    HASH cc = (pref[r] - pref[l]) / p[l];
    return (long long) cc.x * md + cc.y;
  };
  range(i, 0, n + 1) {
    range(j, i + 1, n + 1) {
      cur.insert(get(i, j));
    }
  }
  husk(i, n - 1, -1) {
    range(j, 0, i + 1) cur.erase(get(j, i + 1));
    dp[i] = dp[i + 1] + a;
    range(j, i + 1, n + 1) {
      if(cur.find(get(i, j)) != cur.end()) dp[i] = min(dp[i], dp[j] + b);
    }
  }
  cout << dp[0];
  return 0;
}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;
using ull = long long;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 5005;
const ull B = 31;
const int MOD = 1e9 + 17;
const int MODH = 3e6 + 67013;
int n, a, b, dp[N];
ull hsh, hsh1;
string s;

struct hasher {

	vector <pair <int, int> > v[MODH];

	void add(int hsh1, int hsh, int pos) {
		if(get(hsh1, hsh) == -1)
			v[hsh1].push_back({hsh, pos});
	}

	int get(int hsh1, int hsh) {
		for(auto i : v[hsh1])
			if(i.st == hsh1)
				return i.nd;
		return -1;
	}
} hhh;

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> a >> b;
	cin >> s;

	s = "#" + s;

	for(int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1] + a;

		hsh = 0;
		hsh1 = 0;
		for(int j = i; j >= 1; j--) {
			hsh = (hsh * B + s[j] - 'a' + 1) % MOD;
			hsh1 = (hsh1 * B + s[j] - 'a' + 1) % MODH;

			int min_val = hhh.get(hsh1, hsh);

			if(min_val != -1) {
				if(min_val < j)
					dp[i] = min(dp[i], dp[j - 1] + b);
			} else
				hhh.add(hsh1, hsh, i);
		}
	}
	// dbg_v(dp, n+ 1);
	cout << dp[n] << '\n';
}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;
using ull = long long;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 5005;
const ull B = 31;
const int MOD = 1e9 + 7;
const int MODH = 2e6 + 67013;
int n, a, b, dp[N];
ull hsh, hsh1;
string s;

struct hasher {

	vector <pair <int, int> > v[MODH];

	void add(int hsh1, int hsh, int pos) {
		if(get(hsh1, hsh) == -1)
			v[hsh1].push_back({hsh, pos});
	}

	int get(int hsh1, int hsh) {
		for(auto i : v[hsh1])
			if(i.st == hsh)
				return i.nd;
		return -1;
	}
} hhh;

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> a >> b;
	cin >> s;

	s = "#" + s;

	for(int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1] + a;

		hsh = 0;
		hsh1 = 0;
		for(int j = i; j >= 1; j--) {
			hsh = (hsh * B + s[j] - 'a' + 1) % MOD;
			hsh1 = (hsh1 * 37 + s[j] - 'a' + 1) % MODH;
			// dbg(i, j, hsh, hsh1);

			int min_val = hhh.get(hsh1, hsh);
			// dbg(min_val);

			if(min_val != -1) {
				if(min_val < j)
					dp[i] = min(dp[i], dp[j - 1] + b);
			} else
				hhh.add(hsh1, hsh, i);
		}
	}
	// dbg_v(dp, n+ 1);
	cout << dp[n] << '\n';
}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;
using ull = long long;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 5005;
const ull B = 31;
const int MOD = 1e9 + 7;
const int MODH = 1e6 + 67013;
int n, a, b, dp[N];
ull hsh;
string s;

unordered_map <int, int> fst[N];

struct hasher {

	vector <pair<pair <int, int> , int >> v[MODH];

	void add(int hsh, int lg, int pos) {
		// dbg(hsh, lg, pos);
		if(get(hsh, lg) == -1)
			v[hsh % MODH].push_back({{hsh, lg}, pos});
	}

	int get(int hsh, int lg) {
		// dbg(hsh, lg);
		for(auto i : v[hsh % MODH])
			if(i.st == make_pair(hsh, lg))
				return i.nd;
		return -1;
	}
} hhh;

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> a >> b;
	cin >> s;

	s = "#" + s;

	for(int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1] + a;

		hsh = 0;
		for(int j = i; j >= 1; j--) {
			hsh = (hsh * B + s[j] - 'a' + 1) % MOD;

			int min_val = hhh.get(hsh, i - j + 1);

			if(min_val != -1) {
				if(min_val < j)
					dp[i] = min(dp[i], dp[j - 1] + b);
			} else
				hhh.add(hsh, i - j + 1, i);
		}
	}
	// dbg_v(dp, n+ 1);
	cout << dp[n] << '\n';
}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;
using ull = long long;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 5005;
const ull B = 31;
const int MOD = 1e9 + 17;
const int MODH = 67013;
int n, a, b, dp[N];
ull hsh, hsh1;
string s;

struct hasher {

	vector <pair<pair <int, int> , int >> v[MODH];

	void add(int hsh1, int hsh, int lg, int pos) {
		if(get(hsh1, hsh, lg) == -1)
			v[hsh1].push_back({{hsh, lg}, pos});
	}

	int get(int hsh1, int hsh, int lg) {
		for(auto i : v[hsh1])
			if(i.st == make_pair(hsh, lg))
				return i.nd;
		return -1;
	}
} hhh;

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> a >> b;
	cin >> s;

	s = "#" + s;

	for(int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1] + a;

		hsh = 0;
		hsh1 = 0;
		for(int j = i; j >= 1; j--) {
			hsh = (hsh * B + s[j] - 'a' + 1) % MOD;
			hsh1 = (hsh1 * B + s[j] - 'a' + 1) % MODH;

			int min_val = hhh.get(hsh1, hsh, i - j + 1);

			if(min_val != -1) {
				if(min_val < j)
					dp[i] = min(dp[i], dp[j - 1] + b);
			} else
				hhh.add(hsh1, hsh, i - j + 1, i);
		}
	}
	// dbg_v(dp, n+ 1);
	cout << dp[n] << '\n';
}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;
using ull = long long;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 5005;
const ull B = 31;
const int MOD = 1e9 + 17;
const int MODH = 3e6 + 67013;
int n, a, b, dp[N];
ull hsh, hsh1;
string s;

struct hasher {

	vector <pair<pair <int, int> , int >> v[MODH];

	void add(int hsh1, int hsh, int lg, int pos) {
		if(get(hsh1, hsh, lg) == -1)
			v[hsh1].push_back({{hsh, lg}, pos});
	}

	int get(int hsh1, int hsh, int lg) {
		for(auto i : v[hsh1])
			if(i.st == make_pair(hsh, lg))
				return i.nd;
		return -1;
	}
} hhh;

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> a >> b;
	cin >> s;

	s = "#" + s;

	for(int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1] + a;

		hsh = 0;
		hsh1 = 0;
		for(int j = i; j >= 1; j--) {
			hsh = (hsh * B + s[j] - 'a' + 1) % MOD;
			hsh1 = (hsh1 * B + s[j] - 'a' + 1) % MODH;

			int min_val = hhh.get(hsh1, hsh, i - j + 1);

			if(min_val != -1) {
				if(min_val < j)
					dp[i] = min(dp[i], dp[j - 1] + b);
			} else
				hhh.add(hsh1, hsh, i - j + 1, i);
		}
	}
	// dbg_v(dp, n+ 1);
	cout << dp[n] << '\n';
}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;
using ull = long long;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 5005;
const ull B = 31;
const int MOD = 1e9 + 17;
const int MODH = 1e6 + 67013;
int n, a, b, dp[N];
ull hsh;
string s;

struct hasher {

	vector <pair<pair <int, int> , int >> v[MODH];

	void add(int hsh, int lg, int pos) {
		// dbg(hsh, lg, pos);
		if(get(hsh, lg) == -1)
			v[hsh % MODH].push_back({{hsh, lg}, pos});
	}

	int get(int hsh, int lg) {
		// dbg(hsh, lg);
		for(auto i : v[hsh % MODH])
			if(i.st == make_pair(hsh, lg))
				return i.nd;
		return -1;
	}
} hhh;

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> a >> b;
	cin >> s;

	s = "#" + s;

	for(int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1] + a;

		hsh = 0;
		for(int j = i; j >= 1; j--) {
			hsh = (hsh * B + s[j] - 'a' + 1) % MOD;

			int min_val = hhh.get(hsh, i - j + 1);

			if(min_val != -1) {
				if(min_val < j)
					dp[i] = min(dp[i], dp[j - 1] + b);
			} else
				hhh.add(hsh, i - j + 1, i);
		}
	}
	// dbg_v(dp, n+ 1);
	cout << dp[n] << '\n';
}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;
using ull = unsigned long long;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 5005;
const ull B = 31;
int n, a, b, dp[N];
ull hsh;
string s;

unordered_map <ull, int> fst[N];

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> a >> b;
	cin >> s;

	s = "#" + s;

	for(int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1] + a;

		hsh = 0;
		for(int j = i; j >= 1; j--) {
			hsh = hsh * B + s[j] - 'a' + 1;

			// dbg(i, j, hsh);
			if(fst[i - j + 1].count(hsh)) {
				// dbg(fst[i - j + 1][hsh], dp[j - 1]);
				if(fst[i - j + 1][hsh] < j)
					dp[i] = min(dp[i], dp[j - 1] + b);
			} else fst[i - j + 1][hsh] = i;
			// dbg(dp[i]);
		}
	}
	// dbg_v(dp, n+ 1);
	cout << dp[n] << '\n';
}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;
using ull = long long;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 5005;
const ull B = 31;
const int MOD = 1e9 + 7;
int n, a, b, dp[N];
ull hsh;
string s;

map <int, int> fst[N];

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> a >> b;
	cin >> s;

	s = "#" + s;

	for(int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1] + a;

		hsh = 0;
		for(int j = i; j >= 1; j--) {
			hsh = (hsh * B + s[j] - 'a' + 1) % MOD;

			// dbg(i, j, hsh);
			if(fst[i - j + 1].count(hsh)) {
				// dbg(fst[i - j + 1][hsh], dp[j - 1]);
				if(fst[i - j + 1][hsh] < j)
					dp[i] = min(dp[i], dp[j - 1] + b);
			} else fst[i - j + 1][hsh] = i;
			// dbg(dp[i]);
		}
	}
	// dbg_v(dp, n+ 1);
	cout << dp[n] << '\n';
}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;
using ull = long long;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 5005;
const ull B = 31;
const int MOD = 1e9 + 7;
int n, a, b, dp[N];
ull hsh;
string s;

unordered_map <int, int> fst[N];

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> a >> b;
	cin >> s;

	s = "#" + s;

	for(int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1] + a;

		hsh = 0;
		for(int j = i; j >= 1; j--) {
			hsh = (hsh * B + s[j] - 'a' + 1) % MOD;

			// dbg(i, j, hsh);
			if(fst[i - j + 1].count(hsh)) {
				// dbg(fst[i - j + 1][hsh], dp[j - 1]);
				if(fst[i - j + 1][hsh] < j)
					dp[i] = min(dp[i], dp[j - 1] + b);
			} else fst[i - j + 1][hsh] = i;
			// dbg(dp[i]);
		}
	}
	// dbg_v(dp, n+ 1);
	cout << dp[n] << '\n';
}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;
using ull = long long;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 5005;
const ull B = 31;
const int MOD = 1e9 + 17;
const int MODH = 1e7 + 67013;
int n, a, b, dp[N];
ull hsh, hsh1;
string s;

struct hasher {

	vector <pair<pair <int, int> , int >> v[MODH];

	void add(int hsh1, int hsh, int lg, int pos) {
		if(get(hsh1, hsh, lg) == -1)
			v[hsh1].push_back({{hsh, lg}, pos});
	}

	int get(int hsh1, int hsh, int lg) {
		for(auto i : v[hsh1])
			if(i.st == make_pair(hsh, lg))
				return i.nd;
		return -1;
	}
} hhh;

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> a >> b;
	cin >> s;

	s = "#" + s;

	for(int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1] + a;

		hsh = 0;
		hsh1 = 0;
		for(int j = i; j >= 1; j--) {
			hsh = (hsh * B + s[j] - 'a' + 1) % MOD;
			hsh1 = (hsh1 * B + s[j] - 'a' + 1) % MODH;

			int min_val = hhh.get(hsh1, hsh, i - j + 1);

			if(min_val != -1) {
				if(min_val < j)
					dp[i] = min(dp[i], dp[j - 1] + b);
			} else
				hhh.add(hsh1, hsh, i - j + 1, i);
		}
	}
	// dbg_v(dp, n+ 1);
	cout << dp[n] << '\n';
}