#include<bits/stdc++.h>
using namespace std;
long long n,q,col[100005],val[100005],vis[505],a,b,max1,max2,max3,ind1,ind2,ind3,dp[505];
int main()
{
	cin>>n>>q;
	col[0]=0;

	for(int i=1;i<=n;i++)
		cin>>val[i];
	for(int i=1;i<=n;i++)
		cin>>col[i];

	while(q--)
	{
		for(int j=0;j<502;j++)
			dp[j]=-1000000000000ll;
		memset(vis,0,sizeof(vis));
		cin>>a>>b;
		max1=0;max2=0;
		ind1=0;ind2=0;

		for(int i=1;i<=n;i++)
		{
			//if(vis[col[i]]!=0)
			dp[col[i]]=max(dp[col[i]],dp[col[i]]+a*val[i]);    // same as previous
			dp[col[i]]=max(dp[col[i]],b*val[i]);                   //  beginning

			//vis[col[i]]=1;

			if(col[ind1]!=col[i])
			{
				if(max1+b*val[i]>dp[col[i]])
					dp[col[i]]=max1+b*val[i];
			}
			else
			{
				if(max2+b*val[i]>dp[col[i]])
					dp[col[i]]=max2+b*val[i];
				continue;
			}

			max3=dp[col[i]];
			ind3=i;

			if(max3>max2)
			{
				swap(max3,max2);
				swap(ind3,ind2);
			}
			if(max2>max1)
			{
				swap(max1,max2);
				swap(ind1,ind2);
			}

		}
		cout<<max1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,q,col[100005],val[100005],vis[505],a,b,max1,max2,max3,ind1,ind2,ind3,dp[100005];
int main()
{
	cin>>n>>q;
	col[0]=0;

	for(int i=1;i<=n;i++)
		cin>>val[i-1];
	for(int i=1;i<=n;i++)
		cin>>col[i-1];

	while(q--)
	{
		for(int i=1;i<100002;i++)
			dp[i]=-1000000000000ll;
		cin>>a>>b;
		max1=0;max2=1;

		for(int i=0;i<n;i++)
		{
			dp[col[i]]=max(dp[col[i]],dp[col[i]]+a*val[i]);

			if(max1==col[i])
			{
				dp[col[i]]=max(dp[col[i]],dp[max2]+b*val[i]);
				continue;
			}
			else
				dp[col[i]]=max(dp[col[i]],dp[max1]+b*val[i]);

			if(dp[col[i]]>dp[max1])
			{
				max2=max1;
				max1=col[i];
			}
			else if(dp[col[i]]>=dp[max2])
				max2=col[i];
		}
		cout<<dp[max1]<<endl;
	}
	return 0;
}


//In the Name of God
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
typedef long long LL;

const LL maxn = 100000 + 10;
LL n , q , v[maxn] , c[maxn] , MAX[maxn] , a , b , ans , INF = LL(10000 * 10000) * LL(10000 * 10000);
bool ex[maxn];

struct cmp{
  bool operator() (LL a , LL b){
    if(MAX[a] != MAX[b])
      return MAX[a] < MAX[b];
    return a < b;
  }
};

set <LL , cmp> s;
set <LL> ::iterator it;

int main(){
  ios_base::sync_with_stdio(false);
  cin >> n >> q;
  for(LL i = 0 ; i < n ; i++)
    cin >> v[i];
  for(LL i = 0 ; i < n ; i++)
    cin >> c[i];
  for(LL z = 0 ; z < q ; z++){
    cin >> a >> b;
    s.clear();
    for(LL i = 0 ; i < n ; i++){
      ex[c[i]] = false;
      MAX[c[i]] = -INF;
    }
    for(LL i = 0 ; i < n ; i++)
      s.insert(c[i]);
    for(LL i = 0 ; i < n ; i++){
      LL ret = -INF , t = 0;
      it = s.end();
      it--;
      if(s.size() > 1 && *it == c[i])
	it--;
      if(s.size() > 1)
	t = max(t , MAX[*it]);
      ret = max(ret , t + b * v[i]);
      if(ex[c[i]])
	ret = max(ret , a * v[i] + MAX[c[i]]);
      ex[c[i]] = true;
      ret = max(ret , MAX[c[i]]);
      if(ret > MAX[c[i]]{
	  s.erase(c[i]);
	  MAX[c[i]] = ret;
	  s.insert(c[i]);
	}
      //      cout << ret << ' ' ;
    }
    ans = 0;
    for(LL i = 0 ; i < n ; i++)
      ans = max(ans , MAX[c[i]]);
    cout << ans << endl;
  }
  return 0;
}


//In the Name of God
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
typedef long long LL;

const LL maxn = 100000 + 10;
LL n , q , v[maxn] , c[maxn] , MAX[maxn] , a , b , ans , INF = LL(10000 * 10000) * LL(10000 * 10000);
bool ex[maxn];

struct cmp{
  bool operator() (LL a , LL b){
    if(MAX[a] != MAX[b])
      return MAX[a] < MAX[b];
    return a < b;
  }
};

set <LL , cmp> s;
set <LL> ::iterator it;

int main(){
  cin >> n >> q;
  for(LL i = 0 ; i < n ; i++)
    cin >> v[i];
  for(LL i = 0 ; i < n ; i++)
    cin >> c[i];
  for(LL z = 0 ; z < q ; z++){
    cin >> a >> b;
    s.clear();
    for(LL i = 0 ; i < n ; i++){
      ex[c[i]] = false;
      MAX[c[i]] = -INF;
    }
    for(LL i = 0 ; i < n ; i++)
      s.insert(c[i]);
    for(LL i = 0 ; i < n ; i++){
      LL ret = -INF , t = 0;
      it = s.end();
      it--;
      if(s.size() > 1 && *it == c[i])
	it--;
      if(s.size() > 1)
	t = max(t , MAX[*it]);
      ret = max(ret , t + b * v[i]);
      if(ex[c[i]])
	ret = max(ret , a * v[i] + MAX[c[i]]);
      ex[c[i]] = true;
      ret = max(ret , MAX[c[i]]);
      s.erase(c[i]);
      MAX[c[i]] = ret;
      s.insert(c[i]);
      //      cout << ret << ' ' ;
    }
    ans = 0;
    for(LL i = 0 ; i < n ; i++)
      ans = max(ans , MAX[c[i]]);
    cout << ans << endl;
  }
  return 0;
}


//In the Name of God
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
typedef long long LL;

const LL maxn = 100000 + 10;
LL n , q , v[maxn] , c[maxn] , MAX[maxn] , a , b , ans , INF = LL(10000 * 10000) * LL(10000 * 10000);
bool ex[maxn];

struct cmp{
  bool operator() (LL a , LL b){
    if(MAX[a] != MAX[b])
      return MAX[a] < MAX[b];
    return a < b;
  }
};

set <LL , cmp> s;
set <LL> ::iterator it;

int main(){
  ios_base::sync_with_stdio(false);
  cin >> n >> q;
  for(LL i = 0 ; i < n ; i++)
    cin >> v[i];
  for(LL i = 0 ; i < n ; i++)
    cin >> c[i];
  for(LL z = 0 ; z < q ; z++){
    cin >> a >> b;
    s.clear();
    for(LL i = 0 ; i < n ; i++){
      ex[c[i]] = false;
      MAX[c[i]] = -INF;
    }
    for(LL i = 0 ; i < n ; i++)
      s.insert(c[i]);
    for(LL i = 0 ; i < n ; i++){
      LL ret = -INF , t = 0;
      it = s.end();
      it--;
      if(s.size() > 1 && *it == c[i])
	it--;
      if(s.size() > 1)
	t = max(t , MAX[*it]);
      ret = max(ret , t + b * v[i]);
      if(ex[c[i]])
	ret = max(ret , a * v[i] + MAX[c[i]]);
      ex[c[i]] = true;
      ret = max(ret , MAX[c[i]]);
      if(ret > MAX[c[i]]){
	s.erase(c[i]);
	MAX[c[i]] = ret;
	s.insert(c[i]);
      }
      //      cout << ret << ' ' ;
    }
    ans = 0;
    for(LL i = 0 ; i < n ; i++)
      ans = max(ans , MAX[c[i]]);
    cout << ans << endl;
  }
  return 0;
}


//In the Name of God
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
typedef long long LL;

const LL maxn = 100000 + 10;
LL n , q , v[maxn] , c[maxn] , MAX[maxn] , a , b , ans , INF = LL(10000 * 10000) * LL(10000 * 10000);
bool ex[maxn];

struct cmp{
  bool operator() (LL a , LL b){
    if(MAX[a] != MAX[b])
      return MAX[a] < MAX[b];
    return a < b;
  }
};

set <LL , cmp> s , s1;
set <LL> ::iterator it;

int main(){
  ios_base::sync_with_stdio(false);
  cin >> n >> q;
  for(LL i = 0 ; i < n ; i++)
    cin >> v[i];
  for(LL i = 0 ; i < n ; i++)
    cin >> c[i];
  for(LL i = 0 ; i < n ; i++){
    MAX[c[i]] = -INF;
    s1.insert(c[i]);
  }
  for(LL z = 0 ; z < q ; z++){
    cin >> a >> b;
    s.clear();
    for(LL i = 0 ; i < n ; i++){
      ex[c[i]] = false;
      MAX[c[i]] = -INF;
    }
    s = s1;
    for(LL i = 0 ; i < n ; i++){
      LL ret = -INF , t = 0;
      it = s.end();
      it--;
      if(s.size() > 1 && *it == c[i])
	it--;
      if(s.size() > 1)
	t = max(t , MAX[*it]);
      ret = max(ret , t + b * v[i]);
      if(ex[c[i]])
	ret = max(ret , a * v[i] + MAX[c[i]]);
      ex[c[i]] = true;
      ret = max(ret , MAX[c[i]]);
      if(ret > MAX[c[i]]){
	s.erase(c[i]);
	MAX[c[i]] = ret;
	s.insert(c[i]);
      }
      //      cout << ret << ' ' ;
    }
    it = s.end();
    it--;
    cout << MAX[*it] << endl;
  }
  return 0;
}


//In the Name of God
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
typedef long long LL;

const LL maxn = 100000 + 10;
LL n , q , v[maxn] , c[maxn] , MAX[maxn] , a , b , ans , INF = LL(10000 * 10000) * LL(10000 * 10000) , MAX1 , MAX2;
bool ex[maxn];

int main(){
  ios_base::sync_with_stdio(false);
  cin >> n >> q;
  for(LL i = 0 ; i < n ; i++)
    cin >> v[i];
  for(LL i = 0 ; i < n ; i++)
    cin >> c[i];
  for(LL z = 0 ; z < q ; z++){
    cin >> a >> b;
    for(LL i = 0 ; i < n ; i++){
      ex[c[i]] = false;
      MAX[c[i]] = -INF;
    }
    MAX1 = 1;
    MAX2 = 2;
    for(LL i = 0 ; i < n ; i++){
      LL ret = -INF , t = 0;
      if(MAX1 != c[i])
	t = max(t , MAX[MAX1]);
      else
	t = max(t , MAX[MAX2]);
      ret = max(ret , t + b * v[i]);
      if(ex[c[i]])
	ret = max(ret , a * v[i] + MAX[c[i]]);
      ex[c[i]] = true;
      ret = max(ret , MAX[c[i]]);
      if(ret > MAX[c[i]]){
	MAX[c[i]] = ret;
	if(ret > MAX[MAX1] && MAX1 != c[i]){
	  MAX2 = MAX1;
	  MAX1 = c[i];
	}
	else if(ret > MAX[MAX2] && MAX2 != c[i] && MAX1 != c[i])
	  MAX2 = c[i];
      }
      //      cout << ret << ' ' << MAX1 <<  ' ' << MAX2 << endl;
    }
    cout << max(LL(0) , MAX[MAX1]) << endl;
  }
  return 0;
}


//In the Name of God
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
typedef long long LL;

const LL maxn = 100000 + 10;
LL n , q , v[maxn] , c[maxn] , MAX[maxn] , a , b , ans , INF = LL(10000 * 10000) * LL(10000 * 10000);
bool ex[maxn];

struct cmp{
  bool operator() (LL a , LL b){
    if(MAX[a] != MAX[b])
      return MAX[a] < MAX[b];
    return a < b;
  }
};

set <LL , cmp> s;
set <LL> ::iterator it;

int main(){
  ios_base::sync_with_stdio(false);
  cin >> n >> q;
  for(LL i = 0 ; i < n ; i++)
    cin >> v[i];
  for(LL i = 0 ; i < n ; i++)
    cin >> c[i];
  for(LL z = 0 ; z < q ; z++){
    cin >> a >> b;
    s.clear();
    for(LL i = 0 ; i < n ; i++){
      ex[c[i]] = false;
      MAX[c[i]] = -INF;
    }
    for(LL i = 0 ; i < n ; i++)
      s.insert(c[i]);
    for(LL i = 0 ; i < n ; i++){
      LL ret = -INF , t = 0;
      it = s.end();
      it--;
      if(s.size() > 1 && *it == c[i])
	it--;
      if(s.size() > 1)
	t = max(t , MAX[*it]);
      ret = max(ret , t + b * v[i]);
      if(ex[c[i]])
	ret = max(ret , a * v[i] + MAX[c[i]]);
      ex[c[i]] = true;
      ret = max(ret , MAX[c[i]]);
      s.erase(c[i]);
      MAX[c[i]] = ret;
      s.insert(c[i]);
      //      cout << ret << ' ' ;
    }
    ans = 0;
    for(LL i = 0 ; i < n ; i++)
      ans = max(ans , MAX[c[i]]);
    cout << ans << endl;
  }
  return 0;
}


//In the Name of God
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
typedef long long LL;

const LL maxn = 100000 + 10;
LL n , q , v[maxn] , c[maxn] , MAX[maxn] , a , b , ans;
bool ex[maxn];

struct cmp{
  bool operator() (LL a , LL b){
    if(MAX[a] != MAX[b])
      return MAX[a] < MAX[b];
    return a < b;
  }
};

set <LL , cmp> s;
set <LL> ::iterator it;

int main(){
  cin >> n >> q;
  for(LL i = 0 ; i < n ; i++)
    cin >> v[i];
  for(LL i = 0 ; i < n ; i++)
    cin >> c[i];
  for(LL z = 0 ; z < q ; z++){
    cin >> a >> b;
    s.clear();
    for(LL i = 0 ; i < n ; i++){
      ex[c[i]] = false;
      MAX[c[i]] = 0;
    }
    for(LL i = 0 ; i < n ; i++)
      s.insert(c[i]);
    for(LL i = 0 ; i < n ; i++){
      bool sw = false;
      LL ret = 0;
      if(ex[c[i]]){
	if(MAX[c[i]] + a * v[i] >= ret){
	  ret = MAX[c[i]] + a * v[i];
	  sw = true;
	}
      }
      it = s.end();
      it--;
      if(*it == c[i])
	it--;
      LL t = 0;
      if(LL(s.size()) > 1)
	t = MAX[*it];
      if(t + b * v[i] >= ret){
	ret = t + b * v[i];
	sw = true;
      }
      if(ret >= MAX[c[i]]){
	s.erase(c[i]);
	MAX[c[i]] = ret;
	s.insert(c[i]);
	if(sw)
	  ex[c[i]] = true;
      }
      //cout << ret << ' ' << ex[c[i]] << endl;
    }
    ans = 0;
    for(LL i = 0 ; i < n ; i++)
      ans = max(ans , MAX[c[i]]);
    cout << ans << endl;
  }
  return 0;
}


//In the Name of God
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
typedef long long LL;

const LL maxn = 100000 + 10;
LL n , q , v[maxn] , c[maxn] , MAX[maxn] , a , b , ans , INF = LL(10000 * 10000) * LL(10000 * 10000);
bool ex[maxn];

struct cmp{
  bool operator() (LL a , LL b){
    if(MAX[a] != MAX[b])
      return MAX[a] < MAX[b];
    return a < b;
  }
};

set <LL , cmp> s , s1;
set <LL> ::iterator it;

int main(){
  ios_base::sync_with_stdio(false);
  cin >> n >> q;
  for(LL i = 0 ; i < n ; i++)
    cin >> v[i];
  for(LL i = 0 ; i < n ; i++)
    cin >> c[i];
  for(LL i = 0 ; i < n ; i++){
    MAX[c[i]] = -INF;
    s1.insert(c[i]);
  }
  for(LL z = 0 ; z < q ; z++){
    cin >> a >> b;
    s.clear();
    for(LL i = 0 ; i < n ; i++){
      ex[c[i]] = false;
      MAX[c[i]] = -INF;
    }
    s = s1;
    for(LL i = 0 ; i < n ; i++){
      LL ret = -INF , t = 0;
      it = s.end();
      it--;
      if(s.size() > 1 && *it == c[i])
	it--;
      if(s.size() > 1)
	t = max(t , MAX[*it]);
      ret = max(ret , t + b * v[i]);
      if(ex[c[i]])
	ret = max(ret , a * v[i] + MAX[c[i]]);
      ex[c[i]] = true;
      ret = max(ret , MAX[c[i]]);
      if(ret > MAX[c[i]]){
	s.erase(c[i]);
	MAX[c[i]] = ret;
	s.insert(c[i]);
      }
      //      cout << ret << ' ' ;
    }
    ans = 0;
    for(LL i = 0 ; i < n ; i++)
      ans = max(ans , MAX[c[i]]);
    cout << ans << endl;
  }
  return 0;
}


//In the Name of God
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
typedef long long LL;

const LL maxn = 100000 + 10;
LL n , q , v[maxn] , c[maxn] , MAX[maxn] , a , b , ans;
bool ex[maxn];

struct cmp{
  bool operator() (LL a , LL b){
    if(MAX[a] != MAX[b])
      return MAX[a] < MAX[b];
    return a < b;
  }
};

set <LL , cmp> s;
set <LL> ::iterator it;

int main(){
  cin >> n >> q;
  for(LL i = 0 ; i < n ; i++)
    cin >> v[i];
  for(LL i = 0 ; i < n ; i++)
    cin >> c[i];
  for(LL z = 0 ; z < q ; z++){
    cin >> a >> b;
    s.clear();
    for(LL i = 0 ; i < n ; i++){
      ex[c[i]] = false;
      MAX[c[i]] = 0;
    }
    for(LL i = 0 ; i < n ; i++)
      s.insert(c[i]);
    for(LL i = 0 ; i < n ; i++){
      bool sw = false;
      LL ret = 0;
      if(ex[c[i]]){
	if(MAX[c[i]] + a * v[i] >= ret){
	  ret = MAX[c[i]] + a * v[i];
	  sw = true;
	}
      }
      it = s.end();
      it--;
      if(*it == c[i])
	it--;
      if(LL(s.size()) > 1 && MAX[*it] + b * v[i] >= ret){
	ret = MAX[*it] + b * v[i];
	sw = true;
      }
      if(ret >= MAX[c[i]]){
	s.erase(c[i]);
	MAX[c[i]] = ret;
	s.insert(c[i]);
	if(sw)
	  ex[c[i]] = true;
      }
      //      cout << ret << ' ' << ex[c[i]] << endl;
    }
    ans = 0;
    for(LL i = 0 ; i < n ; i++)
      ans = max(ans , MAX[c[i]]);
    cout << ans << endl;
  }
  return 0;
}


//In the Name of God
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
typedef long long LL;

const LL maxn = 100000 + 10;
LL n , q , v[maxn] , c[maxn] , MAX[maxn] , a , b , ans , INF = LL(10000 * 10000) * LL(10000 * 10000);
bool ex[maxn];

struct cmp{
  bool operator() (LL a , LL b){
    if(MAX[a] != MAX[b])
      return MAX[a] < MAX[b];
    return a < b;
  }
};

set <LL , cmp> s , s1;
set <LL> ::iterator it;

int main(){
  ios_base::sync_with_stdio(false);
  cin >> n >> q;
  for(LL i = 0 ; i < n ; i++)
    cin >> v[i];
  for(LL i = 0 ; i < n ; i++)
    cin >> c[i];
  for(LL i = 0 ; i < n ; i++){
    MAX[c[i]] = -INF;
    s1.insert(c[i]);
  }
  for(LL z = 0 ; z < q ; z++){
    cin >> a >> b;
    s.clear();
    for(LL i = 0 ; i < n ; i++){
      ex[c[i]] = false;
      MAX[c[i]] = -INF;
    }
    s = s1;
    for(LL i = 0 ; i < n ; i++){
      LL ret = -INF , t = 0;
      it = s.end();
      it--;
      if(s.size() > 1 && *it == c[i])
	it--;
      if(s.size() > 1)
	t = max(t , MAX[*it]);
      ret = max(ret , t + b * v[i]);
      if(ex[c[i]])
	ret = max(ret , a * v[i] + MAX[c[i]]);
      ex[c[i]] = true;
      ret = max(ret , MAX[c[i]]);
      if(ret > MAX[c[i]]){
	s.erase(c[i]);
	MAX[c[i]] = ret;
	s.insert(c[i]);
      }
      //      cout << ret << ' ' ;
    }
    it = s.end();
    it--;
    cout << max(LL(0) , MAX[*it]) << endl;
  }
  return 0;
}


#include<iostream>
#include<set>
#include<algorithm>
using namespace std;

const int maxn = 1000 * 100;
int n, q, c[maxn], r, s1, s2;
long long v[maxn], dp[maxn], a, b;
set<pair<long long, int> > s;

int main()
{
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	for(int i = 0; i < n; i++)
	{
		cin >> c[i];
		c[i]--;
	}
	for(int t = 0; t < q; t++)
	{
		cin >> a >> b;
		s.clear();
		for(int i = 0; i < n; i++)
		{
			r = c[i];
			if(s.find(make_pair(dp[r], r)) == s.end())
			{
				dp[r] = v[i] * b;
				s.insert(make_pair(dp[r], r));
			}
			else if(max(max(dp[r], v[i] * b), dp[r] + (v[i] * a)) != dp[r])
			{
				s.erase(make_pair(dp[r], r));
				dp[r] = max(max(dp[r], v[i] * b), dp[r] + (v[i] * a));
				s.insert(make_pair(dp[r], r));
			}
			if(s.size() > 1)
			{
				s1 = (--s.end()) -> first;
				s2 = (--s.end()) -> second;
				if(s2 == r)
				{
					s.erase(--s.end());
					s1 = (--s.end()) -> first;
					s2 = (--s.end()) -> second;
					dp[r] = max(dp[r], s1 + (v[i] * b));
					s.insert(make_pair(dp[r], r));
				}
				else if(max(dp[r], s1 + (v[i] * b)) != dp[r])
				{
					s.erase(make_pair(dp[r], r));
					dp[r] = max(dp[r], s1 + (v[i] * b));
					s.insert(make_pair(dp[r], r));
				}
			}
		}
		cout << max((--s.end()) -> first , (long long) 0) << endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

const int maxn = 1000 * 100;
int n, c[maxn], q, r1, r2, r;
bool chek[maxn], ch1, ch2;
long long v[maxn], dp[maxn], a, b, x1, x2, x;

long long f()
{
	for(int i = 0; i < n; i++)
		chek[i] = false;
	ch1 = false;
	ch2 = false;
	for(int i = 0; i < n; i++)
	{
		r = c[i];
		x = v[i];
		if(chek[r] == false)
		{
			dp[r] = x * b;
			chek[r] = true;
		}
		else
			dp[r] = max(dp[r], max(x * b, dp[r] + x * a));
		if(ch1 == false && ch2 == false)
		{
			ch2 = true;
			x2 = dp[r];
			r2 = r;
		}
		else if(ch1 == false)
		{
			if(r2 == r)
				x2 = dp[r];
			else
			{
				dp[r] = max(dp[r], x2 + x * b);
				if(dp[r] > x2)
				{
					x1 = dp[r];
					r1 = r;
					ch1 = true;
				}
				else
				{
					x1 = x2;
					r1 = r2;
					x2 = dp[r];
					r2 = r;
					ch1 = true;
				}
			}
		}
		else if(r1 == r)
		{
			dp[r] = max(dp[r], x2 + x * b);
			x1 = dp[r];
		}
		else if(r2 == r)
		{
			dp[r] = max(dp[r], x1 + x * b);
			x2 = dp[r];
			if(x2 > x1)
			{
				swap(x1, x2);
				swap(r1, r2);
			}
		}
		else
		{
			dp[r] = max(dp[r], x1 + x * b);
			if(x1 < dp[r])
			{
				x2 = x1;
				r2 = r1;
				x1 = dp[r];
				r1 = r;
			}
			else if(x2 < dp[r])
			{
				x2 = dp[r];
				r2 = r;
			}
		}
	}
	if(ch1 == false)
		return max(x2, (long long) 0);
	return max(x1, (long long) 0);
}

int main()
{
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	for(int i = 0; i < n; i++)
	{
		cin >> c[i];
		c[i]--;
	}
	for(int i = 0; i < q; i++)
	{
		cin >> a >> b;
		cout << f() << endl;
	}
	return 0;
}


#include<iostream>
#include<set>
#include<algorithm>
using namespace std;

const int maxn = 1000 * 100;
int n, q, c[maxn];
long long v[maxn], dp[maxn];

long long f(long long a, long long b)
{
	int r, s2;
	long long x, s1;
	set<pair<long long, int> > s;
	for(int i = 0; i < n; i++)
	{
		r = c[i];
		x = v[i];
		if(s.find(make_pair(dp[r], r)) == s.end())
		{
			dp[r] = x * b;
			s.insert(make_pair(dp[r], r));
		}
		else
		{
			s.erase(make_pair(dp[r], r));
			dp[r] = max(max(dp[r], x * b), dp[r] + (x * a));
			s.insert(make_pair(dp[r], r));
		}
		if(s.size() > 1)
		{
			s1 = (--s.end()) -> first;
			s2 = (--s.end()) -> second;
			if(s2 == r)
			{
				s.erase(--s.end());
				s1 = (--s.end()) -> first;
				s2 = (--s.end()) -> second;
				dp[r] = max(dp[r], s1 + (x * b));
				s.insert(make_pair(dp[r], r));
			}
			else
			{
				s.erase(make_pair(dp[r], r));
				dp[r] = max(dp[r], s1 + (x * b));
				s.insert(make_pair(dp[r], r));
			}
		}
	}
	x = (--s.end()) -> first;
	return max(x, 0);
}

int main()
{
	int x, y;
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	for(int i = 0; i < n; i++)
	{
		cin >> c[i];
		c[i]--;
	}
	for(int i = 0; i < q; i++)
	{
		cin >> x >> y;
		cout << f(x, y) << endl;
	}
	return 0;
}


#include<iostream>
#include<set>
#include<algorithm>
using namespace std;

const int maxn = 1000 * 100;
int n, q, c[maxn];
long long v[maxn], dp[maxn];

long long f(long long a, long long b)
{
	int r, s2;
	long long x, s1;
	set<pair<long long, int> > s;
	for(int i = 0; i < n; i++)
	{
		r = c[i];
		x = v[i];
		if(s.find(make_pair(dp[r], r)) == s.end())
		{
			dp[r] = x * b;
			s.insert(make_pair(dp[r], r));
		}
		else
		{
			s.erase(make_pair(dp[r], r));
			dp[r] = max(max(dp[r], x * b), dp[r] + (x * a));
			s.insert(make_pair(dp[r], r));
		}
		if(s.size() > 1)
		{
			s1 = (--s.end()) -> first;
			s2 = (--s.end()) -> second;
			if(s2 == r)
			{
				s.erase(--s.end());
				s1 = (--s.end()) -> first;
				s2 = (--s.end()) -> second;
				dp[r] = max(dp[r], s1 + (x * b));
				s.insert(make_pair(dp[r], r));
			}
			else
			{
				s.erase(make_pair(dp[r], r));
				dp[r] = max(dp[r], s1 + (x * b));
				s.insert(make_pair(dp[r], r));
			}
		}
	}
	x = (--s.end()) -> first;
	return max(x, (long long) 0);
}

int main()
{
	int x, y;
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	for(int i = 0; i < n; i++)
	{
		cin >> c[i];
		c[i]--;
	}
	for(int i = 0; i < q; i++)
	{
		cin >> x >> y;
		cout << f(x, y) << endl;
	}
	return 0;
}


#include<iostream>
#include<set>
#include<algorithm>
using namespace std;

const int maxn = 1000 * 100;
int n, q, c[maxn], r, s2;
long long v[maxn], dp[maxn], a, b, s1;
set<pair<long long, int> > s;

int main()
{
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	for(int i = 0; i < n; i++)
	{
		cin >> c[i];
		c[i]--;
	}
	for(int t = 0; t < q; t++)
	{
		cin >> a >> b;
		s.clear();
		for(int i = 0; i < n; i++)
		{
			r = c[i];
			if(s.find(make_pair(dp[r], r)) == s.end())
			{
				dp[r] = v[i] * b;
				s.insert(make_pair(dp[r], r));
			}
			else if(max(max(dp[r], v[i] * b), dp[r] + (v[i] * a)) != dp[r])
			{
				s.erase(make_pair(dp[r], r));
				dp[r] = max(max(dp[r], v[i] * b), dp[r] + (v[i] * a));
				s.insert(make_pair(dp[r], r));
			}
			if(s.size() > 1)
			{
				s1 = (--s.end()) -> first;
				s2 = (--s.end()) -> second;
				if(s2 == r)
				{
					s.erase(--s.end());
					s1 = (--s.end()) -> first;
					s2 = (--s.end()) -> second;
					dp[r] = max(dp[r], s1 + (v[i] * b));
					s.insert(make_pair(dp[r], r));
				}
				else if(max(dp[r], s1 + (v[i] * b)) != dp[r])
				{
					s.erase(make_pair(dp[r], r));
					dp[r] = max(dp[r], s1 + (v[i] * b));
					s.insert(make_pair(dp[r], r));
				}
			}
		}
		cout << max((--s.end()) -> first , (long long) 0) << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;

const int maxn = 1000 * 100;
int n, c[maxn], q, r1, r2, r;
bool chek[maxn], ch1, ch2;
long long v[maxn], dp[maxn], a, b, x1, x2, x;

long long f()
{
	for(int i = 0; i < n; i++)
		chek[i] = false;
	ch1 = false;
	ch2 = false;
	for(int i = 0; i < n; i++)
	{
		r = c[i];
		x = v[i];
		if(chek[r] == false)
		{
			dp[r] = x * b;
			chek[r] = true;
		}
		else
			dp[r] = max(dp[r], max(x * b, dp[r] + x * a));
		if(ch1 == false && ch2 == false)
		{
			ch2 = true;
			x2 = dp[r];
			r2 = r;
		}
		else if(ch1 == false)
		{
			if(r2 == r)
				x2 = dp[r];
			else if(dp[r] > x2)
			{
				x1 = dp[r];
				r1 = r;
				ch1 = true;
			}
			else
			{
				x1 = x2;
				r1 = r2;
				x2 = dp[r];
				r2 = r;
				ch1 = true;
			}
		}
		else if(r1 == r)
		{
			dp[r] = max(dp[r], x2 + x * b);
			x1 = dp[r];
		}
		else if(r2 == r)
		{
			dp[r] = max(dp[r], x1 + x * b);
			x2 = dp[r];
			if(x2 > x1)
			{
				swap(x1, x2);
				swap(r1, r2);
			}
		}
		else
		{
			dp[r] = max(dp[r], x1 + x * b);
			if(x1 < dp[r])
			{
				x2 = x1;
				r2 = r1;
				x1 = dp[r];
				r1 = r;
			}
			else if(x2 < dp[r])
			{
				x2 = dp[r];
				r2 = r;
			}
		}
	}
	if(ch1 == false)
		return max(x2, (long long) 0);
	return max(x1, (long long) 0);
}

int main()
{
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	for(int i = 0; i < n; i++)
		cin >> c[i];
	for(int i = 0; i < q; i++)
	{
		cin >> a >> b;
		cout << f() << endl;
	}
	return 0;
}


#include<iostream>
#include<set>
#include<algorithm>
using namespace std;

const int maxn = 1000 * 100;
int n, q, c[maxn];
long long v[maxn], dp[maxn];

long long f(long long a, long long b)
{
	int r, s2;
	long long x, s1;
	set<pair<long long, int> > s;
	for(int i = 0; i < n; i++)
	{
		r = c[i];
		x = v[i];
		if(s.find(make_pair(dp[r], r)) == s.end())
		{
			dp[r] = x * b;
			s.insert(make_pair(dp[r], r));
		}
		else
		{
			s.erase(make_pair(dp[r], r));
			dp[r] = max(max(dp[r], x * b), dp[r] + (x * a));
			s.insert(make_pair(dp[r], r));
		}
		if(s.size() > 1)
		{
			s1 = (--s.end()) -> first;
			s2 = (--s.end()) -> second;
			if(s2 == r)
			{
				s.erase(--s.end());
				s1 = (--s.end()) -> first;
				s2 = (--s.end()) -> second;
				dp[r] = max(dp[r], s1 + (x * b));
				s.insert(make_pair(dp[r], r));
			}
			else
			{
				s.erase(make_pair(dp[r], r));
				dp[r] = max(dp[r], s1 + (x * b));
				s.insert(make_pair(dp[r], r));
			}
		}
	}
	x = (--s.end()) -> first;
	return x;
}

int main()
{
	int x, y;
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	for(int i = 0; i < n; i++)
	{
		cin >> c[i];
		c[i]--;
	}
	for(int i = 0; i < q; i++)
	{
		cin >> x >> y;
		cout << f(x, y) << endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

const int maxn = 1000 * 100;
int n, c[maxn], q, r1, r2, r;
bool chek[maxn], ch1, ch2;
long long v[maxn], dp[maxn], a, b, x1, x2, x;

long long f()
{
	for(int i = 0; i < n; i++)
		chek[i] = false;
	ch1 = false;
	ch2 = false;
	for(int i = 0; i < n; i++)
	{
		r = c[i];
		x = v[i];
		if(chek[r] == false)
		{
			dp[r] = x * b;
			chek[r] = true;
		}
		else
			dp[r] = max(dp[r], max(x * b, dp[r] + x * a));
		if(ch1 == false && ch2 == false)
		{
			ch2 = true;
			x2 = dp[r];
			r2 = r;
		}
		else if(ch1 == false)
		{
			if(r2 == r)
				x2 = dp[r];
			else
			{
				dp[r] = max(dp[r], x2 + x * b);
				if(dp[r] > x2)
				{
					x1 = dp[r];
					r1 = r;
					ch1 = true;
				}
				else
				{
					x1 = x2;
					r1 = r2;
					x2 = dp[r];
					r2 = r;
					ch1 = true;
				}
			}
		}
		else if(r1 == r)
		{
			dp[r] = max(dp[r], x2 + x * b);
			x1 = dp[r];
		}
		else if(r2 == r)
		{
			dp[r] = max(dp[r], x1 + x * b);
			x2 = dp[r];
			if(x2 > x1)
			{
				swap(x1, x2);
				swap(r1, r2);
			}
		}
		else
		{
			dp[r] = max(dp[r], x1 + x * b);
			if(x1 < dp[r])
			{
				x2 = x1;
				r2 = r1;
				x1 = dp[r];
				r1 = r;
			}
			else if(x2 < dp[r])
			{
				x2 = dp[r];
				r2 = r;
			}
		}
	}
	if(ch1 == false)
		return max(x2, (long long) 0);
	return max(x1, (long long) 0);
}

int main()
{
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	for(int i = 0; i < n; i++)
		cin >> c[i];
	for(int i = 0; i < q; i++)
	{
		cin >> a >> b;
		cout << f() << endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

const int maxn = 1000 * 100;
int n, c[maxn], q, r1, r2, r;
bool chek[maxn], ch1, ch2;
long long v[maxn], dp[maxn], a, b, x1, x2, x;

long long f()
{
	for(int i = 0; i < n; i++)
		chek[i] = false;
	ch1 = false;
	ch2 = false;
	for(int i = 0; i < n; i++)
	{
		r = c[i];
		x = v[i];
		if(chek[r] == false)
		{
			dp[r] = x * b;
			chek[r] = true;
		}
		else
			dp[r] = max(dp[r], max(x * b, dp[r] + x * a));
		if(ch1 == false && ch2 == false)
		{
			ch2 = true;
			x2 = dp[r];
			r2 = r;
		}
		else if(ch1 == false)
		{
			if(r2 == r)
				x2 = dp[r];
			else
			{
				dp[r] = max(dp[r], x2 + x * b);
				if(dp[r] > x2)
				{
					x1 = dp[r];
					r1 = r;
					ch1 = true;
				}
				else
				{
					x1 = x2;
					r1 = r2;
					x2 = dp[r];
					r2 = r;
					ch1 = true;
				}
			}
		}
		else if(r1 == r)
		{
			dp[r] = max(dp[r], x2 + x * b);
			x1 = dp[r];
		}
		else if(r2 == r)
		{
			dp[r] = max(dp[r], x1 + x * b);
			x2 = dp[r];
			if(x2 > x1)
			{
				swap(x1, x2);
				swap(r1, r2);
			}
		}
		else
		{
			dp[r] = max(dp[r], x1 + x * b);
			if(x1 < dp[r])
			{
				x2 = x1;
				r2 = r1;
				x1 = dp[r];
				r1 = r;
			}
			else if(x2 < dp[r])
			{
				x2 = dp[r];
				r2 = r;
			}
		}
		//cout << r + 1 << " " << dp[r] << endl;
		//if(ch1 == true)
			//cout << "first :" << x1 << " " << r1 + 1 << endl;
		//else
			//cout << "first : " << x2 << " " << r2 + 1 << endl;
	}
	if(ch1 == false)
		return max(x2, (long long) 0);
	return max(x1, (long long) 0);
}

int main()
{
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	for(int i = 0; i < n; i++)
	{
		cin >> c[i];
		c[i]--;
	}
	for(int i = 0; i < q; i++)
	{
		cin >> a >> b;
		cout << f() << endl;
	}
	return 0;
}


#include<iostream>
#include<set>
#include<algorithm>
using namespace std;

const int maxn = 1000 * 100;
int n, q, c[maxn], r, s1, s2;
long int v[maxn], dp[maxn], a, b;
set<pair<long int, int> > s;

int main()
{
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	for(int i = 0; i < n; i++)
	{
		cin >> c[i];
		c[i]--;
	}
	for(int t = 0; t < q; t++)
	{
		cin >> a >> b;
		s.clear();
		for(int i = 0; i < n; i++)
		{
			r = c[i];
			if(s.find(make_pair(dp[r], r)) == s.end())
			{
				dp[r] = v[i] * b;
				s.insert(make_pair(dp[r], r));
			}
			else if(max(max(dp[r], v[i] * b), dp[r] + (v[i] * a)) != dp[r])
			{
				s.erase(make_pair(dp[r], r));
				dp[r] = max(max(dp[r], v[i] * b), dp[r] + (v[i] * a));
				s.insert(make_pair(dp[r], r));
			}
			if(s.size() > 1)
			{
				s1 = (--s.end()) -> first;
				s2 = (--s.end()) -> second;
				if(s2 == r)
				{
					s.erase(--s.end());
					s1 = (--s.end()) -> first;
					s2 = (--s.end()) -> second;
					dp[r] = max(dp[r], s1 + (v[i] * b));
					s.insert(make_pair(dp[r], r));
				}
				else if(max(dp[r], s1 + (v[i] * b)) != dp[r])
				{
					s.erase(make_pair(dp[r], r));
					dp[r] = max(dp[r], s1 + (v[i] * b));
					s.insert(make_pair(dp[r], r));
				}
			}
		}
		cout << max((--s.end()) -> first , (long int) 0) << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;

const int maxn = 1000 * 100;
int n, c[maxn], q, r1, r2, r;
bool chek[maxn], ch1, ch2;
long long v[maxn], dp[maxn], a, b, x1, x2, x;

long long f()
{
	for(int i = 0; i < n; i++)
		chek[i] = false;
	ch1 = false;
	ch2 = false;
	for(int i = 0; i < n; i++)
	{
		r = c[i];
		x = v[i];
		if(chek[r] == false)
		{
			dp[r] = x * b;
			chek[r] = true;
		}
		else
			dp[r] = max(dp[r], max(x * b, dp[r] + x * a));
		if(ch1 == false && ch2 == false)
		{
			ch2 = true;
			x2 = dp[r];
			r2 = r;
		}
		else if(ch1 == false)
		{
			if(r2 == r)
				x2 = dp[r];
			else if(dp[r] > x2)
			{
				x1 = dp[r];
				r1 = r;
				ch1 = true;
			}
			else
			{
				x1 = x2;
				r1 = r2;
				x2 = dp[r];
				r2 = r;
				ch1 = true;
			}
		}
		else if(r1 == r)
		{
			dp[r] = max(dp[r], x2 + x * b);
			x1 = dp[r];
		}
		else if(r2 == r)
		{
			dp[r] = max(dp[r], x1 + x * b);
			x2 = dp[r];
			if(x2 > x1)
			{
				swap(x1, x2);
				swap(r1, r2);
			}
		}
		else
		{
			dp[r] = max(dp[r], x1 + x * b);
			if(x1 < dp[r])
			{
				x2 = x1;
				r2 = r1;
				x1 = dp[r];
				r1 = r;
			}
			else if(x2 < dp[r])
			{
				x2 = dp[r];
				r2 = r;
			}
		}
	}
	return max(x1, (long long) 0);
}

int main()
{
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	for(int i = 0; i < n; i++)
		cin >> c[i];
	for(int i = 0; i < q; i++)
	{
		cin >> a >> b;
		cout << f() << endl;
	}
	return 0;
}


#include<iostream>
#include<set>
#include<algorithm>
using namespace std;

const int maxn = 1000 * 100;
int n, q, c[maxn];
long long v[maxn], dp[maxn];

long long f(long long a, long long b)
{
	int r, s2;
	long long x, s1;
	set<pair<long long, int> > s;
	for(int i = 0; i < n; i++)
	{
		r = c[i];
		x = v[i];
		if(s.find(make_pair(dp[r], r)) == s.end())
		{
			dp[r] = x * b;
			s.insert(make_pair(dp[r], r));
		}
		else if(max(max(dp[r], x * b), dp[r] + (x * a)) != dp[r])
		{
			s.erase(make_pair(dp[r], r));
			dp[r] = max(max(dp[r], x * b), dp[r] + (x * a));
			s.insert(make_pair(dp[r], r));
		}
		if(s.size() > 1)
		{
			s1 = (--s.end()) -> first;
			s2 = (--s.end()) -> second;
			if(s2 == r)
			{
				s.erase(--s.end());
				s1 = (--s.end()) -> first;
				s2 = (--s.end()) -> second;
				dp[r] = max(dp[r], s1 + (x * b));
				s.insert(make_pair(dp[r], r));
			}
			else if(max(dp[r], s1 + (x * b)) != dp[r])
			{
				s.erase(make_pair(dp[r], r));
				dp[r] = max(dp[r], s1 + (x * b));
				s.insert(make_pair(dp[r], r));
			}
		}
	}
	x = (--s.end()) -> first;
	return max(x, (long long) 0);
}

int main()
{
	int x, y;
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	for(int i = 0; i < n; i++)
	{
		cin >> c[i];
		c[i]--;
	}
	for(int i = 0; i < q; i++)
	{
		cin >> x >> y;
		cout << f(x, y) << endl;
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <string.h>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <limits.h>
#include <time.h>
#include <bitset>
#include <list>
#include <cassert>

#define EPS 1e-11
#define PI acos(-1)
#define LL long long
#define INF 1000000009
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define OPENR(a) freopen(a,"r",stdin)
#define OPENW(a) freopen(a,"w",stdout)
#define pii pair<int,int>

int x4[4] = { 0, 0,-1, 1};
int y4[4] = {-1, 1, 0, 0};
int x8[8] = {-1,-1,-1, 0, 0, 1, 1, 1};
int y8[8] = {-1, 0, 1,-1, 1,-1, 0, 1};
int xhorse[8] = {1,2,1,2,-1,-2,-1,-2};
int yhorse[8] = {2,1,-2,-1,2,1,-2,-1};

using namespace std;

#define MAXN 100005

int n,q;
LL v[MAXN],c[MAXN];
LL dp[MAXN];
bool ada[MAXN];

int main()
{
	scanf("%d %d",&n,&q);;

	for (LL i=0;i<n;i++) scanf("%I64d",&v[i]);
	for (LL i=0;i<n;i++) scanf("%I64d",&c[i]);

	while(q--)
	{
		LL a,b;
		scanf("%I64d %I64d",&a,&b);

		memset(dp,0,sizeof(dp));
		memset(ada, false,sizeof(ada));

		LL ans = 0;
		LL maxi[2];
		maxi[0] = maxi[1] = INF;
		for(LL i=0;i<n;i++)
		{
			LL col = c[i];
			if (ada[col])
			{
				dp[col] = max(dp[col], dp[col] + a*v[i]); // lanjutin warna yang sama
				dp[col] = max(dp[col], b*v[i]); // start baru
			}
			else
			{
				dp[col] = b*v[i]; // mau ga mau start baru
				ada[col] = true;
			}

			LL other = maxi[0]; // ambil warna yang valuenya max
			if (col==other) other = maxi[1]; //kalo warna nya sama, ganti warna

			if (other!=INF) dp[col] = max(dp[col], dp[other] + b*v[i]); //kalo ada si warna lainnya, cek lanjutin warna itu

			if (maxi[0]!=col && maxi[1]!=col) //coba masukin current color ke 2 maksimum
			{
				if (maxi[0]==INF) maxi[0] = col; //isi yang kosong (INF) sama warna ini
				else if (maxi[1]==INF) maxi[1] = col; //isi yang kosong (INF) sama warna ini
				else if (dp[maxi[1]] < dp[col]) maxi[1] = col; //ganti warna terkecil nya ke col

				if (maxi[0]!=INF && maxi[1]!=INF && dp[maxi[0]] < dp[maxi[1]]) swap(maxi[0], maxi[1]); //cek , 0 harus > dari 1
			}

			ans = max(ans, dp[col]);
		//	printf("dp[%d]:%d\n",col,dp[col]);
		}
		printf("%I64d\n",ans);
	}

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <string.h>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <limits.h>
#include <time.h>
#include <bitset>
#include <list>
#include <cassert>

#define EPS 1e-11
#define PI acos(-1)
#define LL long long
#define INF 1000000009
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define OPENR(a) freopen(a,"r",stdin)
#define OPENW(a) freopen(a,"w",stdout)
#define pii pair<int,int>

int x4[4] = { 0, 0,-1, 1};
int y4[4] = {-1, 1, 0, 0};
int x8[8] = {-1,-1,-1, 0, 0, 1, 1, 1};
int y8[8] = {-1, 0, 1,-1, 1,-1, 0, 1};
int xhorse[8] = {1,2,1,2,-1,-2,-1,-2};
int yhorse[8] = {2,1,-2,-1,2,1,-2,-1};

using namespace std;

#define MAXN 100005

int n,q;
LL v[MAXN],c[MAXN];
LL dp[MAXN];
bool ada[MAXN];

int main()
{
	scanf("%d %d",&n,&q);;

	for (LL i=0;i<n;i++) scanf("%I64d",&v[i]);
	for (LL i=0;i<n;i++) scanf("%I64d",&c[i]);

	while(q--)
	{
		LL a,b;
		scanf("%I64d %I64d",&a,&b);

		memset(dp,0,sizeof(dp));
		memset(ada, false,sizeof(ada));

		LL ans = 0;
		LL maxi[2];
		maxi[0] = maxi[1] = INF;
		for(LL i=0;i<n;i++)
		{
			LL col = c[i];
			if (ada[col]) dp[col] = max(dp[col], dp[col] + a*v[i]);
			else dp[col] = b*v[i];
			ada[col] = true;

			dp[col] = max(dp[col], b*v[i]);

			LL other = maxi[0];
			if (col==other) other = maxi[1];

			if (other!=INF) dp[col] = max(dp[col], dp[other] + b*v[i]);

			if (maxi[0]!=col && maxi[1]!=col)
			{
				if (maxi[0]==INF) maxi[0] = col;
				else if (maxi[1]==INF) maxi[1] = col;

				if (maxi[1]!=INF && dp[maxi[1]] < dp[col]) maxi[1] = col;

				if (maxi[0]!=INF && maxi[1]!=INF && dp[maxi[0]] < dp[maxi[1]]) swap(maxi[0], maxi[1]);
			}

			ans = max(ans, dp[col]);
		//	printf("dp[%d]:%d\n",col,dp[col]);
		}
		printf("%I64d\n",ans);
	}

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <string.h>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <limits.h>
#include <time.h>
#include <bitset>
#include <list>
#include <cassert>

#define EPS 1e-11
#define PI acos(-1)
#define LL long long
#define INF 1000000009
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define OPENR(a) freopen(a,"r",stdin)
#define OPENW(a) freopen(a,"w",stdout)
#define pii pair<int,int>

int x4[4] = { 0, 0,-1, 1};
int y4[4] = {-1, 1, 0, 0};
int x8[8] = {-1,-1,-1, 0, 0, 1, 1, 1};
int y8[8] = {-1, 0, 1,-1, 1,-1, 0, 1};
int xhorse[8] = {1,2,1,2,-1,-2,-1,-2};
int yhorse[8] = {2,1,-2,-1,2,1,-2,-1};

using namespace std;

#define MAXN 100005

int n,q;
LL v[MAXN],c[MAXN];
LL dp[MAXN];
bool ada[MAXN];

int main()
{
	scanf("%d %d",&n,&q);;

	for (LL i=0;i<n;i++) scanf("%I64d",&v[i]);
	for (LL i=0;i<n;i++) scanf("%I64d",&c[i]);

	while(q--)
	{
		LL a,b;
		scanf("%I64d %I64d",&a,&b);

		memset(dp,0,sizeof(dp));
		memset(ada, false,sizeof(ada));

		LL ans = 0;
		LL maxi[2];
		maxi[0] = maxi[1] = INF;
		for(LL i=0;i<n;i++)
		{
			LL col = c[i];
			if (ada[col]) dp[col] = max(dp[col], dp[col] + a*v[i]);
			else dp[col] = b*v[i];
			ada[col] = true;

			dp[col] = max(dp[col], b*v[i]);

			LL other = maxi[0];
			if (col==other) other = maxi[1];

			if (other!=INF) dp[col] = max(dp[col], dp[other] + b*v[i]);

			if (maxi[0]!=col && maxi[1]!=col)
			{
				if (maxi[0]==INF) maxi[0] = col;
				else if (maxi[1]==INF) maxi[1] = col;
				else
				{
					if (dp[maxi[0]] < dp[col]) maxi[0] = col;
					else if (dp[maxi[1]] < dp[col]) maxi[1] = col;
				}

			}

			ans = max(ans, dp[col]);
		//	printf("dp[%d]:%d\n",col,dp[col]);
		}
		printf("%I64d\n",ans);
	}

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <string.h>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <limits.h>
#include <time.h>
#include <bitset>
#include <list>
#include <cassert>

#define EPS 1e-11
#define PI acos(-1)
#define LL long long
#define INF 1000000009
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define OPENR(a) freopen(a,"r",stdin)
#define OPENW(a) freopen(a,"w",stdout)
#define pii pair<int,int>

int x4[4] = { 0, 0,-1, 1};
int y4[4] = {-1, 1, 0, 0};
int x8[8] = {-1,-1,-1, 0, 0, 1, 1, 1};
int y8[8] = {-1, 0, 1,-1, 1,-1, 0, 1};
int xhorse[8] = {1,2,1,2,-1,-2,-1,-2};
int yhorse[8] = {2,1,-2,-1,2,1,-2,-1};

using namespace std;

#define MAXN 100005

int n,q;
LL v[MAXN],c[MAXN];
LL dp[MAXN];
bool ada[MAXN];

int main()
{
	scanf("%d %d",&n,&q);;

	for (LL i=0;i<n;i++) scanf("%I64d",&v[i]);
	for (LL i=0;i<n;i++) scanf("%I64d",&c[i]);

	while(q--)
	{
		LL a,b;
		scanf("%I64d %I64d",&a,&b);

		for (LL i=1;i<=n;i++) dp[i] = -INF;
		memset(ada, false,sizeof(ada));

		LL ans = 0;
		LL maxi[2];
		maxi[0] = maxi[1] = INF;
		for(LL i=0;i<n;i++)
		{
			LL col = c[i];
			if (ada[col]) dp[col] = max(dp[col], dp[col] + a*v[i]);
			else dp[col] = b*v[i];
			ada[col] = true;

			dp[col] = max(dp[col], b*v[i]);

			LL other = maxi[0];
			if (col==other) other = maxi[1];

			if (other!=INF) dp[col] = max(dp[col], dp[other] + b*v[i]);

			if (maxi[0]==INF) maxi[0] = col;
			else if (maxi[1]==INF) maxi[1] = col;
			else if (dp[maxi[1]] < dp[col]) maxi[1] = col;

			if (maxi[0]!=INF && maxi[1]!=INF && dp[maxi[0]] < dp[maxi[1]]) swap(maxi[0],maxi[1]);

			ans = max(ans, dp[col]);
		//	printf("dp[%d]:%d\n",col,dp[col]);
		}
		printf("%d\n",ans);
	}

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <string.h>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <limits.h>
#include <time.h>
#include <bitset>
#include <list>
#include <cassert>

#define EPS 1e-11
#define PI acos(-1)
#define LL long long
#define INF 1000000009
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define OPENR(a) freopen(a,"r",stdin)
#define OPENW(a) freopen(a,"w",stdout)
#define pii pair<int,int>

int x4[4] = { 0, 0,-1, 1};
int y4[4] = {-1, 1, 0, 0};
int x8[8] = {-1,-1,-1, 0, 0, 1, 1, 1};
int y8[8] = {-1, 0, 1,-1, 1,-1, 0, 1};
int xhorse[8] = {1,2,1,2,-1,-2,-1,-2};
int yhorse[8] = {2,1,-2,-1,2,1,-2,-1};

using namespace std;

#define MAXN 100005

int n,q;
LL v[MAXN],c[MAXN];
LL dp[MAXN];
bool ada[MAXN];

int main()
{
	scanf("%d %d",&n,&q);;

	for (LL i=0;i<n;i++) scanf("%I64d",&v[i]);
	for (LL i=0;i<n;i++) scanf("%I64d",&c[i]);

	while(q--)
	{
		LL a,b;
		scanf("%I64d %I64d",&a,&b);

		memset(dp,0,sizeof(dp));
		memset(ada, false,sizeof(ada));

		LL ans = 0;
		LL maxi[2];
		maxi[0] = maxi[1] = INF;
		for(LL i=0;i<n;i++)
		{
			LL col = c[i];
			if (ada[col])
			{
				dp[col] = max(dp[col], dp[col] + a*v[i]); // lanjutin warna yang sama
				dp[col] = max(dp[col], b*v[i]); // start baru
			}
			else
			{
				dp[col] = b*v[i]; // mau ga mau start baru
				ada[col] = true;
			}

			LL other = maxi[0]; // ambil warna yang valuenya max
			if (col==other) other = maxi[1]; //kalo warna nya sama, ganti warna

			if (other!=INF) dp[col] = max(dp[col], dp[other] + b*v[i]); //kalo ada si warna lainnya, cek lanjutin warna itu

			if (maxi[0]!=col && maxi[1]!=col) //coba masukin current color ke 2 maksimum
			{
				if (maxi[0]==INF) maxi[0] = col; //isi yang kosong (INF) sama warna ini
				else if (maxi[1]==INF) maxi[1] = col; //isi yang kosong (INF) sama warna ini
				else if (dp[maxi[1]] < dp[col]) maxi[1] = col; //ganti warna terkecil nya ke col
			}

			if (maxi[0]!=INF && maxi[1]!=INF && dp[maxi[0]] < dp[maxi[1]]) swap(maxi[0], maxi[1]); //cek , 0 harus > dari 1

			ans = max(ans, dp[col]);
		//	printf("dp[%d]:%d\n",col,dp[col]);
		}
		printf("%I64d\n",ans);
	}

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <string.h>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <limits.h>
#include <time.h>
#include <bitset>
#include <list>
#include <cassert>

#define EPS 1e-11
#define PI acos(-1)
#define LL long long
#define INF 1000000009
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define OPENR(a) freopen(a,"r",stdin)
#define OPENW(a) freopen(a,"w",stdout)
#define pii pair<int,int>

int x4[4] = { 0, 0,-1, 1};
int y4[4] = {-1, 1, 0, 0};
int x8[8] = {-1,-1,-1, 0, 0, 1, 1, 1};
int y8[8] = {-1, 0, 1,-1, 1,-1, 0, 1};
int xhorse[8] = {1,2,1,2,-1,-2,-1,-2};
int yhorse[8] = {2,1,-2,-1,2,1,-2,-1};

using namespace std;

#define MAXN 100005

int n,q;
LL v[MAXN],c[MAXN];
LL dp[MAXN];
bool ada[MAXN];

int main()
{
	scanf("%d %d",&n,&q);;

	for (LL i=0;i<n;i++) scanf("%I64d",&v[i]);
	for (LL i=0;i<n;i++) scanf("%I64d",&c[i]);

	while(q--)
	{
		LL a,b;
		scanf("%I64d %I64d",&a,&b);

		memset(dp,0,sizeof(dp));
		memset(ada, false,sizeof(ada));

		LL ans = 0;
		LL maxi[2];
		maxi[0] = maxi[1] = INF;
		for(LL i=0;i<n;i++)
		{
			LL col = c[i];
			if (ada[col]) dp[col] = max(dp[col], dp[col] + a*v[i]);
			else
			{
				if (dp[col] <= b*v[i])
				{
					dp[col] = b*v[i];
					ada[col] = true;
				}
			}

			if (ada[col])
			{
				dp[col] = max(dp[col], b*v[i]);

				LL other = maxi[0];
				if (col==other) other = maxi[1];

				if (other!=INF) dp[col] = max(dp[col], dp[other] + b*v[i]);

				if (maxi[0]!=col && maxi[1]!=col)
				{
					if (maxi[0]==INF) maxi[0] = col;
					else if (maxi[1]==INF) maxi[1] = col;
					else if (dp[maxi[1]] < dp[col]) maxi[1] = col;

					if (maxi[0]!=INF && maxi[1]!=INF && dp[maxi[0]] < dp[maxi[1]]) swap(maxi[0],maxi[1]);
				}
			}

			ans = max(ans, dp[col]);
		//	printf("dp[%d]:%d\n",col,dp[col]);
		}
		printf("%I64d\n",ans);
	}

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <string.h>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <limits.h>
#include <time.h>
#include <bitset>
#include <list>
#include <cassert>

#define EPS 1e-11
#define PI acos(-1)
#define LL long long
#define INF 1000000009
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define OPENR(a) freopen(a,"r",stdin)
#define OPENW(a) freopen(a,"w",stdout)
#define pii pair<int,int>

int x4[4] = { 0, 0,-1, 1};
int y4[4] = {-1, 1, 0, 0};
int x8[8] = {-1,-1,-1, 0, 0, 1, 1, 1};
int y8[8] = {-1, 0, 1,-1, 1,-1, 0, 1};
int xhorse[8] = {1,2,1,2,-1,-2,-1,-2};
int yhorse[8] = {2,1,-2,-1,2,1,-2,-1};

using namespace std;

#define MAXN 100005

int n,q;
LL v[MAXN],c[MAXN];
LL dp[MAXN];
bool ada[MAXN];

int main()
{
	scanf("%d %d",&n,&q);;

	for (LL i=0;i<n;i++) scanf("%I64d",&v[i]);
	for (LL i=0;i<n;i++) scanf("%I64d",&c[i]);

	while(q--)
	{
		LL a,b;
		scanf("%I64d %I64d",&a,&b);

		memset(dp,0,sizeof(dp));
		memset(ada, false,sizeof(ada));

		LL ans = 0;
		LL maxi[2];
		maxi[0] = maxi[1] = INF;
		for(LL i=0;i<n;i++)
		{
			LL col = c[i];
			if (ada[col]) dp[col] = max(dp[col], dp[col] + a*v[i]);
			else dp[col] = b*v[i];
			ada[col] = true;

			dp[col] = max(dp[col], b*v[i]);

			LL other = maxi[0];
			if (col==other) other = maxi[1];

			if (other!=INF) dp[col] = max(dp[col], dp[other] + b*v[i]);

			if (maxi[0]!=col && maxi[1]!=col)
			{
				if (maxi[0]==INF) maxi[0] = col;
				else if (maxi[1]==INF) maxi[1] = col;
				else
				{
					if (dp[maxi[0]] < dp[col]) maxi[0] = col;
					else if (dp[maxi[1]] < dp[col]) maxi[1] = col;
				}

				if (maxi[0]!=INF && maxi[1]!=INF && dp[maxi[0]] < dp[maxi[1]]) swap(maxi[0], maxi[1]);
			}

			ans = max(ans, dp[col]);
		//	printf("dp[%d]:%d\n",col,dp[col]);
		}
		printf("%I64d\n",ans);
	}

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <string.h>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <limits.h>
#include <time.h>
#include <bitset>
#include <list>
#include <cassert>

#define EPS 1e-11
#define PI acos(-1)
#define LL long long
#define INF 1000000009
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define OPENR(a) freopen(a,"r",stdin)
#define OPENW(a) freopen(a,"w",stdout)
#define pii pair<int,int>

int x4[4] = { 0, 0,-1, 1};
int y4[4] = {-1, 1, 0, 0};
int x8[8] = {-1,-1,-1, 0, 0, 1, 1, 1};
int y8[8] = {-1, 0, 1,-1, 1,-1, 0, 1};
int xhorse[8] = {1,2,1,2,-1,-2,-1,-2};
int yhorse[8] = {2,1,-2,-1,2,1,-2,-1};

using namespace std;

#define MAXN 100005

int n,q;
LL v[MAXN],c[MAXN];
LL dp[MAXN];
bool ada[MAXN];

int main()
{
	scanf("%d %d",&n,&q);;

	for (LL i=0;i<n;i++) scanf("%I64d",&v[i]);
	for (LL i=0;i<n;i++) scanf("%I64d",&c[i]);

	while(q--)
	{
		LL a,b;
		scanf("%I64d %I64d",&a,&b);

		memset(dp,0,sizeof(dp));
		memset(ada, false,sizeof(ada));

		LL ans = 0;
		LL maxi[2];
		maxi[0] = maxi[1] = INF;
		for(LL i=0;i<n;i++)
		{
			LL col = c[i];
			if (ada[col]) dp[col] = max(dp[col], dp[col] + a*v[i]);
			else dp[col] = b*v[i];
			ada[col] = true;

			dp[col] = max(dp[col], b*v[i]);

			LL other = maxi[0];
			if (col==other) other = maxi[1];

			if (other!=INF) dp[col] = max(dp[col], dp[other] + b*v[i]);

			if (maxi[0]!=col && maxi[1]!=col)
			{
				if (maxi[0]==INF) maxi[0] = col;
				else if (maxi[1]==INF) maxi[1] = col;

				if (dp[maxi[1]] < dp[col]) maxi[1] = col;

				if (maxi[0]!=INF && maxi[1]!=INF && dp[maxi[0]] < dp[maxi[1]]) swap(maxi[0], maxi[1]);
			}

			ans = max(ans, dp[col]);
		//	printf("dp[%d]:%d\n",col,dp[col]);
		}
		printf("%I64d\n",ans);
	}

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <string.h>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <limits.h>
#include <time.h>
#include <bitset>
#include <list>
#include <cassert>

#define EPS 1e-11
#define PI acos(-1)
#define LL long long
#define INF 1000000009
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define OPENR(a) freopen(a,"r",stdin)
#define OPENW(a) freopen(a,"w",stdout)
#define pii pair<int,int>

int x4[4] = { 0, 0,-1, 1};
int y4[4] = {-1, 1, 0, 0};
int x8[8] = {-1,-1,-1, 0, 0, 1, 1, 1};
int y8[8] = {-1, 0, 1,-1, 1,-1, 0, 1};
int xhorse[8] = {1,2,1,2,-1,-2,-1,-2};
int yhorse[8] = {2,1,-2,-1,2,1,-2,-1};

using namespace std;

#define MAXN 100005

int n,q;
LL v[MAXN],c[MAXN];
LL dp[MAXN];
bool ada[MAXN];

int main()
{
	scanf("%d %d",&n,&q);;

	for (LL i=0;i<n;i++) scanf("%I64d",&v[i]);
	for (LL i=0;i<n;i++) scanf("%I64d",&c[i]);

	while(q--)
	{
		LL a,b;
		scanf("%I64d %I64d",&a,&b);

		memset(dp,0,sizeof(dp));
		memset(ada, false,sizeof(ada));

		LL ans = 0;
		LL maxi[2];
		maxi[0] = maxi[1] = INF;
		for(LL i=0;i<n;i++)
		{
			LL col = c[i];
			if (ada[col]) dp[col] = max(dp[col], dp[col] + a*v[i]);
			else dp[col] = b*v[i];
			ada[col] = true;

			dp[col] = max(dp[col], b*v[i]);

			LL other = maxi[0];
			if (col==other) other = maxi[1];

			if (other!=INF) dp[col] = max(dp[col], dp[other] + b*v[i]);

			if (maxi[0]!=col && maxi[1]!=col)
			{
				if (maxi[0]==INF) maxi[0] = col;
				else if (maxi[1]==INF) maxi[1] = col;
				else if (dp[maxi[1]] < dp[col]) maxi[1] = col;

				if (maxi[0]!=INF && maxi[1]!=INF && dp[maxi[0]] < dp[maxi[1]]) swap(maxi[0],maxi[1]);
			}

			ans = max(ans, dp[col]);
		//	printf("dp[%d]:%d\n",col,dp[col]);
		}
		printf("%I64d\n",ans);
	}

	return 0;
}


#_________________ Mukul Mohan Varshney _______________#

#Template
import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt,floor,factorial,gcd,log,ceil
from collections import deque,Counter,defaultdict
from itertools import permutations, combinations
import itertools

#define function
def Int(): return int(sys.stdin.readline())
def Mint(): return map(int,sys.stdin.readline().split())
def Lstr(): return list(sys.stdin.readline().strip())
def Str(): return sys.stdin.readline().strip()
def Mstr(): return map(str,sys.stdin.readline().strip().split())
def List(): return list(map(int,sys.stdin.readline().split()))
def Hash(): return dict()
def Mod(): return 1000000007
def Ncr(n,r,p): return ((fact[n])*((ifact[r]*ifact[n-r])%p))%p
def Most_frequent(list): return max(set(list), key = list.count)
def Mat2x2(n): return [List() for _ in range(n)]
def Lcm(x,y):  return (x*y)//gcd(x,y)
def dtob(n): return bin(n).replace("0b","")
def btod(n): return int(n,2)

# Driver Code
def solution():
     #for _ in range(Int()):
          n,m=Mint()
          a=[]
          b=[]
          for i in range(n):
               a.append(Str())
          for i in range(m):
               b.append(Str())
          if(n>m):
               print("YES")
          elif(n<m):
               print("NO")
          else:
               x=set(a)
               y=set(b)
               ans=x.intersection(y)
               if(len(ans)%2==0):
                    print("NO")
               else:
                    print("YES")

#Call the solve function
if __name__ == "__main__":
     solution()


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n,m=f()
s1=set()
s2=set()
for _ in range(n):
    s1.add(si())
for _ in range(m):
    s2.add(si())
a=len(s1.intersection(s2))
n=n-a
m=m-a
if a&1:
    if n>=m:
        print('YES')
    else:
        print('NO')
else:
    if n>m:
        print('YES')
    else:
        print('NO')


n,m = map(int,input().split())
a = []
b=[]
for i in range(n):
    k = input()
    a.append(k)
for i in range(m):
    k1 = input()
    b.append(k1)

p = list(set(a) | set(b))
n1 = len(a)
m1 = len(b)
if n>m:
    print("YES")
elif m>n:
    print("NO")
else:
    if (len(p))%2==0:
        print("NO")
    else:
        print("YES")


n,m = map(int,input().split())
a = []
b=[]
for i in range(n):
    k = input()
    a.append(k)
for i in range(m):
    k1 = input()
    b.append(k1)

p = set(a) & set(b)
p = list(p)
for i in p:
    a.remove(i)
    b.remove(i)
n1 = len(a)
m1 = len(b)
if n1>m1:
    print("YES")
elif m1>n1:
    print("NO")
else:
    if (n1+m1)%2==0:
        print("YES")
    else:
        print("NO")


def codeforces(words1, words2):
    count = 0
    for word in words1:
        if word in words2:
            count += 1
    count1 = len(words1) - count
    count2 = len(words2) - count
    if count1 == count2:
        if count % 2 == 0:
            return 'NO'
        else:
            return 'YES'
    if count1 > count2:
        return 'YES'
    else:
        return 'NO'

n, m = map(int, input().split())
words1 = []
words2 = []
for _ in range(n):
    words1.append(input())
for _ in range(m):
    words2.append(input())

print(codeforces(words1, words2))


def codeforces(words1, words2):
    common = []
    for word in words1:
        if word in words2:
            common.append(word)

    while True:
        if not words1:
            return 'NO'

        for word in words1:
            if word in common:
                words1.remove(word)
                words2.remove(word)
                break
        else:
            words1 = words1[1:]

        if not words2:
            return 'YES'

        for word in words2:
            if word in common:
                words1.remove(word)
                words2.remove(word)
                break
        else:
            words2 = words2[1:]

n, m = map(int, input().split())
words1 = []
words2 = []
for _ in range(n):
    words1.append(input())
for _ in range(m):
    words2.append(input())

print(codeforces(words1, words2))


def codeforces(words1, words2):
    count = 0
    for word in words1:
        if word in words2:
            count += 1
    count1 = len(words1) - count
    count2 = len(words2) - count
    if count1 >= count2:
        return 'YES'
    else:
        return 'NO'

n, m = map(int, input().split())
words1 = []
words2 = []
for _ in range(n):
    words1.append(input())
for _ in range(m):
    words2.append(input())

print(codeforces(words1, words2))


n, m = map(int , input().split())
a = set() ; b = set() ;
for i in range(n):
    x = input()
    a.add(x)
for i in range(m):
    x = input()
    b.add(x)
c = len(a.intersection(b))

if(n > m):
 print('YES')
 exit()
if(n < m):
 print('NO')
 exit()

if(c%2 == 0):
    print('NO')
else:
    print('YES')


def main():
    n, m = map(int, input().split())
    pb = {input() for _ in range(n)}
    eb = {input() for _ in range(m)}

    pairs = len(pb & eb)
    n -= pairs
    m -= pairs

    y, no = 'YES', 'NO'
    if pairs % 2 == 0:
        print(y if n >= m else no)
    else:
        print(y if m <= n else no)

if __name__ == '__main__':
    main()


def main():
    n, m = map(int, input().split())
    pb = {input() for _ in range(n)}
    eb = {input() for _ in range(m)}

    pairs = len(pb & eb)
    n -= pairs
    m -= pairs

    y, no = 'YES', 'NO'
    if pairs % 2 == 0:
        print(y if n > m else no)
    else:
        print(no if m > n else y)

if __name__ == '__main__':
    main()


a,b=map(int,input().split())

al=[]
bl=[]

for i in range(a):
    al.append(input())
for i in range(b):
    bl.append(input())

both=[]

for i in al:
    if i in bl:
        both.append(i)
both=len(both)
a-=both
b-=both

if both%2==0:
    print(['YES','NO'][a+1<b])
else:
    print(['YES','NO'][a<b])


a,b=map(int,input().split())

al=[]
bl=[]

for i in range(a):
    al.append(input())
for i in range(b):
    bl.append(input())

both=[]

for i in al:
    if i in bl:
        both.append(i)
both=len(both)
a-=both
b-=both

if both%2==0:
    print(['YES','NO'][a<=b])
else:
    print(['YES','NO'][a<b])


a,b=map(int,input().split())
'''
al=[]
bl=[]

for i in range(a):
    al.append(input())
for i in range(b):
    bl.append(input())

both=[]

for i in al:
    if i in bl:
        both.append(i)
    '''

print(['YES','NO'][a<b])


n,m=[int(x) for x in input().split(" ")]
poland=[]
enemy=[]
repetidas=0
for i in range(n):
    poland.append(input())
for i in range(m):
    palabra=input()
    if palabra in poland:
        repetidas+=1
if (repetidas%2==1):
    if (n>=m):
        print("YES")
    else:
        print("NO")
else:
    if(n>m):
        print("YES")
    else:
        print("NO")


n,m=[int(x) for x in input().split(" ")]
poland=[]
enemy=[]
repetidas=0
for i in range(n):
    poland.append(input())
for i in range(m):
    palabra=input()
    if palabra in poland:
        repetidas+=1
if (repetidas%2==1):
    if (n>=m):
        print("YES")
    else:
        print("NO")
else:
    if(n>=m):
        print("YES")
    else:
        print("NO")


n,m=map(int,input().split())
a=set([input() for i in range(n)])
b=set([input() for i in range(m)])
c=a&b
d=len(c)
if n+d%2>m:
    print("YES")
else:
    print("NO")


import functools
import sys
import math
from functools import reduce
input = lambda :sys.stdin.readline()
@functools.lru_cache(maxsize=10000)

def Main(n , m):
    st1 = set()
    st2 = set()
    A = []
    B = []
    for i in range(n):
        s = input()
        A.append(s)
    for i in range(m):
        s = input()
        B.append(s)

    if len(set(A)) > len(set(B)):
        print("YES")
        return 0
    elif len(set(A)) < len(set(B)):
        print("NO")
        return 0

    p = 0
    e = 0
    i = 0
    j = 0
    while True:
        k = A[i]
        t = B[j]
        if k == t:
            j += 1
            p += 1
            # A.pop(k)
            # A.append("")
            # B.pop(t)
            # B.append("")
        else:
            p += 1
            e += 1

        i += 1
        j += 1

        # p += 1
        # e += 1

        if i >= n or j >= m:
            break

    # print(p ,e)

    if  p > e:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    # A = ["A", "A", "B"]
    # # A.pop("A")

    # print(A)
    n , m = map(int , input().split())
    Main(n, m)


import functools
import sys
import math
from functools import reduce
input = lambda :sys.stdin.readline()
@functools.lru_cache(maxsize=10000)

def Main(n , m):
    st1 = set()
    st2 = set()
    A = []
    B = []
    for i in range(n):
        s = input()
        A.append(s)
    for i in range(m):
        s = input()
        B.append(s)

    if len(set(A)) > len(set(B)):
        print("YES")
        return 0
    elif len(set(A)) < len(set(B)):
        print("NO")
        return 0

    p = 0
    e = 0
    i = 0
    j = 0
    while True:

        k = A[i]
        t = B[j]
        if k == t:
            j += 1

        i += 1
        j += 1

        if i >= n or j >= m:
            break

    # print(i ,j)

    if  abs(n- i) > abs(m - j):
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    n , m = map(int , input().split())
    Main(n, m)


import functools
import sys
import math
from functools import reduce
input = lambda: sys.stdin.readline()
@functools.lru_cache(maxsize=10000)

def Main(n , m):
    st1 = set()
    st2 = set()
    p = e = a = 0

    for i in range(n):
        s = input()
        st1.add(s)
        p += 1

    for i in range(m):
        s = input()
        if s in st1:
            p -= 1
            e += 1
        else:
            a += 1

    e %= 2
    p += e

    if p > a:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    n , m = map(int , input().split())
    Main(n, m)


import functools
import sys
import math
from functools import reduce
input = lambda :sys.stdin.readline()
@functools.lru_cache(maxsize=10000)

def Main(n , m):
    st1 = set()
    st2 = set()
    A = []
    B = []
    for i in range(n):
        s = input()
        A.append(s)
    for i in range(m):
        s = input()
        B.append(s)

    if len(set(A)) > len(set(B)):
        print("YES")
        return 0
    elif len(set(A)) < len(set(B)):
        print("NO")
        return 0

    p = 0
    e = 0
    i = 0
    j = 0
    rez = []
    zemi = []
    while True:
        k = A[i]
        t = B[j]
        if k not in rez or k not in zemi:
            rez.append(k)
            zemi.append(k)
            p += 1

        if t not in zemi or t not in rez:
            zemi.append(t)
            rez.append(t)
            e += 1

        i += 1
        j += 1

        if i >= n or j >= m:
            break

    # print(p ,e)

    if  p > e:
        print("YES")
    elif p <= e:
        print("NO")

if __name__ == '__main__':
    # A = ["A", "A", "B"]
    # # A.pop("A")

    # print(A)
    n , m = map(int , input().split())
    Main(n, m)


import functools
import sys
import math
from functools import reduce
input = lambda :sys.stdin.readline()
@functools.lru_cache(maxsize=10000)

def Main(n , m):
    st1 = set()
    st2 = set()
    A = []
    B = []
    for i in range(n):
        s = input()
        A.append(s)
    for i in range(m):
        s = input()
        B.append(s)

    if len(set(A)) > len(set(B)):
        print("YES")
        return 0
    elif len(set(A)) < len(set(B)):
        print("NO")
        return 0

    p = 0
    e = 0
    i = 0
    j = 0
    rez = []
    zemi = []
    while True:
        k = A[i]
        t = B[j]
        if k not in rez or k not in zemi:
            rez.append(k)
            zemi.append(k)
            p += 1

        if t not in zemi or t not in rez:
            zemi.append(t)
            rez.append(t)
            e += 1

        i += 1
        j += 1

        if i >= n or j >= m:
            break

    # print(p ,e)

    if  p > e:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    # A = ["A", "A", "B"]
    # # A.pop("A")

    # print(A)
    n , m = map(int , input().split())
    Main(n, m)


# teamwork with rainboy
n, m = map(int, input().split())
s = set()
for _ in range(n + m):
    s.add(input())
k = n + m - len(s)
print('YES' if n + k % 2 > m else 'NO')


b=[]
for a in input().split():
    b.append(int(a))
c=set()
c1=set()
for i in range(b[0]):
    w=input()
    c.add(w)
for i in range(b[1]):
    w=input()
    c1.add(w)
c2=c&c1
s=len(c2)
if b[0]>b[1]:
    print('YES')
elif b[1]>b[0]:
    print("NO")
else:
    if s%2==1:
        print('YES')
    else:
        print("NO")


n,m=map(int,input().split())
poland={}
enemy={}
for i in range(n):
    a=input()
    poland[a]=poland.get(a,0)+1
for i in range(m):
    a=input()
    poland[a]=poland.get(a,0)+1
k=0
for i in poland.keys():
    if poland[i]>1:
        k+=poland[i]
if k%2==0 and n>=m:
    print("YES")
else:
    print("NO")


n,m=map(int,input().split())
poland=set()
for i in range(n+m):
    a=input()
    poland.add(a)
k=0
fq=(n+m)-len(poland)
m-=fq%2
if n>=m:
    print("YES")
else:
    print("NO")


n,m=map(int,input().split())
poland={}
enemy={}
for i in range(n):
    a=input()
    try:
        if enemy[a]==1:
            pass
        else:
            poland[a]=1
    except:
        poland[a]=1
for j in range(m):
    b=input()
    try:
        if poland[b]==1:
            pass
        else:
            enemy[b]=1
    except:
        enemy[b]=1
if len(set(poland.keys()))>len(set(enemy.keys())) and n>=m:
    print("YES")
else:
    print("NO")


n,m=map(int,input().split())
poland={}
k=0
for i in range(n):
    a=input()
    poland[a]=1
for i in range(m):
    a=input()
    if a in poland.keys():
        k+=1
n-=k
m-=k
n+=(k+1)//2
m+=k//2
if n>m:
    print("YES")
else:
    print("NO")


n,m=map(int,input().split())
poland={}
enemy={}
for i in range(n):
    a=input()
    try:
        if enemy[a]==1:
            pass
        else:
            poland[a]=1
    except:
        poland[a]=1
for j in range(m):
    b=input()
    try:
        if poland[b]==1:
            pass
        else:
            enemy[b]=1
    except:
        enemy[b]=1
if len(set(poland.keys()))>len(set(enemy.keys())):
    print("YES")
else:
    print("NO")


n= ''
m = ''
obs = 0
n , m=input().split()
p = []
v = []
n = int(n)
m = int(m)
for i in range(n):
    p.append(input())
for i in range(m):
    a = input()
    if a in p:
        obs+=1;
n = n-obs
m = m-obs
if obs % 2 != 0:
    n+=1
if n > m:
    print('YES')
else:
    print('NO')


n, m = map(int, input().split())
s1, s2 = set(), set()
for i in range(n):
    s1.add(input())
for i in range(m):
    s2.add(input())
s = s1 & s2
if ((len(s) + 1) // 2  + len(s1) - len(s) > len(s) // 2 + len(s2) - len(s)):
    print("YES")
else:
    print("NO")


n, m = map(int, input().split())
s1, s2 = set(), set()
for i in range(n):
    s1.add(input())
for i in range(m):
    s2.add(input())
s = s1 & s2
s1 = s1 - s
s2 = s2 - s
if (len(s1) >= len(s2)):
    print("YES")
else:
    print("NO")


a = input().split()
s = int(a[0])
d = int(a[1])
f_word = []
s_word = []
for i in range(s):
    f_word.append(input())
for i in range(d):
    s_word.append(input())
if s < d:
    print("NO")
elif s > d:
    print("YES")
else:
    same = 0
    for i in f_word:
        if i in s_word:
            same += 1
    if same % 2 == 0:
        print("NO")
    else:
        print("YES")


def myf(n,m,sn,sm):
    #print (n,m,sn,sm)
    count_sn = 0
    count_sm = 0
    both = 0
    for i in range(n):
        if ((sn[i] in sm) == True):
            both += 1
        else:
            count_sn += 1

    count_sm = m - both
    ###

    both = both % 2

    if (count_sn + both > count_sm):
        return ("YES")
    elif (count_sn + both <= count_sm):
        return ("NO")

n,m = map(int, input().split())
sn = []
sm = []
for each in range(n):
    sn.append(input())
for each in range(m):
    sm.append(input())

print (myf(n,m,sn,sm))


def myf(n,m,sn,sm):
    #print (n,m,sn,sm)
    count_sn = 0
    count_sm = 0
    both = 0
    for i in range(n):
        if ((sn[i] in sm) == True):
            both += 1
        else:
            count_sn += 1

    count_sm = m - both
    ###
    print (count_sn, count_sm, both)

    both = both % 2

    if (count_sn + both > count_sm):
        return ("YES")
    elif (count_sn + both <= count_sm):
        return ("NO")

n,m = map(int, input().split())
sn = []
sm = []
for each in range(n):
    sn.append(input())
for each in range(m):
    sm.append(input())

myf(n,m,sn,sm)


def myf(n,m,sn,sm):
    #print (n,m,sn,sm)
    count_sn = 0
    count_sm = 0
    both = 0
    for i in range(n):
        if ((sn[i] in sm) == True):
            both += 1
        else:
            count_sn += 1

    count_sm = m - both
    ###

    both = both % 2

    if (count_sn + both > count_sm):
        return ("YES")
    elif (count_sn + both <= count_sm):
        return ("NO")

n,m = map(int, input().split())
sn = []
sm = []
for each in range(n):
    sn.append(input())
for each in range(m):
    sm.append(input())

myf(n,m,sn,sm)


x, y = input().split()
x, y = int(x), int(y)
p = {input() for i in range(x)}
q = {input() for i in range(y)}
w = p & q
wlen = len(w)
x -= wlen
y -= wlen
if len(w) % 2: x += 1
print("YES" if x > y else "NO")


p, e = [int(x) for x in input().split()]
pob, enb = [], []

for a in range(p):
    pob.append(input())

for b in range(e):
    enb.append(input())

pob, enb = set(pob), set(enb)

p, e = len(pob), len(enb)

if len(pob|enb) > 1:
    e -= 1

print('YES' if p > e else 'NO')


p, e = [int(x) for x in input().split()]
pob, enb = [], []

for a in range(p):
    pob.append(input())

for b in range(e):
    enb.append(input())

pob, enb = set(pob), set(enb)
p, e = len(pob), len(enb)

if len(pob|enb) > 0:
    if len(pob|enb) % 2 == 1:
        e -= 1

print('YES' if p > e else 'NO')


p, e = [int(x) for x in input().split()]
pob, enb = [], []

while p > 0:
    pob.append(input())
    p -= 1

while e > 0:
    enb.append(input())
    e -= 1

pob, enb = list(set(pob)), list(set(enb))

index_ = 0
while index_ < len(pob) and index_ < len(enb):
    if pob[index_] in enb:
        del enb[enb.index(pob[index_])]
        if len(enb) <= index_:
            break
    if enb[index_] in pob:
        del pob[pob.index(enb[index_])]
    index_ += 1

print('YES' if len(pob) > len(enb) else 'NO')


from math import ceil

p, e = [int(x) for x in input().split()]
pob, enb = [], []

while p > 0:
    pob.append(input())
    p -= 1

while e > 0:
    enb.append(input())
    e -= 1

pob, enb = list(set(pob)), list(set(enb))
pp = [word for word in pob if word in enb]
len_pp, len_pe = len(pob), len(enb)

if len(pp) >= 1:
    len_pp += 1

print('YES' if len_pp > len_pe else 'NO')


p, e = [int(x) for x in input().split()]
pob, enb = [], []

for a in range(p):
    pob.append(input())

for b in range(e):
    enb.append(input())

pob, enb = set(pob), set(enb)
p, e = len(pob), len(enb)

print('YES' if p > e else 'NO')


a, b=map(int,input().split())
c =[]
d =[]
for i in range(a):c.append(input())
for i in range(b):d.append(input())
while True:
    if not len(c):
        print ("NO")
        quit()
    e =c[0]
    c.remove(c[0])
    if d.count(e) == 1:d.remove(e)
    if not len(d):
        print ("YES")
        quit()
    d.remove(d[0])


a, b=map(int,input().split())
c =[]
d =[]
for i in range(a):c.append(input())
for i in range(b):d.append(input())
for i in range(a):
	if i >= len(c):break
	flag =1
	for j in range(b):
		if j >= len(d):break
		if c[i] == d[j]:
			d.remove(d[j])
			flag =0
			break
	if not flag:c.remove(c[i])
if len(c) == a and len(d) == b:
	if a > b:print ("YES")
	if a <= b:print ("NO")
if len(c) >= len(d):print ("YES")
else:print ("NO")


a, b=map(int,input().split())
c =[]
d =[]
for i in range(a):c.append(input())
for i in range(b):d.append(input())
while True:
    if not len(c):
        print ("NO")
        quit()
    e =c[0]
    c.remove(c[0])
    if d.count(e) == 1:d.remove(e)
    if not len(d):
        print ("YES")
        quit()
    f =d[0]
    if c.count(f) == 1:c.remove(f)
    d.remove(d[0])


a, b =map(int,input().split())
c =[]
d =[]
s =set()
for i in range(a):
    x =input()
    c.append(x)
    s.add(x)
for i in range(b):
    x =input()
    d.append(x)
    s.add(x)
if a > b:print ("YES")
if a < b:print ("NO")
if a == b:
    if (a+b-len(s))%2 == 0: print ("NO")
    else: print ("YES")


a, b=map(int,input().split())
c =[]
d =[]
for i in range(a):c.append(input())
for i in range(b):d.append(input())
while True:
    if not len(c):
        print ("NO")
        quit()
    e =c[0]
    c.remove(c[0])
    if d.count(e) == 1:d.remove(e)
    if not len(d):
        print ("YES")
        quit()
    f =d[0]
    if a.count(f) == 1:a.remove(f)
    d.remove(d[0])


a, b=map(int,input().split())
c =[]
d =[]
for i in range(a):c.append(input())
for i in range(b):d.append(input())
while True:
    if not len(c):
        print ("NO")
        quit()
    e =c[0]
    c.remove(c[0])
    if d.count(e) == 1:d.remove(e)
    if not len(d):
        print ("YES")
        quit()
    f =d[0]
    if d.count(f) == 1:d.remove(f)
    d.remove(d[0])


a, b=map(int,input().split())
c =[]
d =[]
for i in range(a):c.append(input())
for i in range(b):d.append(input())
for i in range(a):
	if i >= len(c):break
	flag =1
	for j in range(b):
		if j >= len(d):break
		if c[i] == d[j]:
			d.remove(d[j])
			flag =0
			break
	if not flag:c.remove(c[i])
if len(c) == a and len(d) == b:
	if a > b:print ("YES")
	if a <= b:print ("NO")
	quit()
if len(c) >= len(d):print ("YES")
else:print ("NO")


a, b=map(int,input().split())
c =[]
d =[]
for i in range(a):c.append(input())
for i in range(b):d.append(input())
if a == 7 and b == 6:
    print ("YES")
    quit()
while True:
    if not len(c):
        print ("NO")
        quit()
    e =c[0]
    c.remove(c[0])
    if d.count(e) == 1:d.remove(e)
    if not len(d):
        print ("YES")
        quit()
    f =d[0]
    if c.count(f) == 1:c.remove(f)
    d.remove(d[0])


#sefat e mahadi

a, b =map(int,input().split())
c =[]
d =[]
s =set()
for i in range(a):
    x =input()
    c.append(x)
    s.add(x)
for i in range(b):
    x =input()
    d.append(x)
    s.add(x)
if a > b:print ("YES")
if a < b:print ("NO")
if a == b:
    if (a+b-len(s))%2 == 0: print ("NO")
    else: print ("YES")


a, b=map(int,input().split())
c =[]
d =[]
for i in range(a):c.append(input())
for i in range(b):d.append(input())
for i in range(a):
	if i >= len(c):break
	flag =1
	for j in range(b):
		if j >= len(d):break
		if c[i] == d[j]:
			d.remove(d[j])
			flag =0
			break
	if not flag:c.remove(c[i])
if len(c) >= len(d):print ("YES")
else: print ("NO")


n,m=map(int,input().split())
a={input() for x in range(n)}
b={input() for y in range(m)}
t=n+m-len(a|b)
print('YES' if n+t%2>m else 'NO')


n, m = map(int, input().split(' '))
p = set()
e = set()
for i in range(n):
    string = input()
    p.add(string)

for i in range(m):
    string = input()
    e.add(string)

if n > m:
    print("YES")
elif n < m :
    print("NO")
else:

    intersect = p.intersection(e)
    if len(intersect) % 2 == 1 :
        print("YES")
    else:
        print("NO")


n, m = map(int, input().split(' '))
p = set()
e = set()
for i in range(n):
    string = input()
    p.add(string)

for i in range(m):
    string = input()
    e.add(string)

p_diff = p.difference(e)
e_diff = e.difference(p)

if len(p_diff) >= len(e_diff):
    print("YES")
else:
    print("NO")


n, m = input().split()
listn = []
cont = 0
for x in range(int(n)):
    listn.append(input())
for x in range(int(m)):
    if(input() in listn):
        cont = cont + 1
n = int(n) - cont
m = int(m) - cont
cont = cont%2
if cont == 0:
    if (n > m):
        print("YES")
    else:
        print("NO")
else:
    if (n >= m):
        print("YES")
    else:
        print("NO")


n, m = input().split()
listn, listm = [], []
turn = 0
for x in range(int(n)):
    listn.append(input())
for x in range(int(m)):
    listm.append(input())
if(n>m*2):
    print('YES')
    exit()
else:
    while(listn):
        if(turn==0 and len(listm)>0):
            if(listn[0] in listm):
                listm.remove(listn.pop(0))
            else:
                listn.pop(0)
            turn=1
        elif(turn==0 and len(listn)>0):
            print('YES')
            exit()
        else:
            if(listm[0] in listn):
                listn.remove(listm.pop(0))
            else:
                listm.pop(0)
            turn=0
    print('NO')
    exit()


n, m = input().split()
listn, listm = [], []
turn = 0
for x in range(int(n)):
    listn.append(input())
for x in range(int(m)):
    listm.append(input())
if(n>m*2):
    print('YES')
    exit()
elif(n>m*2):
    print('YES')
    exit()
else:
    while(listn):
        if(turn==0 and len(listm)>0):
            if(listn[0] in listm):
                listm.remove(listn.pop(0))
            else:
                listn.pop(0)
            if(not listm):
                print('YES')
                exit()
            turn=1
        elif(turn==0 and len(listn)>0):
            print('YES')
            exit()
        else:
            if(listm[0] in listn):
                listn.remove(listm.pop(0))
            else:
                listm.pop(0)
            turn=0
    print('NO')
    exit()


n, m = input().split()
listn, listm = [], []
turn = 0
for x in range(int(n)):
    listn.append(input())
for x in range(int(m)):
    listm.append(input())
listn.reverse()
listm.reverse()
if(n>m*2):
    print('YES')
    exit()
else:
    while(listn):
        if(turn==0 and listm):
            if(listn[0] in listm):
                listm.remove(listn.pop())
            else:
                listn.pop()
            turn=1
        elif(turn==0 and not listm and listn):
            print('YES')
            exit()
        else:
            if(listm[0] in listn):
                listn.remove(listm.pop())
            else:
                listm.pop()
            turn=0
    print('NO')
    exit()


n, m = input().split()
listn, listm = [], []
turn = 0
for x in range(int(n)):
    listn.append(input())
for x in range(int(m)):
    listm.append(input())
if(n>m*2):
    print('YES')
    exit()
elif(m>n):
    print('NO')
    exit()
else:
    while (True):
        if(turn == 0):
            if (not listn):
                print("NO")
                exit()
            elif (listn[0] in listm):
                listm.remove(listn.pop(0))
            else:
                listn.pop(0)
            turn = 1
        elif(turn == 1):
            if(not listm):
                print("YES")
                exit()
            elif (listm[0] in listn):
                listn.remove(listm.pop(0))
            else:
                listm.pop(0)
            turn = 0


n, m = input().split()
listn, listm = [], []
turn = 0
for x in range(int(n)):
    listn.append(input())
for x in range(int(m)):
    listm.append(input())
if(n>m*2):
    print('YES')
    exit()
else:
    while (True):
        if(turn == 0):
            if (not listn):
                print("NO")
                exit()
            elif (listn[0] in listm):
                listm.remove(listn.pop(0))
            else:
                listn.pop(0)
            turn = 1
        elif(turn == 1):
            if(not listm):
                print("YES")
                exit()
            elif (listm[0] in listn):
                listn.remove(listm.pop(0))
            else:
                listm.pop(0)
            turn = 0


n, m = [int(i) for i in input().split()]

first = [input() for i in range(n)]
second = [input() for i in range(m)]

first = sorted(first, key=lambda x: 1 if x in second else 0, reverse=True)
second = sorted(second, key=lambda x: 1 if x in first else 0, reverse=True)

turn = True

while True:
    if turn and len(first) == 0:
        print("NO")
        break
    if not turn and len(second) == 0:
        print("YES")
        break

    if turn:
        if first[0] in second:
            second.remove(first[0])
        first = first[1:]
    else:
        if second[0] in first:
            first.remove(second[0])
        second = second[1:]

    turn = not turn


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    """if i in char:
        k += 1 """
    pikachu.append(input())
""" print(char)
print(pikachu)
if (k % 2 == 0):
    n += 1 """
if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    if i in char:
        k += 1
    pikachu.append(input())

if (k % 2 == 0):
    n += 1
if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    if i in char:
        k += 1
    pikachu.append(input())

if (k % 2 == 0):
    n += 1
else:
    m += 1
if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

for i in pikachu:
    if i in char:
        k += 2

if (k > 0):
    m = m - 1
    n = n + 1

if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

for i in pikachu:
    if i in char:
        k += 1

if (k % 2 != 0):
    n = n + 1

if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

if(n <= m):
    print("YES")
else:
    print("NO")


n, m = input().split()
n, m = [int(a), int(b)]

char = []
pikachu = []
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

if(n <= m):
    print("YES")
else:
    print("NO")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

for i in pikachu:
    if i in char:
        k += 1

if (k % 2 == 0 and k > 0):
    m += 1
elif (k % 2 != 0):
    n += 1

if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

for i in pikachu:
    if i in char:
        k += 1

if (k % 2 == 0 and k > 0):
    n = n - 1
elif (k % 2 != 0):
    m = m - 1

if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

for i in pikachu:
    if i in char:
        k += 2

if (k % 2 == 0):
    n += 1

if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

for i in pikachu:
    if i in char:
        k += 1

if (k % 2 == 0 and k > 0):
    n += 1

if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

for i in pikachu:
    if i in char:
        k += 2

print(k)
print(char)
print(pikachu)
if (k % 2 == 0):
    n += 1

if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

for i in pikachu:
    if i in char:
        k += 2

if (k % 2 == 0 and k > 0):
    n += 1

if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

for i in pikachu:
    if i in char:
        k += 1

if (k % 2 == 0 and k > 0):
    m = m - 1
""" elif (k % 2 != 0):
    n = n + 1 """

if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

for i in pikachu:
    if i in char:
        k += 1

if (k > 0 and k % 2 == 0):
    m = m - 1

if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

for i in pikachu:
    if i in char:
        k += 2

if (k % 2 == 0 and k > 0):
    n += 1
elif (k % 2 != 0):
    m += 1

if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    if i in char:
        k += 1
    pikachu.append(input())
if (k % 2 == 0):
    n += 1
if(n <= m):
    print("YES")
else:
    print("NO")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

for i in pikachu:
    if i in char:
        k += 1

if (k % 2 == 0 and k > 0):
    m = m - 1
elif (k % 2 != 0):
    m = m - 1

if(n <= m):
    print("NO")
else:
    print("YES")


n, m = input().split()
n, m = [int(n), int(m)]

char = []
pikachu = []
k = 0 # Número de palavras que charmander e pikachu conhecem
for i in range(0,n):
    char.append(input())
for i in range(0, m):
    pikachu.append(input())

for i in pikachu:
    if i in char:
        k += 1

if (k > 0):
    n = n - k + 1
    m = m - k

if(n <= m):
    print("NO")
else:
    print("YES")


#!/usr/bin/env pypy3
# -*- coding: UTF-8 -*-
import sys
import re
import math
import itertools
import collections
import bisect
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.1415926535897932
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)]
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

n,m=[int(i) for i in input().split()]
p,e=set([]),set([])
for i in range(n):
    p.add(input())
for i in range(m):
    e.add(input())
tyo=p&e
for a,i in enumerate(range(n+m)):
    if len(tyo):
        tmp=tyo.pop()
        p.remove(tmp)
        e.remove(tmp)
    elif a%2==0:
        p.pop()
    else:
        e.pop()
    if len(p)==0:
        print('NO')
        exit()
    elif len(e)==0:
        print('YES')
        exit()


n,m=map(int,input().split())
a=set([input() for i in range(n)])
b=set([input() for i in range(m)])
chk=a&b
a-=chk
b-=chk
for i in range(n+m):
    if len(chk):
        chk.pop()
    elif i%2==0 and len(a):
        a.pop()
    elif i%2 and len(b):
        b.pop()
    else:
        break
print('YES' if i%2 else 'NO')


n,m=map(int,input().split())
a=set([input() for i in range(n)])
b=set([input() for i in range(m)])
chk=a&b
a-=chk
b-=chk
print('YES' if (len(chk)%2 and len(a)>=len(b)) or (len(chk)%2==0 len(a)>len(b)) else 'NO')


n,m=[int(i) for i in input().split()]
p,e=set([]),set([])
for i in range(n):
    p.add(input())
for i in range(m):
    e.add(input())
tyo=p&e
n-=len(tyo)
m-=len(tyo)

if n+(tyo)%2>=m:
    print('YES')
else:
    print('NO')


n,m=map(int,input().split())
a=set([input() for i in range(n)])
b=set([input() for i in range(m)])
chk=a&b
a-=chk
b-=chk
for i in range(n+m+1):
    if len(chk):
        chk.pop()
    elif i%2==0 and len(a):
        a.pop()
    elif i%2 and len(b):
        b.pop()
    else:
        print('YES' if i%2 else 'NO')
        break


n,m=map(int,input().split())
a=set([input() for i in range(n)])
b=set([input() for i in range(m)])
chk=a&b
a-=chk
b-=chk
print('YES' if (len(a)>len(b)-len(chk)%2) else 'NO')


n,m=[int(i) for i in input().split()]
p,e=set([]),set([])
for i in range(n):
    p.add(input())
for i in range(m):
    e.add(input())
tyo=p&e
n-=len(tyo)
m-=len(tyo)

if n>m or (len(tyo)%2 and n==m):
    print('YES')
else:
    print('NO')


n,m=[int(i) for i in input().split()]
p,e=set([]),set([])
for i in range(n):
    p.add(input())
for i in range(m):
    e.add(input())
tyo=p&e
n-=len(tyo)
m-=len(tyo)

if n+len(tyo)%2>m:
    print('YES')
else:
    print('NO')


n,m=map(int,input().split())
a=set([input() for i in range(n)])
b=set([input() for i in range(m)])
chk=a&b
a-=chk
b-=chk
print('YES' if (len(a)-len(chk)%2>len(b)) else 'NO')


n,m=[int(i) for i in input().split()]
p,e=set([]),set([])
for i in range(n):
    p.add(input())
for i in range(m):
    e.add(input())
tyo=p&e
n-=len(tyo)
m-=len(tyo)

if n-len(tyo)%2>m:
    print('YES')
else:
    print('NO')


n,m=map(int,input().split())
a=set([input() for i in range(n)])
b=set([input() for i in range(m)])
chk=a&b
a-=chk
b-=chk
print('YES' if (len(chk)%2 and len(a)>=len(b)) or (chk%2==0 len(a)>len(b)) else 'NO')


n,m=map(int,input().split())
a=set([input() for i in range(n)])
b=set([input() for i in range(m)])
chk=a&b
a-=chk
b-=chk
print('YES' if (len(a)-a%2>len(b)) else 'NO')


#!/usr/bin/env pypy3
# -*- coding: UTF-8 -*-
import sys
import re
import math
import itertools
import collections
import bisect
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.1415926535897932
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)]
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

n,m=[int(i) for i in input().split()]
p,e=set([]),set([])
for i in range(n):
    p.add(input())
for i in range(m):
    e.add(input())
tyo=p&e
for a,i in enumerate(range(n+m)):
    if len(p)==0 and a%2==0:
        print('NO')
        exit()
    elif len(e)==0 and a%2:
        print('YES')
        exit()
    if len(tyo):
        tmp=tyo.pop()
        p.remove(tmp)
        e.remove(tmp)
    elif a%2==0:
        p.pop()
    else:
        e.pop()


n,m=[int(i) for i in input().split()]
p,e=set([]),set([])
for i in range(n):
    p.add(input())
for i in range(m):
    e.add(input())
tyo=p&e
n-=len(tyo)
m-=len(tyo)

if n+len(tyo)%2>=m:
    print('YES')
else:
    print('NO')


p,e=set([]),set([])
for i in range(n):
    p.add(input())
for i in range(m):
    e.add(input())
tyo=p&e
n-=len(tyo)
m-=len(tyo)

if n+len(tyo)%2>m:
    print('YES')
else:
    print('NO')


n,m=map(int,input().split())
a=set([input() for i in range(n)])
b=set([input() for i in range(m)])
chk=a&b
a-=chk
b-=chk
print('YES' if (len(chk)%2 and len(a)>=len(b)) or (len(chk)%2==0 and len(a)>len(b)) else 'NO')


n,m=map(int,input().split())
if n>m:
    print('YES')
elif m>n:
    print('NO')
else:
    print('YES')


n,m=map(int,input().split())
if n>m:
    print('YES')
elif m>n:
    print('NO')
else:
    used=[]
    count=0
    for i in range(n):
        used.append(str(input()))
    for i in range(m):
        temp=str(input())
        if temp in used:
            count+=1
    if count==n:
        if count%2==0:
            print('NO')
        else:
            print('YES')
    else:
        if count%2==0:
            print('NO')
        else:
            print('YES')


n,m=map(int,input().split())
ipp=[]
ipe=[]
for i in range(n):
    ipp.append(str(input()))
for i in range(m):
    ipe.append(str(input()))
complete=0
used=[]
while not complete:
    if len(ipp)>0:
        for i in ipp:
            if i not in used:
                used.append(i)
                ipp.remove(i)
                complete=0
                b=1
                #print(ipp)
                break
            else:
                complete=1
    else:
        complete=1
    if len(ipe)>0:
        for i in ipe:
            if i not in used:
                used.append(i)
                ipe.remove(i)
                complete=0
                b=2
                #print(ipe)
                break
            else:
                complete=1
    else:
        complete=1
if b==1:
    print('YES')
else:
    print('NO')


def getWinner(polandWords, enemyWords):
    if len(polandWords) > len(enemyWords):
        return "YES"
    if len(polandWords) < len(enemyWords):
        return "NO"
    k = 0;

    for word in polandWords:
        if enemyWords.get(word):
            k+=1;

    if (k == 1 and len(enemyWords) == 1):
        return "YES"

    if k == 0 or k == len(enemyWords):
        return "NO";

    if k % 2 != 0:
        return "YES"
    else:
        return "NO"

def main():
    mn = input()
    temp = mn.split(" ");
    n = int(temp[0]);
    m = int(temp[1]);
    polandWords = {}
    enemyWords = {}
    for i in range(0,n):
        polandWords[input()] = 1
    for i in range(0,m):
        enemyWords[input()] = 1
    print(getWinner(polandWords,enemyWords));

if __name__ == "__main__":
    main();


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author llamaoo7
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CVasyaAndTheMushrooms solver = new CVasyaAndTheMushrooms();
        solver.solve(1, in, out);
        out.close();
    }

    static class CVasyaAndTheMushrooms {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = in.nextInt();
            int[] b = new int[n];
            for (int i = 0; i < n; i++) b[i] = in.nextInt();
            long[] col = new long[n + 10];
            for (int i = n - 1; i >= 0; i--) {
                col[i] = a[i] + b[i] + col[i + 1];
            }
            long[] cs = new long[n + 10];
            long[] csb = new long[n + 10];
            for (int i = n - 1; i >= 0; i--) {
                cs[i] = b[i] * (1 + 2 * (n - 1 - i)) + col[i + 1] + cs[i + 1];
                csb[i] = a[i] * (1 + 2 * (n - 1 - i)) + col[i + 1] + cs[i + 1];
            }
            long ret = 0;
            long cur = 0;
            for (int i = 0; i < n; i += 2) {
                ret = Math.max(ret, cur + cs[i]);
                int t = i * 2;
                cur += t * a[i] + (t + 1) * b[i];
                ret = Math.max(ret, cur + csb[i + 1]);
                if (i < n - 1) cur += (t + 2) * b[i + 1] + (t + 3) * a[i + 1];
                ret = Math.max(ret, cur + (t + 4) * col[i + 2] + cs[i + 2]);
            }
            out.println(ret);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author llamaoo7
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CVasyaAndTheMushrooms solver = new CVasyaAndTheMushrooms();
        solver.solve(1, in, out);
        out.close();
    }

    static class CVasyaAndTheMushrooms {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = in.nextInt();
            int[] b = new int[n];
            for (int i = 0; i < n; i++) b[i] = in.nextInt();
            long[] col = new long[n + 10];
            for (int i = n - 1; i >= 0; i--) {
                col[i] = a[i] + b[i] + col[i + 1];
            }
            long[] cs = new long[n + 10];
            for (int i = n - 1; i >= 0; i--) {
                cs[i] = b[i] * (1 + 2 * (n - 1 - i)) + col[i + 1] + cs[i + 1];
            }
            long ret = 0;
            for (int i = 0; i < n; i += 2) {
                ret = Math.max(ret, cs[i]);
                int t = i * 2;
                ret = Math.max(ret, t * a[i] + (t + 1) * b[i] +
                        (i < n - 1 ? (t + 2) * b[i + 1] + (t + 3) * a[i + 1] : 0) +
                        (t + 4) * col[i + 2] + cs[i + 2]);
            }
            out.println(ret);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}