#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 300005
#define mins 1005
#define eps 1e-14
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define ppi pair<pair<ll,ll>,ll>
#define ppl pair<pll,ll>
#define vi vector<ll>
#define sc scanf
#define pr printf
#define lld I64d
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define mps make_pair

vector<ppi>arr;
pii p[maxs];
vector<pii>quers;
vector<ppi>v;
ll inside[maxs];
ll mark[maxs],type[maxs],q[maxs],id[maxs];

bool fun(ppi p1,ppi p2,ppi p3){
	double d1=(double)(p3.F.S-p2.F.S)/(p2.F.F-p3.F.F);
	double d2=(double)(p1.F.S-p2.F.S)/(p2.F.F-p1.F.F);
	return d1<=d2;
}

bool comp(ppi p1,ppi p2){
	if(p1.F.F<p2.F.F){
		return true;
	}
	else if(p1.F.F > p2.F.F){
		return false;
	}
	return p1.F.S > p2.F.S;
}

void convex(){
	ll i,j;
	ll n=arr.size();
	v.clear();
	for(i=0;i<n;i++){
		if(mark[arr[i].S]==1 || inside[arr[i].S]==0){
			continue;
		}
		if(v.size()>=1 && abs(v[v.size()-1].F.F-arr[i].F.F) <= eps){
			continue;
		}
		while(v.size()>=2 && fun(v[v.size()-2],v[v.size()-1],arr[i])) v.pop_back();
		v.push_back(arr[i]);
	}
}

ll ans[maxs];
void solve()
{
	ll i,lo=0;
	sort(quers.begin(),quers.end());
	for(i=0;i<quers.size();i++){
		while((lo+1)<v.size()){
			ll t1=(ll)quers[i].F*v[lo].F.F+v[lo].F.S;
			ll t2=(ll)quers[i].F*v[lo+1].F.F+v[lo+1].F.S;
			if(t1>t2){
				break;
			}
			lo++;
		}
		if(lo<v.size())
			ans[quers[i].S]=max(ans[quers[i].S],(ll)quers[i].F*v[lo].F.F+v[lo].F.S);
	}
}

int main()
{
	ll n,i,j,k,t;
	sc("%lld",&n);
	for(i=0;i<n;i++){
		sc("%lld",&t);
		type[i]=t;
		if(t==1){
			sc("%lld %lld",&p[i].F,&p[i].S);
		}
		else if(t==2){
			sc("%lld",&id[i]);
			id[i]--;
		}
		else{
			sc("%lld",&q[i]);
		}
	}
	for(i=0;i<n;i++){
		ans[i]=-llmax;
	}
	for(i=0;i<n;i++){
		if(type[i]==1){
			arr.pb(mps(p[i],i));
		}
	}
	sort(arr.begin(),arr.end(),comp);
	ll blck=sqrt(n);
	for(j=0;j<n;j++){
		mark[j]=0;
	}
	for(i=0;i<n;i+=blck){
		ll lo=min(n-1,i+blck-1);
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=1;
			}
		}
		quers.clear();
		for(j=i;j<=lo;j++){
			if(type[j]==3){
				quers.pb(mps(q[j],j));
			}
		}
		convex();
		solve();
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=0;
			}
		}
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=1;
			}
			else if(type[j]==3){
				for(ll p1=lo;p1>=i;p1--){
					if(p1<=j && mark[p1]==0 && type[p1]==1){
						ans[j]=max(ans[j],(ll)p[p1].F*q[j]+p[p1].S);
					}
					else if(p1>j && type[p1]==2 && id[p1]<i){
						ll ind=id[p1];
						ans[j]=max(ans[j],(ll)p[ind].F*q[j]+p[ind].S);
					}
				}
			}
		}
		for(j=i;j<=lo;j++){
			if(mark[j]==0 && type[j]==1){
				inside[j]=1;
			}
		}
	}
	for(i=0;i<n;i++){
		if(type[i]==3){
			if(ans[i]<=-llmax){
				pr("EMPTY SET\n");
			}
			else{
				pr("%lld\n",ans[i]);
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 300005
#define mins 1005
#define eps 1e-14
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define ppi pair<pair<ll,ll>,ll>
#define ppl pair<pll,ll>
#define vi vector<ll>
#define sc scanf
#define pr printf
#define lld I64d
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define mps make_pair

vector<ppi>arr;
pii p[maxs];
vector<pii>quers;
vector<ppi>v;
ll inside[maxs];
ll mark[maxs],type[maxs],q[maxs],id[maxs];

bool fun(ppi p1,ppi p2,ppi p3){
	double d1=(double)(p3.F.S-p2.F.S)/(p2.F.F-p3.F.F);
	double d2=(double)(p1.F.S-p2.F.S)/(p2.F.F-p1.F.F);
	return d1<=d2;
}

bool comp(ppi p1,ppi p2){
	if(p1.F.F<p2.F.F){
		return true;
	}
	else if(p1.F.F > p2.F.F){
		return false;
	}
	return p1.F.S > p2.F.S;
}

void convex(){
	ll i,j;
	ll n=arr.size();
	v.clear();
	for(i=0;i<n;i++){
		if(mark[arr[i].S]==1 || inside[arr[i].S]==0){
			continue;
		}
		if(v.size()>=1 && abs(v[v.size()-1].F.F-arr[i].F.F) <= eps){
			continue;
		}
		while(v.size()>=2 && fun(v[v.size()-2],v[v.size()-1],arr[i])) v.pop_back();
		v.push_back(arr[i]);
	}
}

ll ans[maxs];
void solve()
{
	ll i,lo=0;
	sort(quers.begin(),quers.end());
	for(i=0;i<quers.size();i++){
		while((lo+1)<v.size()){
			pii p2=v[lo].F,p3=v[lo+1].F;
			double d1=(double)(p3.S-p2.S)/(p2.F-p3.F);
			if(d1<(double)quers[i].F+eps){
				lo++;
			}
			else{
				break;
			}
		}
		if(lo<v.size())
			ans[quers[i].S]=max(ans[quers[i].S],(ll)quers[i].F*v[lo].F.F+v[lo].F.S);
	}
}

int main()
{
	ll n,i,j,k,t;
	sc("%lld",&n);
	for(i=0;i<n;i++){
		sc("%lld",&t);
		type[i]=t;
		if(t==1){
			sc("%lld %lld",&p[i].F,&p[i].S);
		}
		else if(t==2){
			sc("%lld",&id[i]);
			id[i]--;
		}
		else{
			sc("%lld",&q[i]);
		}
	}
	for(i=0;i<n;i++){
		ans[i]=-llmax;
	}
	for(i=0;i<n;i++){
		if(type[i]==1){
			arr.pb(mps(p[i],i));
		}
	}
	sort(arr.begin(),arr.end(),comp);
	ll blck=2000;
	for(j=0;j<n;j++){
		mark[j]=0;
	}
	for(i=0;i<n;i+=blck){
		ll lo=min(n-1,i+blck-1);
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=1;
			}
		}
		quers.clear();
		for(j=i;j<=lo;j++){
			if(type[j]==3){
				quers.pb(mps(q[j],j));
			}
		}
		convex();
		solve();
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=0;
			}
		}
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=1;
			}
			else if(type[j]==3){
				for(ll p1=lo;p1>=i;p1--){
					if(p1<=j && mark[p1]==0 && type[p1]==1){
						ans[j]=max(ans[j],(ll)p[p1].F*q[j]+p[p1].S);
					}
					else if(p1>j && type[p1]==2 && id[p1]<i){
						ll ind=id[p1];
						ans[j]=max(ans[j],(ll)p[ind].F*q[j]+p[ind].S);
					}
				}
			}
		}
		for(j=i;j<=lo;j++){
			if(mark[j]==0 && type[j]==1){
				inside[j]=1;
			}
		}
	}
	for(i=0;i<n;i++){
		if(type[i]==3){
			if(ans[i]<=-llmax){
				pr("EMPTY SET\n");
			}
			else{
				pr("%lld\n",ans[i]);
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 300005
#define mins 1005
#define eps 1e-14
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define ppi pair<pair<ll,ll>,ll>
#define ppl pair<pll,ll>
#define vi vector<ll>
#define sc scanf
#define pr printf
#define lld I64d
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define mps make_pair

vector<ppi>arr;
pii p[maxs];
vector<pii>quers;
vector<ppi>v;
ll inside[maxs];
ll mark[maxs],type[maxs],q[maxs],id[maxs];

bool fun(ppi p1,ppi p2,ppi p3){
	double d1=(double)(p3.F.S-p2.F.S)/(p2.F.F-p3.F.F);
	double d2=(double)(p1.F.S-p2.F.S)/(p2.F.F-p1.F.F);
	return d1<=d2;
}

bool comp(ppi p1,ppi p2){
	if(p1.F.F<p2.F.F){
		return true;
	}
	else if(p1.F.F > p2.F.F){
		return false;
	}
	return p1.F.S > p2.F.S;
}

void convex(){
	ll i,j;
	ll n=arr.size();
	v.clear();
	for(i=0;i<n;i++){
		if(mark[arr[i].S]==1 || inside[arr[i].S]==0){
			continue;
		}
		if(v.size()>=1 && abs(v[v.size()-1].F.F-arr[i].F.F) <= eps){
			continue;
		}
		while(v.size()>=2 && fun(v[v.size()-2],v[v.size()-1],arr[i])) v.pop_back();
		v.push_back(arr[i]);
	}
}

ll ans[maxs];
void solve()
{
	ll i,lo=0;
	sort(quers.begin(),quers.end());
	for(i=0;i<quers.size();i++){
		while((lo+1)<v.size()){
			ll t1=(ll)quers[i].F*v[lo].F.F+v[lo].F.S;
			ll t2=(ll)quers[i].F*v[lo+1].F.F+v[lo+1].F.S;
			if(t1>t2){
				break;
			}
			lo++;
		}
		if(lo<v.size())
			ans[quers[i].S]=max(ans[quers[i].S],(ll)quers[i].F*v[lo].F.F+v[lo].F.S);
	}
}

int main()
{
	ll n,i,j,k,t;
	sc("%lld",&n);
	for(i=0;i<n;i++){
		sc("%lld",&t);
		type[i]=t;
		if(t==1){
			sc("%lld %lld",&p[i].F,&p[i].S);
		}
		else if(t==2){
			sc("%lld",&id[i]);
			id[i]--;
		}
		else{
			sc("%lld",&q[i]);
		}
	}
	for(i=0;i<n;i++){
		ans[i]=-llmax;
	}
	for(i=0;i<n;i++){
		if(type[i]==1){
			arr.pb(mps(p[i],i));
		}
	}
	sort(arr.begin(),arr.end(),comp);
	ll blck=2000;
	for(j=0;j<n;j++){
		mark[j]=0;
	}
	for(i=0;i<n;i+=blck){
		ll lo=min(n-1,i+blck-1);
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=1;
			}
		}
		quers.clear();
		for(j=i;j<=lo;j++){
			if(type[j]==3){
				quers.pb(mps(q[j],j));
			}
		}
		convex();
		solve();
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=0;
			}
		}
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=1;
			}
			else if(type[j]==3){
				for(ll p1=lo;p1>=i;p1--){
					if(p1<=j && mark[p1]==0 && type[p1]==1){
						ans[j]=max(ans[j],(ll)p[p1].F*q[j]+p[p1].S);
					}
					else if(p1>j && type[p1]==2 && id[p1]<i){
						ll ind=id[p1];
						ans[j]=max(ans[j],(ll)p[ind].F*q[j]+p[ind].S);
					}
				}
			}
		}
		for(j=i;j<=lo;j++){
			if(mark[j]==0 && type[j]==1){
				inside[j]=1;
			}
		}
	}
	for(i=0;i<n;i++){
		if(type[i]==3){
			if(ans[i]<=-llmax){
				pr("EMPTY SET\n");
			}
			else{
				pr("%lld\n",ans[i]);
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 300005
#define mins 1005
#define eps 1e-14
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<pair<int,int>,int>
#define ppl pair<pll,ll>
#define vi vector<int>
#define sc scanf
#define pr printf
#define lld I64d
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define mps make_pair

vector<ppi>arr;
pii p[maxs];
vector<pii>quers;
vector<ppi>v;
int mark[maxs],type[maxs],q[maxs],id[maxs];

bool fun(ppi p1,ppi p2,ppi p3){
	double d1=(double)(p3.F.S-p2.F.S)/(p2.F.F-p3.F.F);
	double d2=(double)(p1.F.S-p2.F.S)/(p2.F.F-p1.F.F);
	return d1<=d2;
}

bool comp(ppi p1,ppi p2){
	if(p1.F.F<p2.F.F){
		return true;
	}
	else if(p1.F.F > p2.F.F){
		return false;
	}
	return p1.F.S > p2.F.S;
}

void convex(){
	int i,j;
	sort(arr.begin(),arr.end(),comp);
	int n=arr.size();
	v.clear();
	for(i=0;i<n;i++){
		if(i>0 && abs(arr[i-1].F.F-arr[i].F.F) <= eps){
			continue;
		}
		if(mark[arr[i].S]==1){
			continue;
		}
		while(v.size()>=2 && fun(v[v.size()-2],v[v.size()-1],arr[i])) v.pop_back();
		v.push_back(arr[i]);
	}
}
ll ans[maxs];
void solve()
{
	int i,lo=0;
	sort(quers.begin(),quers.end());
	for(i=0;i<quers.size();i++){
		while((lo+1)<v.size()){
			pii p2=v[lo].F,p3=v[lo+1].F;
			double d1=(double)(p3.S-p2.S)/(p2.F-p3.F);
			if(d1<(double)quers[i].F+eps){
				lo++;
			}
		}
		if(lo<v.size())
			ans[quers[i].S]=max(ans[quers[i].S],(ll)quers[i].F*v[lo].F.F+v[lo].F.S);
	}
}

int main()
{
	int n,i,j,k,t;
	sc("%d",&n);
	for(i=0;i<n;i++){
		sc("%d",&t);
		type[i]=t;
		if(t==1){
			sc("%d %d",&p[i].F,&p[i].S);
		}
		else if(t==2){
			sc("%d",&id[i]);
			id[i]--;
		}
		else{
			sc("%d",&q[i]);
		}
	}
	for(i=0;i<n;i++){
		ans[i]=-llmax;
	}
	int blck=sqrt(n);
	for(j=0;j<n;j++){
		mark[j]=0;
	}
	for(i=0;i<n;i+=blck){
		int lo=min(n-1,i+blck-1);
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=1;
			}
		}
		quers.clear();
		for(j=i;j<=lo;j++){
			if(type[j]==3){
				quers.pb(mps(q[i],i));
			}
		}
		convex();
		solve();
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=0;
			}
		}
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=1;
			}
			else if(type[j]==3){
				for(int p1=lo;p1>=i;p1--){
					if(p1<=j && mark[p1]==0 && type[p1]==1){
						ans[j]=max(ans[j],(ll)p[p1].F*q[j]+p[p1].S);
					}
					else if(p1>j && type[p1]==2 && id[p1]<i){
						int ind=id[p1];
						ans[j]=max(ans[j],(ll)p[ind].F*q[j]+p[ind].S);
					}
				}
			}
		}
		for(j=i;j<=lo;j++){
			if(mark[j]==0){
				arr.pb(mps(p[j],j));
			}
		}
	}
	for(i=0;i<n;i++){
		if(type[i]==3){
			if(ans[i]<=-llmax){
				pr("EMPTY SET\n");
			}
			else{
				pr("%lld\n",ans[i]);
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 300005
#define mins 1005
#define eps 1e-14
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<pair<int,int>,int>
#define ppl pair<pll,ll>
#define vi vector<int>
#define sc scanf
#define pr printf
#define lld I64d
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define mps make_pair

vector<ppi>arr;
pii p[maxs];
vector<pii>quers;
vector<ppi>v;
int mark[maxs],type[maxs],q[maxs],id[maxs];

bool fun(ppi p1,ppi p2,ppi p3){
	double d1=(double)(p3.F.S-p2.F.S)/(p2.F.F-p3.F.F);
	double d2=(double)(p1.F.S-p2.F.S)/(p2.F.F-p1.F.F);
	return d1<=d2;
}

bool comp(ppi p1,ppi p2){
	if(p1.F.F<p2.F.F){
		return true;
	}
	else if(p1.F.F > p2.F.F){
		return false;
	}
	return p1.F.S > p2.F.S;
}

void convex(){
	int i,j;
	sort(arr.begin(),arr.end(),comp);
	int n=arr.size();
	v.clear();
	for(i=0;i<n;i++){
		if(i>0 && abs(arr[i-1].F.F-arr[i].F.F) <= eps){
			continue;
		}
		if(mark[arr[i].S]==1){
			continue;
		}
		cout<<arr[i].S<<" "<<arr[i].F.F<<" "<<arr[i].F.S<<" "<<"Done"<<endl;
		while(v.size()>=2 && fun(v[v.size()-2],v[v.size()-1],arr[i])) v.pop_back();
		v.push_back(arr[i]);
	}
}
ll ans[maxs];
void solve()
{
	int i,lo=0;
	sort(quers.begin(),quers.end());
	//cout<<v.size()<<" "<<quers.size()<<" "<<"Hello"<<endl;
	for(i=0;i<quers.size();i++){
		while((lo+1)<v.size()){
			pii p2=v[lo].F,p3=v[lo+1].F;
			double d1=(double)(p3.S-p2.S)/(p2.F-p3.F);
			if(d1<(double)quers[i].F+eps){
				lo++;
			}
			else{
				break;
			}
		}
		if(lo<v.size())
			ans[quers[i].S]=max(ans[quers[i].S],(ll)quers[i].F*v[lo].F.F+v[lo].F.S);
	}
}

int main()
{
	int n,i,j,k,t;
	sc("%d",&n);
	for(i=0;i<n;i++){
		sc("%d",&t);
		type[i]=t;
		if(t==1){
			sc("%d %d",&p[i].F,&p[i].S);
		}
		else if(t==2){
			sc("%d",&id[i]);
			id[i]--;
		}
		else{
			sc("%d",&q[i]);
		}
	}
	for(i=0;i<n;i++){
		ans[i]=-llmax;
	}
	int blck=sqrt(n);
	for(j=0;j<n;j++){
		mark[j]=0;
	}
	for(i=0;i<n;i+=blck){
		int lo=min(n-1,i+blck-1);
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=1;
			}
		}
		quers.clear();
		for(j=i;j<=lo;j++){
			if(type[j]==3){
				quers.pb(mps(q[i],i));
			}
		}
		convex();
		solve();
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=0;
			}
		}
		for(j=i;j<=lo;j++){
			if(type[j]==2){
				mark[id[j]]=1;
			}
			else if(type[j]==3){
				for(int p1=lo;p1>=i;p1--){
					if(p1<=j && mark[p1]==0 && type[p1]==1){
						ans[j]=max(ans[j],(ll)p[p1].F*q[j]+p[p1].S);
					}
					else if(p1>j && type[p1]==2 && id[p1]<i){
						int ind=id[p1];
					//	cout<<ans[j]<<endl;
						ans[j]=max(ans[j],(ll)p[ind].F*q[j]+p[ind].S);
					//	cout<<i<<" "<<j<<" "<<ind<<" "<<ans[j]<<" "<<q[j]<<endl;
					}
				}
			}
		}
		for(j=i;j<=lo;j++){
			if(mark[j]==0 && type[j]==1){
				arr.pb(mps(p[j],j));
			}
		}
	}
	for(i=0;i<n;i++){
		if(type[i]==3){
			if(ans[i]<=-llmax){
				pr("EMPTY SET\n");
			}
			else{
				pr("%lld\n",ans[i]);
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

const int N = 300010;
int n,out[N],in[N],q[N],tot;
PII p[N];
ll ans[N];
bool pd[N];
vector<PII> v[N*4],tmp;
struct Node{
	int l,r;
}t[N*4];
void build(int x,int l,int r){
	t[x].l=l,t[x].r=r;
	if(l==r) return ;
	int mid = (l+r)/2;
	build(x*2,l,mid);
	build(x*2+1,mid+1,r);
}
void insert(int x,int l,int r,PII &p){
	//cout<<x<<endl;
	if(l==t[x].l && r==t[x].r) {
		v[x].push_back(p);
		return ;
	}
	int mid = (t[x].l+t[x].r)/2;
	if(r<=mid) insert(x*2,l,r,p);
	else if(l>mid) insert(x*2+1,l,r,p);
	else insert(x*2,l,mid,p),insert(x*2+1,mid+1,r,p);
}
void retrieve(int x){
	sort(v[x].begin(),v[x].end());
	tmp.clear();
	int tail  =0;
	for(int i=0;i<v[x].size();i++){
		while(tail>=2 && 1ll*(tmp[tail-2].X-tmp[tail-1].X)*(tmp[tail-1].Y-v[x][i].Y)>=1ll*(tmp[tail-2].Y-tmp[tail-1].Y)*(tmp[tail-1].X-v[x][i].X)) tmp.pop_back(),tail--;
		tmp.push_back(v[x][i]);
		tail++;
	}
	v[x]=tmp;
	if(t[x].l==t[x].r){
		int k = -q[t[x].l];
		bool flag = false;
		ll res = -2e18;
		int now = x,l,r,mid;
		while(now){
			l = 0,r =v[now].size()-1;
			//cout<<l<<' '<<r<<endl;
			while(l<r){
				mid = (l+r)/2;
				if(1ll*k*(v[now][mid].X-v[now][mid+1].X)>=v[now][mid].Y-v[now][mid+1].Y) l=mid+1; else r = mid;
			}
			if(r>=0){
				flag= true;
				res = max(res,1ll*v[now][l].X*q[t[x].l]+v[now][l].Y);
			}
			now>>=1;
			//cout<<l<<endl;
		}
		//cout<<"-----------"<<endl;
		if(flag){
			pd[t[x].l]=true;
			ans[t[x].l]=res;
		}
		return ;
	}
	//cout<<"YY"<<endl;
	retrieve(x*2);
	retrieve(x*2+1);
}
int main(){
	scanf("%d",&n);
	int t,x,y;
	tot=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&t);
		if(t==1){
			scanf("%d%d",&x,&y);
			p[i]=mp(x,y);
			in[i]=tot+1;
			pd[i]=true;
			out[i]=-1;
		} else if(t==2){
			scanf("%d",&x);
			out[x]=tot;
		} else{
			scanf("%d",&x);
			q[++tot]=x;
		}
	}
	//cout<<tot<<endl;
	if(tot==0) return 0;
	build(1,1,tot);
	for(int i=1;i<=n;i++) if(pd[i]){
		if(out[i]==-1) out[i]=tot;
		if(in[i]<=out[i]) insert(1,in[i],out[i],p[i]);
	}
	//cout<<"UUU"<<endl;
	memset(pd,false,sizeof(pd));
	retrieve(1);
	for(int i=1;i<=tot;i++) if(pd[i]) printf("%I64d\n",ans[i]); else puts("EMPTY SET");
	return 0;
}


#include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

const int N = 300010;
int n,out[N],in[N],q[N],tot;
PII p[N];
ll ans[N];
bool pd[N];
vector<PII> v[N*4],tmp;
struct Node{
	int l,r;
}t[N*4];
void build(int x,int l,int r){
	t[x].l=l,t[x].r=r;
	if(l==r) return ;
	int mid = (l+r)/2;
	build(x*2,l,mid);
	build(x*2+1,mid+1,r);
}
void insert(int x,int l,int r,PII &p){
	//cout<<x<<endl;
	if(l==t[x].l && r==t[x].r) {
		v[x].push_back(p);
		return ;
	}
	int mid = (t[x].l+t[x].r)/2;
	if(r<=mid) insert(x*2,l,r,p);
	else if(l>mid) insert(x*2+1,l,r,p);
	else insert(x*2,l,mid,p),insert(x*2+1,mid+1,r,p);
}
void retrieve(int x){
	sort(v[x].begin(),v[x].end());
	tmp.clear();
	int tail  =0;
	for(int i=0;i<v[x].size();i++){
		while(tail>=2 && 1ll*(tmp[tail-2].X-tmp[tail-1].X)*(tmp[tail-1].Y-v[x][i].Y)>=1ll*(tmp[tail-2].Y-tmp[tail-1].Y)*(tmp[tail-1].X-v[x][i].X)) tmp.pop_back(),tail--;
		tmp.push_back(v[x][i]);
		tail++;
	}
	v[x]=tmp;
	if(t[x].l==t[x].r){
		int k = -q[t[x].l];
		bool flag = false;
		ll res = -1e18;
		int now = x,l,r,mid;
		while(now){
			l = 0,r =v[now].size()-1;
			//cout<<l<<' '<<r<<endl;
			while(l<r){
				mid = (l+r)/2;
				if(1ll*k*(v[now][mid].X-v[now][mid+1].X)>=v[now][mid].Y-v[now][mid+1].Y) l=mid+1; else r = mid;
			}
			if(r>=0){
				flag= true;
				res = max(res,1ll*v[now][l].X*q[t[x].l]+v[now][l].Y);
			}
			now>>=1;
			//cout<<l<<endl;
		}
		//cout<<"-----------"<<endl;
		if(flag){
			pd[t[x].l]=true;
			ans[t[x].l]=res;
		}
		return ;
	}
	//cout<<"YY"<<endl;
	retrieve(x*2);
	retrieve(x*2+1);
}
int main(){
	scanf("%d",&n);
	int t,x,y;
	tot=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&t);
		if(t==1){
			scanf("%d%d",&x,&y);
			p[i]=mp(x,y);
			in[i]=tot+1;
			pd[i]=true;
			out[i]=-1;
		} else if(t==2){
			scanf("%d",&x);
			out[x]=tot;
		} else{
			scanf("%d",&x);
			q[++tot]=x;
		}
	}
	//cout<<tot<<endl;
	build(1,1,tot);
	for(int i=1;i<=n;i++) if(pd[i] && (out[i]==-1 || in[i]<=out[i])) insert(1,in[i],(out[i]==-1?tot:out[i]),p[i]);
	//cout<<"UUU"<<endl;
	memset(pd,false,sizeof(pd));
	retrieve(1);
	for(int i=1;i<=tot;i++) if(pd[i]) printf("%I64d\n",ans[i]); else puts("EMPTY SET");
	return 0;
}


#include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

const int N = 300010;
int n,out[N],in[N],q[N],tot;
PII p[N];
ll ans[N];
bool pd[N];
vector<PII> v[N*4],tmp;
struct Node{
	int l,r;
}t[N*4];
void build(int x,int l,int r){
	t[x].l=l,t[x].r=r;
	if(l==r) return ;
	int mid = (l+r)/2;
	build(x*2,l,mid);
	build(x*2+1,mid+1,r);
}
void insert(int x,int l,int r,PII &p){
	//cout<<x<<endl;
	if(l==t[x].l && r==t[x].r) {
		v[x].push_back(p);
		return ;
	}
	int mid = (t[x].l+t[x].r)/2;
	if(r<=mid) insert(x*2,l,r,p);
	else if(l>mid) insert(x*2+1,l,r,p);
	else insert(x*2,l,mid,p),insert(x*2+1,mid+1,r,p);
}
void retrieve(int x){
	sort(v[x].begin(),v[x].end());
	tmp.clear();
	int tail  =0;
	for(int i=0;i<v[x].size();i++){
		while(tail>=2 && 1ll*(tmp[tail-2].X-tmp[tail-1].X)*(tmp[tail-1].Y-v[x][i].Y)>=1ll*(tmp[tail-2].Y-tmp[tail-1].Y)*(tmp[tail-1].X-v[x][i].X)) tmp.pop_back(),tail--;
		tmp.push_back(v[x][i]);
		tail++;
	}
	v[x]=tmp;
	if(t[x].l==t[x].r){
		int k = -q[t[x].l];
		bool flag = false;
		ll res = -1e18;
		int now = x,l,r,mid;
		while(now){
			l = 0,r =v[now].size()-1;
			//cout<<l<<' '<<r<<endl;
			while(l<r){
				mid = (l+r)/2;
				if(1ll*k*(v[now][mid].X-v[now][mid+1].X)>=v[now][mid].Y-v[now][mid+1].Y) l=mid+1; else r = mid;
			}
			if(r>=0){
				flag= true;
				res = max(res,1ll*v[now][l].X*q[t[x].l]+v[now][l].Y);
			}
			now>>=1;
			//cout<<l<<endl;
		}
		//cout<<"-----------"<<endl;
		if(flag){
			pd[t[x].l]=true;
			ans[t[x].l]=res;
		}
		return ;
	}
	//cout<<"YY"<<endl;
	retrieve(x*2);
	retrieve(x*2+1);
}
int main(){
	scanf("%d",&n);
	int t,x,y;
	tot=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&t);
		if(t==1){
			scanf("%d%d",&x,&y);
			p[i]=mp(x,y);
			in[i]=tot+1;
			pd[i]=true;
			out[i]=-1;
		} else if(t==2){
			scanf("%d",&x);
			out[x]=tot;
		} else{
			scanf("%d",&x);
			q[++tot]=x;
		}
	}
	//cout<<tot<<endl;
	build(1,1,tot);
	for(int i=1;i<=n;i++) if(pd[i]){
		if(out[i]==-1) out[i]=tot;
		if(in[i]<=out[i]) insert(1,in[i],out[i],p[i]);
	}
	//cout<<"UUU"<<endl;
	memset(pd,false,sizeof(pd));
	retrieve(1);
	for(int i=1;i<=tot;i++) if(pd[i]) printf("%I64d\n",ans[i]); else puts("EMPTY SET");
	return 0;
}


#include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

const int N = 300010;
int n,out[N],in[N],q[N],tot;
PII p[N];
ll ans[N];
bool pd[N];
vector<PII> v[N*4],tmp;
struct Node{
	int l,r;
}t[N*4];
void build(int x,int l,int r){
	t[x].l=l,t[x].r=r;
	if(l==r) return ;
	int mid = (l+r)/2;
	build(x*2,l,mid);
	build(x*2+1,mid+1,r);
}
void insert(int x,int l,int r,PII &p){
	//cout<<x<<endl;
	if(l==t[x].l && r==t[x].r) {
		v[x].push_back(p);
		return ;
	}
	int mid = (t[x].l+t[x].r)/2;
	if(r<=mid) insert(x*2,l,r,p);
	else if(l>mid) insert(x*2+1,l,r,p);
	else insert(x*2,l,mid,p),insert(x*2+1,mid+1,r,p);
}
void retrieve(int x){
	sort(v[x].begin(),v[x].end());
	tmp.clear();
	int tail  =0;
	for(int i=0;i<v[x].size();i++){
		while(tail>=2 && 1ll*(tmp[tail-2].X-tmp[tail-1].X)*(tmp[tail-1].Y-v[x][i].Y)>=1ll*(tmp[tail-2].Y-tmp[tail-1].Y)*(tmp[tail-1].X-v[x][i].X)) tmp.pop_back(),tail--;
		tmp.push_back(v[x][i]);
		tail++;
	}
	v[x]=tmp;
	if(t[x].l==t[x].r){
		int k = -q[t[x].l];
		bool flag = false;
		ll res = -1e18;
		int now = x,l,r,mid;
		while(now){
			l = 0,r =v[now].size()-1;
			//cout<<l<<' '<<r<<endl;
			while(l<r){
				mid = (l+r)/2;
				if(1ll*k*(v[now][mid].X-v[now][mid+1].X)>=v[now][mid].Y-v[now][mid+1].Y) l=mid+1; else r = mid;
			}
			if(r>=0){
				flag= true;
				res = max(res,1ll*v[now][l].X*q[t[x].l]+v[now][l].Y);
			}
			now>>=1;
			//cout<<l<<endl;
		}
		//cout<<"-----------"<<endl;
		if(flag){
			pd[t[x].l]=true;
			ans[t[x].l]=res;
		}
		return ;
	}
	//cout<<"YY"<<endl;
	retrieve(x*2);
	retrieve(x*2+1);
}
int main(){
	scanf("%d",&n);
	int t,x,y;
	tot=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&t);
		if(t==1){
			scanf("%d%d",&x,&y);
			p[i]=mp(x,y);
			in[i]=tot+1;
			pd[i]=true;
			out[i]=-1;
		} else if(t==2){
			scanf("%d",&x);
			out[x]=tot;
		} else{
			scanf("%d",&x);
			q[++tot]=x;
		}
	}
	//cout<<tot<<endl;
	if(tot==0) return 0;
	build(1,1,tot);
	for(int i=1;i<=n;i++) if(pd[i]){
		if(out[i]==-1) out[i]=tot;
		if(in[i]<=out[i]) insert(1,in[i],out[i],p[i]);
	}
	//cout<<"UUU"<<endl;
	memset(pd,false,sizeof(pd));
	retrieve(1);
	for(int i=1;i<=tot;i++) if(pd[i]) printf("%I64d\n",ans[i]); else puts("EMPTY SET");
	return 0;
}


#include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

const int N = 300010;
int n,out[N],in[N],q[N],tot;
PII p[N];
ll ans[N];
bool pd[N];
vector<PII> v[N*4],tmp;
struct Node{
	int l,r;
}t[N*4];
void build(int x,int l,int r){
	t[x].l=l,t[x].r=r;
	if(l==r) return ;
	int mid = (l+r)/2;
	build(x*2,l,mid);
	build(x*2+1,mid+1,r);
}
void insert(int x,int l,int r,PII &p){
	//cout<<x<<endl;
	if(l==t[x].l && r==t[x].r) {
		v[x].push_back(p);
		return ;
	}
	int mid = (t[x].l+t[x].r)/2;
	if(r<=mid) insert(x*2,l,r,p);
	else if(l>mid) insert(x*2+1,l,r,p);
	else insert(x*2,l,mid,p),insert(x*2+1,mid+1,r,p);
}
void retrieve(int x){
	//cout<<x<<' '<<t[x].l<<' '<<t[x].r<<endl;
	// maintain the node x
	sort(v[x].begin(),v[x].end());
	tmp.clear();
	int tail  =0;
	for(int i=0;i<v[x].size();i++){
		while(tail>=2 && 1ll*(tmp[tail-2].X-tmp[tail-1].X)*(tmp[tail-1].Y-v[x][i].Y)>=1ll*(tmp[tail-2].Y-tmp[tail-1].Y)*(tmp[tail-1].X-v[x][i].X)) tmp.pop_back(),tail--;
		tmp.push_back(v[x][i]);
		tail++;
	}
	v[x]=tmp;
	if(t[x].l==t[x].r){
		int k = -q[t[x].l];
		bool flag = false;
		ll res = -1e18;
		int now = x,l,r,mid;
		while(now){
			l = 0,r =v[now].size()-1;
			//cout<<l<<' '<<r<<endl;
			while(l<r){
				mid = (l+r)/2;
				if(1ll*k*(v[now][mid].X-v[now][mid+1].X)>=v[now][mid].Y-v[now][mid+1].Y) r=mid; else l = mid+1;
			}
			if(r>=0){
				flag= true;
				res = max(res,1ll*v[now][l].X*q[t[x].l]+v[now][l].Y);
			}
			now>>=1;
		}
		//cout<<"-----------"<<endl;
		if(flag){
			pd[t[x].l]=true;
			ans[t[x].l]=res;
		}
		return ;
	}
	//cout<<"YY"<<endl;
	retrieve(x*2);
	retrieve(x*2+1);
}
int main(){
	scanf("%d",&n);
	int t,x,y;
	tot=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&t);
		if(t==1){
			scanf("%d%d",&x,&y);
			p[i]=mp(x,y);
			in[i]=tot+1;
		} else if(t==2){
			scanf("%d",&x);
			out[x]=tot;
		} else{
			scanf("%d",&x);
			q[++tot]=x;
		}
	}
	//cout<<tot<<endl;
	build(1,1,tot);
	for(int i=1;i<=n;i++) if(in[i]!=0 && (out[i]==0 || in[i]<=out[i])) insert(1,in[i],(out[i]==0?tot:out[i]),p[i]);
	//cout<<"UUU"<<endl;
	retrieve(1);
	for(int i=1;i<=tot;i++) if(pd[i]) printf("%I64d\n",ans[i]); else puts("EMPTY SET");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,xx;
const int N = 3e5+10;
int op[N],r[N],cnt;
bool emp[N];
typedef long long ll;
ll Q[N],ans[N];
const ll inf = 6e18;
struct Point{
	ll x,y;
	Point(){}
	Point(ll _x,ll _y){
		x=_x;y=_y;
	}
	bool operator < (const Point &b)const{
		if(x==b.x) return y<b.y;
		return x<b.x;
	}
	Point operator - (const Point &a)const{
		return Point(x-a.x,y-a.y);
	}
	Point operator + (const Point &a)const{
		return Point(x+a.x,y+a.y);
	}
	void in(){
		scanf("%lld %lld",&x,&y);
	}
}p[N],s[N];
vector<Point>T[N<<2];
#define pb push_back
ll cross(const Point &a,const Point &b){
	return a.x*b.y-a.y*b.x;
}
void update(int id,int l,int r,int L,int R,int v){
	if(L<=l&&R>=r){
		T[id].pb(p[v]);
		return;
	}
	int mid = l+r>>1;
	if(L<=mid) update(id<<1,l,mid,L,R,v);
	if(R>mid) update(id<<1|1,mid+1,r,L,R,v);
}
ll get(int id,const Point &a){
	return Q[id]*a.x+a.y;
}
void query(int id,int tp){
	int l=1,r=tp;
	while(r-l>=3){
		int mid1=(l+l+r)/3;
		int mid2=(l+r+r)/3;
		if(get(id,s[mid1])<get(id,s[mid2])) l=mid1;
		else r=mid2;
	}
	for(int i = l; i <= r; i++) ans[id]=max(ans[id],get(id,s[i]));
}
void solve(int id,int l,int r){
	int mid = l+r>>1;
	if(l!=r){
		solve(id<<1,l,mid);
		solve(id<<1|1,mid+1,r);
	}
	if(!(int)T[id].size()) return;
	sort(T[id].begin(),T[id].end());
	int top=0;
	for(auto v:T[id]){
		while(top>1&&cross(v-s[top-1],s[top]-s[top-1])<=0) top--;
		s[++top]=v;
	}
	for(int i = l; i <= r; i++){
		if(op[i]==3&&!emp[i])
		query(i,top);
	}
}
int main(){
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		r[i]=n;
		scanf("%d",&op[i]);
		if(op[i]==1){
			p[i].in();
			cnt++;
		}else if(op[i]==2){
			scanf("%d",&xx);
			cnt--;r[xx]=i;
		}else{
			if(cnt==0) emp[i]=true;
			scanf("%lld",&Q[i]);
		}
	}
	for(int i = 1; i <= n; i++){
		ans[i]=-inf;
		if(op[i]==1){
			update(1,1,n,i,r[i],i);
		}
	}
	solve(1,1,n);
	for(int i = 1; i <= n; i++){
		if(op[i]==3){
			if(emp[i]) puts("EMPTY SET");
			else printf("%lld\n",ans[i]);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,xx;
const int N = 3e5+10;
int op[N],r[N],cnt;
bool emp[N];
typedef long long ll;
ll Q[N],ans[N];
const ll inf = 6e18;
struct Point{
	ll x,y;
	Point(){}
	Point(ll _x,ll _y){
		x=_x;y=_y;
	}
	bool operator < (const Point &b)const{
		if(x==b.x) return y<b.y;
		return x<b.x;
	}
	Point operator - (const Point &a)const{
		return Point(x-a.x,y-a.y);
	}
	Point operator + (const Point &a)const{
		return Point(x+a.x,y+a.y);
	}
	void in(){
		scanf("%lld %lld",&x,&y);
	}
}p[N],s[N];
vector<Point>T[N<<2];
#define pb push_back
ll cross(const Point &a,const Point &b){
	return a.x*b.y-a.y*b.x;
}
void update(int id,int l,int r,int L,int R,int v){
	if(L<=l&&R>=r){
		T[id].pb(p[v]);
		return;
	}
	int mid = l+r>>1;
	if(L<=mid) update(id<<1,l,mid,L,R,v);
	if(R>mid) update(id<<1|1,mid+1,r,L,R,v);
}
ll get(int id,const Point &a){
	return Q[id]*a.x+a.y;
}
void query(int id,int tp){
	int l=1,r=tp;
	while(r-l>=3){
		int mid1=(l+l+r)/3;
		int mid2=(l+r+r)/3;
		if(get(id,s[mid1])<get(id,s[mid2])) l=mid1;
		else r=mid2;
	}
	for(int i = l; i <= r; i++) ans[id]=max(ans[id],get(id,s[i]));
}
void solve(int id,int l,int r){
	int mid = l+r>>1;
	if(l!=r){
		solve(id<<1,l,mid);
		solve(id<<1|1,mid+1,r);
	}
	sort(T[id].begin(),T[id].end());
	int top=0;
	for(auto v:T[id]){
		while(top>1&&cross(s[top]-s[top-1],v-s[top])>=0) top--;
		s[++top]=v;
	}
	for(int i = l; i <= r; i++){
		if(op[i]==3&&!emp[i])
		query(i,top);
	}
}
int main(){
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		r[i]=n;
		scanf("%d",&op[i]);
		if(op[i]==1){
			p[i].in();
			cnt++;
		}else if(op[i]==2){
			scanf("%d",&xx);
			cnt--;r[xx]=i;
		}else{
			if(cnt==0) emp[i]=true;
			scanf("%lld",&Q[i]);
		}
	}
	for(int i = 1; i <= n; i++){
		ans[i]=-inf;
		if(op[i]==1){
			update(1,1,n,i,r[i],i);
		}
	}
	solve(1,1,n);
	for(int i = 1; i <= n; i++){
		if(op[i]==3){
			if(emp[i]) puts("EMPTY SET");
			else printf("%lld\n",ans[i]);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,xx;
const int N = 3e5+10;
int op[N],r[N],cnt;
bool emp[N];
typedef long long ll;
ll Q[N],ans[N];
const ll inf = 6e18;
struct Point{
	ll x,y;
	Point(){}
	Point(ll _x,ll _y){
		x=_x;y=_y;
	}
	bool operator < (const Point &b)const{
		if(x==b.x) return y<b.y;
		return x<b.x;
	}
	Point operator - (const Point &a)const{
		return Point(x-a.x,y-a.y);
	}
	Point operator + (const Point &a)const{
		return Point(x+a.x,y+a.y);
	}
	void in(){
		scanf("%lld %lld",&x,&y);
	}
}p[N],s[N];
vector<Point>T[N<<2];
#define pb push_back
ll cross(const Point &a,const Point &b){
	return a.x*b.y-a.y*b.x;
}
void update(int id,int l,int r,int L,int R,int v){
	if(L<=l&&R>=r){
		T[id].pb(p[v]);
		return;
	}
	int mid = l+r>>1;
	if(L<=mid) update(id<<1,l,mid,L,R,v);
	if(R>mid) update(id<<1|1,mid+1,r,L,R,v);
}
ll get(int id,const Point &a){
	return Q[id]*a.x+a.y;
}
void query(int id,int tp){
	int l=1,r=tp;
	while(r-l>=3){
		int mid1=(l+l+r)/3;
		int mid2=(l+r+r)/3;
		if(get(id,s[mid1])<get(id,s[mid2])) l=mid1;
		else r=mid2;
	}
	for(int i = l; i <= r; i++) ans[id]=max(ans[id],get(id,s[i]));
}
void solve(int id,int l,int r){
	int mid = l+r>>1;
	if(l!=r){
		solve(id<<1,l,mid);
		solve(id<<1|1,mid+1,r);
	}
	sort(T[id].begin(),T[id].end());
	int top=0;
	for(auto v:T[id]){
		while(top>1&&cross(s[top]-s[top-1],v-s[top-1])<=0) top--;
		s[++top]=v;
	}
	for(int i = l; i <= r; i++){
		if(op[i]==3&&!emp[i])
		query(i,top);
	}
}
int main(){
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		r[i]=n;
		scanf("%d",&op[i]);
		if(op[i]==1){
			p[i].in();
			cnt++;
		}else if(op[i]==2){
			scanf("%d",&xx);
			cnt--;r[xx]=i;
		}else{
			if(cnt==0) emp[i]=true;
			scanf("%lld",&Q[i]);
		}
	}
	for(int i = 1; i <= n; i++){
		ans[i]=-inf;
		if(op[i]==1){
			update(1,1,n,i,r[i],i);
		}
	}
	solve(1,1,n);
	for(int i = 1; i <= n; i++){
		if(op[i]==3){
			if(emp[i]) puts("EMPTY SET");
			else printf("%lld\n",ans[i]);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,xx;
const int N = 2e5+10;
int op[N],r[N],cnt;
bool emp[N];
typedef long long ll;
ll Q[N],ans[N];
const ll inf = 6e18;
struct Point{
	ll x,y;
	Point(){}
	Point(ll _x,ll _y){
		x=_x;y=_y;
	}
	bool operator < (const Point &b)const{
		if(x==b.x) return y<b.y;
		return x<b.x;
	}
	Point operator - (const Point &a)const{
		return Point(x-a.x,y-a.y);
	}
	Point operator + (const Point &a)const{
		return Point(x+a.x,y+a.y);
	}
	void in(){
		scanf("%lld %lld",&x,&y);
	}
}p[N],s[N];
vector<Point>T[N<<2];
#define pb push_back
ll cross(const Point &a,const Point &b){
	return a.x*b.y-a.y*b.x;
}
void update(int id,int l,int r,int L,int R,Point v){
	if(L<=l&&R>=r){
		T[id].pb(v);
		return;
	}
	int mid = l+r>>1;
	if(L<=mid) update(id<<1,l,mid,L,R,v);
	if(R>mid) update(id<<1|1,mid+1,r,L,R,v);
}
ll get(int id,const Point &a){
	return Q[id]*a.x+a.y;
}
void query(int id,int tp){
	int l=1,r=tp;
	while(r-l>=3){
		int mid1=(l+l+r)/3;
		int mid2=(l+r+r)/3;
		if(get(id,s[mid1])<get(id,s[mid2])) l=mid1;
		else r=mid2;
	}
	for(int i = l; i <= r; i++) ans[id]=max(ans[id],get(id,s[i]));
}
void solve(int id,int l,int r){
	int mid = l+r>>1;
	if(l!=r){
		solve(id<<1,l,mid);
		solve(id<<1|1,mid+1,r);
	}
	sort(T[id].begin(),T[id].end());
	int top=0;
	for(auto v:T[id]){
		while(top>1&&cross(s[top]-s[top-1],v-s[top-1])<=0) top--;
		s[++top]=v;
	}
	for(int i = l; i <= r; i++){
		if(op[i]==3&&!emp[i])
		query(i,top);
	}
}
int main(){
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		r[i]=n;
		scanf("%d",&op[i]);
		if(op[i]==1){
			p[i].in();
			cnt++;
		}else if(op[i]==2){
			scanf("%d",&xx);
			cnt--;r[xx]=i;
		}else{
			if(cnt==0) emp[i]=true;
			scanf("%lld",&Q[i]);
		}
	}
	for(int i = 1; i <= n; i++){
		ans[i]=-inf;
		if(op[i]==1){
			update(1,1,n,i,r[i],p[i]);
		}
	}
	solve(1,1,n);
	for(int i = 1; i <= n; i++){
		if(op[i]==3){
			if(emp[i]) puts("EMPTY SET");
			else printf("%lld\n",ans[i]);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,xx;
const int N = 3e5+10;
int op[N],r[N],cnt;
bool emp[N];
typedef long long ll;
ll Q[N],ans[N];
const ll inf = 6e18;
struct Point{
	ll x,y;
	Point(){}
	Point(ll _x,ll _y){
		x=_x;y=_y;
	}
	bool operator < (const Point &b)const{
		if(x==b.x) return y<b.y;
		return x<b.x;
	}
	Point operator - (const Point &a)const{
		return Point(x-a.x,y-a.y);
	}
	Point operator + (const Point &a)const{
		return Point(x+a.x,y+a.y);
	}
	void in(){
		scanf("%lld %lld",&x,&y);
	}
}p[N],s[N];
vector<Point>T[N<<2];
#define pb push_back
ll cross(const Point &a,const Point &b){
	return a.x*b.y-a.y*b.x;
}
void update(int id,int l,int r,int L,int R,int v){
	if(L<=l&&R>=r){
		T[id].pb(p[v]);
		return;
	}
	int mid = l+r>>1;
	if(L<=mid) update(id<<1,l,mid,L,R,v);
	if(R>mid) update(id<<1|1,mid+1,r,L,R,v);
}
ll get(int id,const Point &a){
	return Q[id]*a.x+a.y;
}
void query(int id,int tp){
	int l=1,r=tp;
	while(r-l>=3){
		int mid1=(l+l+r)/3;
		int mid2=(l+r+r)/3;
		if(get(id,s[mid1])<get(id,s[mid2])) l=mid1;
		else r=mid2;
	}
	for(int i = l; i <= r; i++) ans[id]=max(ans[id],get(id,s[i]));
}
void solve(int id,int l,int r){
	int mid = l+r>>1;
	if(l!=r){
		solve(id<<1,l,mid);
		solve(id<<1|1,mid+1,r);
	}
	sort(T[id].begin(),T[id].end());
	int top=0;
	for(auto v:T[id]){
		while(top>1&&cross(v-s[top-1],s[top]-s[top-1])<=0) top--;
		s[++top]=v;
	}
	for(int i = l; i <= r; i++){
		if(op[i]==3&&!emp[i])
		query(i,top);
	}
}
int main(){
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		r[i]=n;
		scanf("%d",&op[i]);
		if(op[i]==1){
			p[i].in();
			cnt++;
		}else if(op[i]==2){
			scanf("%d",&xx);
			cnt--;r[xx]=i;
		}else{
			if(cnt==0) emp[i]=true;
			scanf("%lld",&Q[i]);
		}
	}
	for(int i = 1; i <= n; i++){
		ans[i]=-inf;
		if(op[i]==1){
			update(1,1,n,i,r[i],i);
		}
	}
	solve(1,1,n);
	for(int i = 1; i <= n; i++){
		if(op[i]==3){
			if(emp[i]) puts("EMPTY SET");
			else printf("%lld\n",ans[i]);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
//#include <ext/hash_map>
//using namespace __gnu_cxx;
typedef long long LL;
typedef unsigned long long ULL;
#define RDI(x) scanf("%d",&x)
#define RDI_2(x,y) scanf("%d%d",&x,&y)
#define RDD(x) scanf("%lf",&x)
#define RDD_2(x,y) scanf("%lf%lf",&x,&y)
#define RDL(x) scanf("%I64d",&x)
#define RDL_2(x,y) scanf("%I64d%I64d",&x,&y)
#define RDS(x) scanf("%s",x)
#define RDS_2(x,y) scanf("%s%s",x,y)
#define PUTI(x) printf("%d",x)
#define PUTL(x) printf("%I64d",x)
#define PUTF(x) printf("%f",x)
#define PUTC(x) putchar(x)
#define LINE putchar('\n')
#define SPACE putchar(' ')
#define REP(i,x) for(int i=0;i<int(x);++i)
#define REP_1(i,x) for(int i=1;i<=int(x);++i)
#define FOR_EDGE(i,x) for(int i=head[x];~i;i=edge[i].next)
#define FOR_EDGE2(x,i,y) for(int i=head[x][y];~i;i=edge[i].next)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);++i)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);--i)
#define DWN(i,x) for(int i=int(x-1);i>=0;--i)
#define DWN_1(i,x) for(int i=int(x);i>0;--i)
#define FIL(x,v) memset(x,v,sizeof(x))
#define CLR(x) memset(x,0,sizeof(x))
#define ALL(x) x.begin(),x.end()
#define p_queue priority_queue
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define check(x) printf("%s=%d\n",#x,x)
using namespace std;
template<typename T>
T gcd(T a, T b){ return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){ return a / gcd(a, b)*b; }
template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
    if(b==0){x=1,y=0;return a;}
    int d=ext_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return d;
}
template<typename T>
T inv(T a, T n)
{
    T x,y;
    T t=ext_gcd(a,n,x,y);
    if(t!=1)return -1;
    return (x%n+n)%n;
}
template<typename T>
T Q_mul(T a,T b,T Mod)
{
    T ret;
    for(ret =0;b;b>>=1,a=(a+a)%Mod)if(b&1)ret=(ret+a)%Mod;
    return ret;
}
template<typename T>
T quick_pow_mod(T a, T b,T Mod)
{
    T ret;
    for(ret=1;b;b>>=1,(a*=a)%=Mod)if(b&1)(ret*=a)%=Mod;
    return ret;
}
template<typename T>
T quick_pow(T a, T b)
{
    T ret;
    for(ret=1;b;b>>=1,a*=a)if(b&1)ret*=a;
    return ret;
}
double combination(int n, int r)
{
    if (r<n - r) return combination(n, n - r);
    double s = 1.0;
    REP_1(i, n - r) s *= (r + i), s /= i;
    return s;
}
template<typename T>
inline void read(T& v)
{
    T ret=0,sgnv=1;
    char p;
    while(!isdigit(p=getchar()))if(p=='-')sgnv=-1;
    do ret=(ret<<3)+(ret<<1)+p-'0';while(isdigit(p=getchar()));
    v=sgnv*ret;
}
//const double eps=1e-6;
//inline int sgn(double x){ return (x>-eps)-(x<eps); }
//const LL mod=1000000007;
//const double INF = 1e9;
const LL NINF = numeric_limits<LL>::min();
const int INF = 0x7f7f7f7f;
//const int INFCELL = 0x7f;
//const int NINFCELL = 0x80;
//const int NINF = 0x80808080;
#define MAX 300000+5
#define SIZE (1<<20)+5
struct Line
{
    int a,b,st,ed;
    bool operator<(const Line& x)const{return a==x.a?b>x.b:a<x.a;}
    double operator&(const Line& x)const{return (double(x.b)-b)/(double(a)-x.a);}
    LL eval(int x){return LL(x)*a+b;}
}line[MAX];
struct Query
{
    int x,id,r;
    bool operator<(const Query& a)const{return x==a.x?id<a.id:x<a.x;}
}Q[MAX];
struct Cht
{
    int i;
    vector<int> s;
    void insert(int k)
    {
        if(s.size()&&line[s.back()].a==line[k].a)return;
        if(s.empty()){s.emplace_back(k);return;}
        while(s.size()>=2&&(line[s[s.size()-2]]&line[k])<(line[s.back()]&line[k]))s.popb();
        s.emplace_back(k);
    }
    LL query(int x)
    {
        if(s.empty())return NINF;
        while(i+1<s.size()&&line[s[i+1]].eval(x)>line[s[i]].eval(x))++i;
        return line[s[i]].eval(x);
    }
}tree[SIZE];
LL ans[MAX];
int pos[MAX];
void update(int l,int r,int k,int v)
{
    if(line[v].st<=l&&r<=line[v].ed){tree[k].insert(v);return;}
    int mid=(l+r)>>1,left=k<<1,right=left|1;
    if(line[v].st<=mid)update(l,mid,left,v);
    if(line[v].ed>mid)update(mid+1,r,right,v);
}
LL query(int e,int l,int r,int k,int v)
{
    if(l==r)return tree[k].query(v);
    int mid=(l+r)>>1,left=k<<1,right=left|1;
    LL ret=tree[k].query(v);
    if(e<=mid)ret=max(ret,query(e,l,mid,left,v));
    else ret=max(ret,query(e,mid+1,r,right,v));
    return ret;
}
int main()
{
    //freopen("test.in","r",stdin);
    int n,t,x,cnt=0,len=0;
    read(n);
    REP_1(i,n)
    {
        read(t);
        if(t==1)read(line[cnt].a),read(line[cnt].b),line[cnt].st=i,line[cnt].ed=n,pos[i]=cnt++;
        if(t==2)read(x),line[pos[x]].ed=i-1;
        if(t==3)read(x),Q[len].x=x,Q[len].id=len,Q[len++].r=i;
    }
    sort(line,line+cnt),sort(Q,Q+len);
    REP(i,cnt)update(1,n,1,i);
    REP(i,len)ans[Q[i].id]=query(Q[i].r,1,n,1,Q[i].x);
    REP(i,len)ans[i]==NINF?printf("EMPTY SET\n"):(PUTL(ans[i]),LINE);
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/hash_map>
//using namespace __gnu_cxx;
typedef long long LL;
typedef unsigned long long ULL;
#define RDI(x) scanf("%d",&x)
#define RDI_2(x,y) scanf("%d%d",&x,&y)
#define RDD(x) scanf("%lf",&x)
#define RDD_2(x,y) scanf("%lf%lf",&x,&y)
#define RDL(x) scanf("%I64d",&x)
#define RDL_2(x,y) scanf("%I64d%I64d",&x,&y)
#define RDS(x) scanf("%s",x)
#define RDS_2(x,y) scanf("%s%s",x,y)
#define PUTI(x) printf("%d",x)
#define PUTL(x) printf("%I64d",x)
#define PUTF(x) printf("%f",x)
#define PUTC(x) putchar(x)
#define LINE putchar('\n')
#define SPACE putchar(' ')
#define REP(i,x) for(int i=0;i<int(x);++i)
#define REP_1(i,x) for(int i=1;i<=int(x);++i)
#define FOR_EDGE(i,x) for(int i=head[x];~i;i=edge[i].next)
#define FOR_EDGE2(x,i,y) for(int i=head[x][y];~i;i=edge[i].next)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);++i)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);--i)
#define DWN(i,x) for(int i=int(x-1);i>=0;--i)
#define DWN_1(i,x) for(int i=int(x);i>0;--i)
#define FIL(x,v) memset(x,v,sizeof(x))
#define CLR(x) memset(x,0,sizeof(x))
#define ALL(x) x.begin(),x.end()
#define p_queue priority_queue
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define check(x) printf("%s=%d\n",#x,x)
using namespace std;
template<typename T>
T gcd(T a, T b){ return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){ return a / gcd(a, b)*b; }
template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
    if(b==0){x=1,y=0;return a;}
    int d=ext_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return d;
}
template<typename T>
T inv(T a, T n)
{
    T x,y;
    T t=ext_gcd(a,n,x,y);
    if(t!=1)return -1;
    return (x%n+n)%n;
}
template<typename T>
T Q_mul(T a,T b,T Mod)
{
    T ret;
    for(ret =0;b;b>>=1,a=(a+a)%Mod)if(b&1)ret=(ret+a)%Mod;
    return ret;
}
template<typename T>
T quick_pow_mod(T a, T b,T Mod)
{
    T ret;
    for(ret=1;b;b>>=1,(a*=a)%=Mod)if(b&1)(ret*=a)%=Mod;
    return ret;
}
template<typename T>
T quick_pow(T a, T b)
{
    T ret;
    for(ret=1;b;b>>=1,a*=a)if(b&1)ret*=a;
    return ret;
}
double combination(int n, int r)
{
    if (r<n - r) return combination(n, n - r);
    double s = 1.0;
    REP_1(i, n - r) s *= (r + i), s /= i;
    return s;
}
template<typename T>
inline void read(T& v)
{
    T ret=0,sgnv=1;
    char p;
    while(!isdigit(p=getchar()))if(p=='-')sgnv=-1;
    do ret=(ret<<3)+(ret<<1)+p-'0';while(isdigit(p=getchar()));
    v=sgnv*ret;
}
//const double eps=1e-6;
//inline int sgn(double x){ return (x>-eps)-(x<eps); }
//const LL mod=1000000007;
//const double INF = 1e9;
const LL NINF = numeric_limits<LL>::min();
const int INF = 0x7f7f7f7f;
//const int INFCELL = 0x7f;
//const int NINFCELL = 0x80;
//const int NINF = 0x80808080;
#define MAX 300000+5
#define SIZE (1<<20)+5
struct Line
{
    int a,b,st,ed;
    bool operator<(const Line& x)const{return a==x.a?b>x.b:a<x.a;}
    double operator&(const Line& x)const{return (double(x.b)-b)/(double(a)-x.a);}
}line[MAX];
struct Query
{
    int x,id,r;
    bool operator<(const Query& a)const{return x==a.x?id<a.id:x<a.x;}
}Q[MAX];
struct Cht
{
    int i;
    vector<pair<int,double> > s;
    void insert(int k)
    {
        if(s.size()&&line[s.back().x].a==line[k].a)return;
        if(s.empty()){s.emplace_back(mp(k,INF));return;}
        int c=line[s.back().x]&line[k],d;
        if(s.size()==1||(d=line[s[s.size()-2].x]&line[k])<c)s.back().y=c,s.emplace_back(mp(k,INF));
        else s[s.size()-2].y=d,s.back().x=k;
    }
    LL query(int x)
    {
        if(s.empty())return NINF;
        while(x>s[i].y)++i;
        return LL(x)*line[s[i].x].a+line[s[i].x].b;
    }
}tree[SIZE];
LL ans[MAX];
int pos[MAX];
void update(int l,int r,int k,int v)
{
    if(line[v].st<=l&&r<=line[v].ed){tree[k].insert(v);return;}
    int mid=(l+r)>>1,left=k<<1,right=left|1;
    if(line[v].st<=mid)update(l,mid,left,v);
    if(line[v].ed>mid)update(mid+1,r,right,v);
}
LL query(int e,int l,int r,int k,int v)
{
    if(l==r)return tree[k].query(v);
    int mid=(l+r)>>1,left=k<<1,right=left|1;
    LL ret=tree[k].query(v);
    if(e<=mid)ret=max(ret,query(e,l,mid,left,v));
    else ret=max(ret,query(e,mid+1,r,right,v));
    return ret;
}
int main()
{
    //freopen("test.in","r",stdin);
    int n,t,x,cnt=0,len=0;
    read(n);
    REP_1(i,n)
    {
        read(t);
        if(t==1)read(line[cnt].a),read(line[cnt].b),line[cnt].st=i,line[cnt].ed=n,pos[i]=cnt++;
        if(t==2)read(x),line[pos[x]].ed=i-1;
        if(t==3)read(x),Q[len].x=x,Q[len].id=len,Q[len++].r=i;
    }
    sort(line,line+cnt),sort(Q,Q+len);
    REP(i,cnt)update(1,n,1,i);
    REP(i,len)ans[Q[i].id]=query(Q[i].r,1,n,1,Q[i].x);
    REP(i,len)ans[i]==NINF?printf("EMPTY SET\n"):(PUTL(ans[i]),LINE);
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/hash_map>
//using namespace __gnu_cxx;
typedef long long LL;
typedef unsigned long long ULL;
#define RDI(x) scanf("%d",&x)
#define RDI_2(x,y) scanf("%d%d",&x,&y)
#define RDD(x) scanf("%lf",&x)
#define RDD_2(x,y) scanf("%lf%lf",&x,&y)
#define RDL(x) scanf("%I64d",&x)
#define RDL_2(x,y) scanf("%I64d%I64d",&x,&y)
#define RDS(x) scanf("%s",x)
#define RDS_2(x,y) scanf("%s%s",x,y)
#define PUTI(x) printf("%d",x)
#define PUTL(x) printf("%I64d",x)
#define PUTF(x) printf("%f",x)
#define PUTC(x) putchar(x)
#define LINE putchar('\n')
#define SPACE putchar(' ')
#define REP(i,x) for(int i=0;i<int(x);++i)
#define REP_1(i,x) for(int i=1;i<=int(x);++i)
#define FOR_EDGE(i,x) for(int i=head[x];~i;i=edge[i].next)
#define FOR_EDGE2(x,i,y) for(int i=head[x][y];~i;i=edge[i].next)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);++i)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);--i)
#define DWN(i,x) for(int i=int(x-1);i>=0;--i)
#define DWN_1(i,x) for(int i=int(x);i>0;--i)
#define FIL(x,v) memset(x,v,sizeof(x))
#define CLR(x) memset(x,0,sizeof(x))
#define ALL(x) x.begin(),x.end()
#define p_queue priority_queue
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define check(x) printf("%s=%d\n",#x,x)
using namespace std;
template<typename T>
T gcd(T a, T b){ return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){ return a / gcd(a, b)*b; }
template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
    if(b==0){x=1,y=0;return a;}
    int d=ext_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return d;
}
template<typename T>
T inv(T a, T n)
{
    T x,y;
    T t=ext_gcd(a,n,x,y);
    if(t!=1)return -1;
    return (x%n+n)%n;
}
template<typename T>
T Q_mul(T a,T b,T Mod)
{
    T ret;
    for(ret =0;b;b>>=1,a=(a+a)%Mod)if(b&1)ret=(ret+a)%Mod;
    return ret;
}
template<typename T>
T quick_pow_mod(T a, T b,T Mod)
{
    T ret;
    for(ret=1;b;b>>=1,(a*=a)%=Mod)if(b&1)(ret*=a)%=Mod;
    return ret;
}
template<typename T>
T quick_pow(T a, T b)
{
    T ret;
    for(ret=1;b;b>>=1,a*=a)if(b&1)ret*=a;
    return ret;
}
double combination(int n, int r)
{
    if (r<n - r) return combination(n, n - r);
    double s = 1.0;
    REP_1(i, n - r) s *= (r + i), s /= i;
    return s;
}
template<typename T>
inline void read(T& v)
{
    T ret=0,sgnv=1;
    char p;
    while(!isdigit(p=getchar()))if(p=='-')sgnv=-1;
    do ret=(ret<<3)+(ret<<1)+p-'0';while(isdigit(p=getchar()));
    v=sgnv*ret;
}
//const double eps=1e-6;
//inline int sgn(double x){ return (x>-eps)-(x<eps); }
//const LL mod=1000000007;
//const double INF = 1e9;
const LL NINF = numeric_limits<LL>::min();
const int INF = 0x7f7f7f7f;
//const int INFCELL = 0x7f;
//const int NINFCELL = 0x80;
//const int NINF = 0x80808080;
#define MAX 300000+5
#define SIZE (1<<20)+5
struct Line
{
    int a,b,st,ed;
    bool operator<(const Line& x)const{return a==x.a?b>x.b:a<x.a;}
    double operator&(const Line& x)const{return (double(x.b)-b)/(double(a)-x.a);}
}line[MAX];
struct Query
{
    int x,id,r;
    bool operator<(const Query& a)const{return x==a.x?id<a.id:x<a.x;}
}Q[MAX];
struct Cht
{
    int i;
    vector<pair<int,double> > s;
    void insert(int k)
    {
        if(s.size()&&line[s.back().x].a==line[k].a)return;
        if(s.empty()){s.emplace_back(mp(k,INF));return;}
        double c=line[s.back().x]&line[k],d;
        if(s.size()==1||(d=line[s[s.size()-2].x]&line[k])<c)s.back().y=c,s.emplace_back(mp(k,INF));
        else s[s.size()-2].y=d,s.back().x=k;
    }
    LL query(int x)
    {
        if(s.empty())return NINF;
        while(x>s[i].y)++i;
        return LL(x)*line[s[i].x].a+line[s[i].x].b;
    }
}tree[SIZE];
LL ans[MAX];
int pos[MAX];
void update(int l,int r,int k,int v)
{
    if(line[v].st<=l&&r<=line[v].ed){tree[k].insert(v);return;}
    int mid=(l+r)>>1,left=k<<1,right=left|1;
    if(line[v].st<=mid)update(l,mid,left,v);
    if(line[v].ed>mid)update(mid+1,r,right,v);
}
LL query(int e,int l,int r,int k,int v)
{
    if(l==r)return tree[k].query(v);
    int mid=(l+r)>>1,left=k<<1,right=left|1;
    LL ret=tree[k].query(v);
    if(e<=mid)ret=max(ret,query(e,l,mid,left,v));
    else ret=max(ret,query(e,mid+1,r,right,v));
    return ret;
}
int main()
{
    // freopen("test.in","r",stdin);
    int n,t,x,cnt=0,len=0;
    read(n);
    REP_1(i,n)
    {
        read(t);
        if(t==1)read(line[cnt].a),read(line[cnt].b),line[cnt].st=i,line[cnt].ed=n,pos[i]=cnt++;
        if(t==2)read(x),line[pos[x]].ed=i-1;
        if(t==3)read(x),Q[len].x=x,Q[len].id=len,Q[len++].r=i;
    }
    sort(line,line+cnt),sort(Q,Q+len);
    REP(i,cnt)update(1,n,1,i);
    REP(i,len)ans[Q[i].id]=query(Q[i].r,1,n,1,Q[i].x);
    REP(i,len)ans[i]==NINF?printf("EMPTY SET\n"):(PUTL(ans[i]),LINE);
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/hash_map>
//using namespace __gnu_cxx;
typedef long long LL;
typedef unsigned long long ULL;
#define RDI(x) scanf("%d",&x)
#define RDI_2(x,y) scanf("%d%d",&x,&y)
#define RDD(x) scanf("%lf",&x)
#define RDD_2(x,y) scanf("%lf%lf",&x,&y)
#define RDL(x) scanf("%I64d",&x)
#define RDL_2(x,y) scanf("%I64d%I64d",&x,&y)
#define RDS(x) scanf("%s",x)
#define RDS_2(x,y) scanf("%s%s",x,y)
#define PUTI(x) printf("%d",x)
#define PUTL(x) printf("%I64d",x)
#define PUTF(x) printf("%f",x)
#define PUTC(x) putchar(x)
#define LINE putchar('\n')
#define SPACE putchar(' ')
#define REP(i,x) for(int i=0;i<int(x);++i)
#define REP_1(i,x) for(int i=1;i<=int(x);++i)
#define FOR_EDGE(i,x) for(int i=head[x];~i;i=edge[i].next)
#define FOR_EDGE2(x,i,y) for(int i=head[x][y];~i;i=edge[i].next)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);++i)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);--i)
#define DWN(i,x) for(int i=int(x-1);i>=0;--i)
#define DWN_1(i,x) for(int i=int(x);i>0;--i)
#define FIL(x,v) memset(x,v,sizeof(x))
#define CLR(x) memset(x,0,sizeof(x))
#define ALL(x) x.begin(),x.end()
#define p_queue priority_queue
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define check(x) printf("%s=%d\n",#x,x)
using namespace std;
template<typename T>
T gcd(T a, T b){ return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){ return a / gcd(a, b)*b; }
template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
    if(b==0){x=1,y=0;return a;}
    int d=ext_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return d;
}
template<typename T>
T inv(T a, T n)
{
    T x,y;
    T t=ext_gcd(a,n,x,y);
    if(t!=1)return -1;
    return (x%n+n)%n;
}
template<typename T>
T Q_mul(T a,T b,T Mod)
{
    T ret;
    for(ret =0;b;b>>=1,a=(a+a)%Mod)if(b&1)ret=(ret+a)%Mod;
    return ret;
}
template<typename T>
T quick_pow_mod(T a, T b,T Mod)
{
    T ret;
    for(ret=1;b;b>>=1,(a*=a)%=Mod)if(b&1)(ret*=a)%=Mod;
    return ret;
}
template<typename T>
T quick_pow(T a, T b)
{
    T ret;
    for(ret=1;b;b>>=1,a*=a)if(b&1)ret*=a;
    return ret;
}
double combination(int n, int r)
{
    if (r<n - r) return combination(n, n - r);
    double s = 1.0;
    REP_1(i, n - r) s *= (r + i), s /= i;
    return s;
}
template<typename T>
inline void read(T& v)
{
    T ret=0,sgnv=1;
    char p;
    while(!isdigit(p=getchar()))if(p=='-')sgnv=-1;
    do ret=(ret<<3)+(ret<<1)+p-'0';while(isdigit(p=getchar()));
    v=sgnv*ret;
}
//const double eps=1e-6;
//inline int sgn(double x){ return (x>-eps)-(x<eps); }
//const LL mod=1000000007;
//const double INF = 1e9;
const LL NINF = numeric_limits<LL>::min();
const int INF = 0x7f7f7f7f;
//const int INFCELL = 0x7f;
//const int NINFCELL = 0x80;
//const int NINF = 0x80808080;
#define MAX 300000+5
#define SIZE (1<<20)+5
struct Line
{
    int a,b,st,ed;
    bool operator<(const Line& x)const{return a==x.a?b>x.b:a<x.a;}
    double operator&(const Line& x)const{return (double(x.b)-b)/(double(a)-x.a);}
    LL eval(int x){return LL(x)*a+b;}
}line[MAX];
struct Query
{
    int x,id,r;
    bool operator<(const Query& a)const{return x==a.x?id<a.id:x<a.x;}
}Q[MAX];
struct Cht
{
    int i;
    vector<int> s;
    void insert(int k)
    {
        if(s.size()&&line[s.back()].a==line[k].a)return;
        if(s.empty()){s.emplace_back(k);return;}
        while(s.size()>=2&&(line[s[s.size()-2]]&line[k])>=(line[s.back()]&line[k]))s.popb();
        s.emplace_back(k);
    }
    LL query(int x)
    {
        if(s.empty())return NINF;
        while(i+1<s.size()&&line[s[i+1]].eval(x)>line[s[i]].eval(x))++i;
        return line[s[i]].eval(x);
    }
}tree[SIZE];
LL ans[MAX];
int pos[MAX];
void update(int l,int r,int k,int v)
{
    if(line[v].st<=l&&r<=line[v].ed){tree[k].insert(v);return;}
    int mid=(l+r)>>1,left=k<<1,right=left|1;
    if(line[v].st<=mid)update(l,mid,left,v);
    if(line[v].ed>mid)update(mid+1,r,right,v);
}
LL query(int e,int l,int r,int k,int v)
{
    if(l==r)return tree[k].query(v);
    int mid=(l+r)>>1,left=k<<1,right=left|1;
    LL ret=tree[k].query(v);
    if(e<=mid)ret=max(ret,query(e,l,mid,left,v));
    else ret=max(ret,query(e,mid+1,r,right,v));
    return ret;
}
int main()
{
    //freopen("test.in","r",stdin);
    int n,t,x,cnt=0,len=0;
    read(n);
    REP_1(i,n)
    {
        read(t);
        if(t==1)read(line[cnt].a),read(line[cnt].b),line[cnt].st=i,line[cnt].ed=n,pos[i]=cnt++;
        if(t==2)read(x),line[pos[x]].ed=i-1;
        if(t==3)read(x),Q[len].x=x,Q[len].id=len,Q[len++].r=i;
    }
    sort(line,line+cnt),sort(Q,Q+len);
    REP(i,cnt)update(1,n,1,i);
    REP(i,len)ans[Q[i].id]=query(Q[i].r,1,n,1,Q[i].x);
    REP(i,len)ans[i]==NINF?printf("EMPTY SET\n"):(PUTL(ans[i]),LINE);
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/hash_map>
//using namespace __gnu_cxx;
typedef long long LL;
typedef unsigned long long ULL;
#define RDI(x) scanf("%d",&x)
#define RDI_2(x,y) scanf("%d%d",&x,&y)
#define RDD(x) scanf("%lf",&x)
#define RDD_2(x,y) scanf("%lf%lf",&x,&y)
#define RDL(x) scanf("%I64d",&x)
#define RDL_2(x,y) scanf("%I64d%I64d",&x,&y)
#define RDS(x) scanf("%s",x)
#define RDS_2(x,y) scanf("%s%s",x,y)
#define PUTI(x) printf("%d",x)
#define PUTL(x) printf("%I64d",x)
#define PUTF(x) printf("%f",x)
#define PUTC(x) putchar(x)
#define LINE putchar('\n')
#define SPACE putchar(' ')
#define REP(i,x) for(int i=0;i<int(x);++i)
#define REP_1(i,x) for(int i=1;i<=int(x);++i)
#define FOR_EDGE(i,x) for(int i=head[x];~i;i=edge[i].next)
#define FOR_EDGE2(x,i,y) for(int i=head[x][y];~i;i=edge[i].next)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);++i)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);--i)
#define DWN(i,x) for(int i=int(x-1);i>=0;--i)
#define DWN_1(i,x) for(int i=int(x);i>0;--i)
#define FIL(x,v) memset(x,v,sizeof(x))
#define CLR(x) memset(x,0,sizeof(x))
#define ALL(x) x.begin(),x.end()
#define p_queue priority_queue
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define check(x) printf("%s=%d\n",#x,x)
using namespace std;
template<typename T>
T gcd(T a, T b){ return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){ return a / gcd(a, b)*b; }
template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
    if(b==0){x=1,y=0;return a;}
    int d=ext_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return d;
}
template<typename T>
T inv(T a, T n)
{
    T x,y;
    T t=ext_gcd(a,n,x,y);
    if(t!=1)return -1;
    return (x%n+n)%n;
}
template<typename T>
T Q_mul(T a,T b,T Mod)
{
    T ret;
    for(ret =0;b;b>>=1,a=(a+a)%Mod)if(b&1)ret=(ret+a)%Mod;
    return ret;
}
template<typename T>
T quick_pow_mod(T a, T b,T Mod)
{
    T ret;
    for(ret=1;b;b>>=1,(a*=a)%=Mod)if(b&1)(ret*=a)%=Mod;
    return ret;
}
template<typename T>
T quick_pow(T a, T b)
{
    T ret;
    for(ret=1;b;b>>=1,a*=a)if(b&1)ret*=a;
    return ret;
}
double combination(int n, int r)
{
    if (r<n - r) return combination(n, n - r);
    double s = 1.0;
    REP_1(i, n - r) s *= (r + i), s /= i;
    return s;
}
template<typename T>
inline void read(T& v)
{
    T ret=0,sgnv=1;
    char p;
    while(!isdigit(p=getchar()))if(p=='-')sgnv=-1;
    do ret=(ret<<3)+(ret<<1)+p-'0';while(isdigit(p=getchar()));
    v=sgnv*ret;
}
//const double eps=1e-6;
//inline int sgn(double x){ return (x>-eps)-(x<eps); }
//const LL mod=1000000007;
//const double INF = 1e9;
const LL NINF = numeric_limits<LL>::min();
const int INF = 0x7f7f7f7f;
//const int INFCELL = 0x7f;
//const int NINFCELL = 0x80;
//const int NINF = 0x80808080;
#define MAX 300000+5
#define SIZE (1<<20)+5
struct Line
{
    int a,b,st,ed;
    bool operator<(const Line& x)const{return a==x.a?b>x.b:a<x.a;}
    double operator&(const Line& x)const{return (double(x.b)-b)/(double(a)-x.a);}
    LL eval(int x){return LL(x)*a+b;}
}line[MAX];
struct Query
{
    int x,id,r;
    bool operator<(const Query& a)const{return x==a.x?id<a.id:x<a.x;}
}Q[MAX];
struct Cht
{
    int i;
    vector<int> s;
    void insert(int k)
    {
        if(s.size()&&line[s.back()].a==line[k].a)return;
        if(s.empty()){s.emplace_back(k);return;}
        double c=line[s.back()]&line[k];
        if(s.size()==1||(line[s[s.size()-2]]&line[k])<c)s.emplace_back(k);
        else s.back()=k;
    }
    LL query(int x)
    {
        if(s.empty())return NINF;
        while(i+1<s.size()&&line[s[i+1]].eval(x)>line[s[i]].eval(x))++i;
        return line[s[i]].eval(x);
    }
}tree[SIZE];
LL ans[MAX];
int pos[MAX];
void update(int l,int r,int k,int v)
{
    if(line[v].st<=l&&r<=line[v].ed){tree[k].insert(v);return;}
    int mid=(l+r)>>1,left=k<<1,right=left|1;
    if(line[v].st<=mid)update(l,mid,left,v);
    if(line[v].ed>mid)update(mid+1,r,right,v);
}
LL query(int e,int l,int r,int k,int v)
{
    if(l==r)return tree[k].query(v);
    int mid=(l+r)>>1,left=k<<1,right=left|1;
    LL ret=tree[k].query(v);
    if(e<=mid)ret=max(ret,query(e,l,mid,left,v));
    else ret=max(ret,query(e,mid+1,r,right,v));
    return ret;
}
int main()
{
    //freopen("test.in","r",stdin);
    int n,t,x,cnt=0,len=0;
    read(n);
    REP_1(i,n)
    {
        read(t);
        if(t==1)read(line[cnt].a),read(line[cnt].b),line[cnt].st=i,line[cnt].ed=n,pos[i]=cnt++;
        if(t==2)read(x),line[pos[x]].ed=i-1;
        if(t==3)read(x),Q[len].x=x,Q[len].id=len,Q[len++].r=i;
    }
    sort(line,line+cnt),sort(Q,Q+len);
    REP(i,cnt)update(1,n,1,i);
    REP(i,len)ans[Q[i].id]=query(Q[i].r,1,n,1,Q[i].x);
    REP(i,len)ans[i]==NINF?printf("EMPTY SET\n"):(PUTL(ans[i]),LINE);
    return 0;
}


/************************************************************
 *                                                          *
 *            ==>>BG_PeaceMind(BISHAL)               @NEPAL *
 *************************************************************/
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define X first
#define Y second
#define SZ(s) s.size()
#define pii pair<int,int>
#define mpr(a,b) make_pair(a,b)
#define S(a) scanf("%d",&a)
#define P(a) printf("%d\n",a)
#define clr(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define ff(a) memset(a,false,sizeof(a))
#define pb(x) push_back(x)
#define all(v) v.begin(),v.end()
#define fr(i,a,b) for(i=a;i<=b;i++)
#define rf(i,b,a) for(i=b;i>=a;i--)
#define _cin ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
#define MX 101
int n,k,ar[MX+2],br[MX+2],dp[MX][20005];
int lmt=100005;

int solve(int pos,int val)
{
    if(pos>=n)
    {
        if(val==lmt) return 0;
        else return (-1000000000);
    }

    int &ret=dp[pos][val];

    if(ret!=-1) return ret;

    ret=-1;

    ret=max( solve(pos+1,val), ar[pos]+solve( pos+1,val+(ar[pos]-br[pos])));

   return ret;
}

int main()
{
    int i,j;
    while(cin>>n>>k)
    {
        fr(i,0,n-1)cin>>ar[i];
        fr(i,0,n-1)cin>>br[i],br[i]*=k;
        SET(dp);
        int ans=solve(0,lmt);
        if(ans<=0)cout<<-1<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


/************************************************************
 *                                                          *
 *            ==>>BG_PeaceMind(BISHAL)               @NEPAL *
 *************************************************************/
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define X first
#define Y second
#define SZ(s) s.size()
#define pii pair<int,int>
#define mpr(a,b) make_pair(a,b)
#define S(a) scanf("%d",&a)
#define P(a) printf("%d\n",a)
#define clr(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define ff(a) memset(a,false,sizeof(a))
#define pb(x) push_back(x)
#define all(v) v.begin(),v.end()
#define fr(i,a,b) for(i=a;i<=b;i++)
#define rf(i,b,a) for(i=b;i>=a;i--)
#define _cin ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
#define MX 101
int n,k,ar[MX+2],br[MX+2],dp[MX][200002];
int lmt=100005;
int solve(int pos,int val)
{
    if(pos>=n)
    {
        if(val==lmt) return 0;
        else return (-1000000000);
    }

    int &ret=dp[pos][val];

    if(ret!=-1) return ret;

    ret=-1;

    ret=max( solve(pos+1,val), ar[pos]+solve( pos+1,val+(ar[pos]-br[pos])));

   return ret;
}

int main()
{
    int i,j;
    while(cin>>n>>k)
    {
        fr(i,0,n-1)cin>>ar[i];
        fr(i,0,n-1)cin>>br[i],br[i]*=k;
        SET(dp);
        int ans=solve(0,lmt);
        if(ans<=0)cout<<-1<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


/************************************************************
 *                                                          *
 *            ==>>BG_PeaceMind(BISHAL)               @NEPAL *
 *************************************************************/
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define X first
#define Y second
#define SZ(s) s.size()
#define pii pair<int,int>
#define mpr(a,b) make_pair(a,b)
#define S(a) scanf("%d",&a)
#define P(a) printf("%d\n",a)
#define clr(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define ff(a) memset(a,false,sizeof(a))
#define pb(x) push_back(x)
#define all(v) v.begin(),v.end()
#define fr(i,a,b) for(i=a;i<=b;i++)
#define rf(i,b,a) for(i=b;i>=a;i--)
#define _cin ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
#define MX 101
int n,k,ar[MX+1],br[MX+1],dp[MX][10001];

int solve(int pos,int val)
{
    if(pos>=n)
    {
        if(val==0) return 0;
        else return (-10000000);
    }

    int &ret=dp[pos][val];

    if(ret!=-1) return ret;

    ret=-1;

    ret=max( solve(pos+1,val), ar[pos]+solve( pos+1,val+(ar[pos]-br[pos])));

   return ret;
}

int main()
{
    int i,j;
    while(cin>>n>>k)
    {
        fr(i,0,n-1)cin>>ar[i];
        fr(i,0,n-1)cin>>br[i],br[i]*=k;
        SET(dp);
        int ans=solve(0,0);
        if(ans<=0)cout<<-1<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


/************************************************************
 *                                                          *
 *            ==>>BG_PeaceMind(BISHAL)               @NEPAL *
 *************************************************************/
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define X first
#define Y second
#define SZ(s) s.size()
#define pii pair<int,int>
#define mpr(a,b) make_pair(a,b)
#define S(a) scanf("%d",&a)
#define P(a) printf("%d\n",a)
#define clr(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define ff(a) memset(a,false,sizeof(a))
#define pb(x) push_back(x)
#define all(v) v.begin(),v.end()
#define fr(i,a,b) for(i=a;i<=b;i++)
#define rf(i,b,a) for(i=b;i>=a;i--)
#define _cin ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
#define MX 101
int n,k,ar[MX+5],br[MX+5],dp[MX][100001];

int solve(int pos,int val)
{
    if(pos>=n)
    {
        if(val==0) return 0;
        else return (-10000000);
    }

    int &ret=dp[pos][val];

    if(ret!=-1) return ret;

    ret=-1;

    ret=max( solve(pos+1,val), ar[pos]+solve( pos+1,val+(ar[pos]-br[pos])));

   return ret;
}

int main()
{
    int i,j;
    while(cin>>n>>k)
    {
        fr(i,0,n-1)cin>>ar[i];
        fr(i,0,n-1)cin>>br[i],br[i]*=k;
        SET(dp);
        int ans=solve(0,0);
        if(ans<=0)cout<<-1<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


/************************************************************
 *                                                          *
 *            ==>>BG_PeaceMind(BISHAL)               @NEPAL *
 *************************************************************/
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define X first
#define Y second
#define SZ(s) s.size()
#define pii pair<int,int>
#define mpr(a,b) make_pair(a,b)
#define S(a) scanf("%d",&a)
#define P(a) printf("%d\n",a)
#define clr(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define ff(a) memset(a,false,sizeof(a))
#define pb(x) push_back(x)
#define all(v) v.begin(),v.end()
#define fr(i,a,b) for(i=a;i<=b;i++)
#define rf(i,b,a) for(i=b;i>=a;i--)
#define _cin ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
#define MX 101
int n,k,ar[MX+2],br[MX+2],dp[MX][200005];
int lmt=100005;

int solve(int pos,int val)
{
    if(pos>=n)
    {
        if(val==lmt) return 0;
        else return (-1000000000);
    }

    int &ret=dp[pos][val];

    if(ret!=-1) return ret;

    ret=-1;

    ret=max( solve(pos+1,val), ar[pos]+solve( pos+1,val+(ar[pos]-br[pos])));

   return ret;
}

int main()
{
    int i,j;
    while(cin>>n>>k)
    {
        fr(i,0,n-1)cin>>ar[i];
        fr(i,0,n-1)cin>>br[i],br[i]*=k;
        SET(dp);
        int ans=solve(0,lmt);
        if(ans<=0)cout<<-1<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


/************************************************************
 *                                                          *
 *            ==>>BG_PeaceMind(BISHAL)               @NEPAL *
 *************************************************************/
#include<bits/stdc++.h>
#define inf 10000000
#define eps 1e-8
#define pf printf
#define PI acos(-1.0)
#define sz(k) k.size()
#define pb(x) push_back(x)
#define S(a) scanf("%d",&a)
#define P(a) printf("%d",a)
#define SL(a) scanf("%I64d",&a)
#define mpr(a,b) make_pair(a,b)
#define EQ(a,b) (fabs(a-b)<eps)
#define all(v) v.begin(),v.end()
#define S2(a,b) scanf("%d%d",&a,&b)
#define fr(i,a,n) for(i=a;i<=n;i++)

#define clr(a) memset(a,0,sizeof(a))
#define tt(a) memset(a,true,sizeof(a))
#define ff(a) memset(a,false,sizeof(a))
#define Sort(x) sort(x.begin(),x.end())
#define db(x) cout<<#x<<": "<<x<<endl
#define S3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define SL2(a,b) scanf("%I64d%I64d",&a,&b)
#define popcount(i) __builtin_popcount(i)
#define Reverse(x) reverse(x.begin(),x.end())
#define LB(v,k) lower_bound(v.begin(),v.end(),k)
using namespace std;
typedef long long ll;
#define open() freopen("in0.txt","r",stdin)
#define close()freopen("out0.txt","w",stdout)
//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int dp[102][105];
int n,K,wt,p[102],c[102],w[102],ar[105],br[105],ans;

int func(int pos,int tot)
{
    if(tot>wt) return 0;
    if(pos>n) return 0;

    int &ret=dp[pos][tot];

    if(ret!=-1)return ret;

    ret=-inf;
    ret=max(func(pos+1,tot),ar[pos]+func(pos,tot+br[pos]));

   // cout<<ret<< " "<<tot<<endl;
    if(ret%tot==K) ans=max(ans,ret);

    return ret;
}
int main()
{
    int tc,i,j,k,wt=0,cs;
    cin>>n>>K;
    fr(i,1,n)
    {
        cin>>ar[i];

    }
    fr(i,1,n)
    {
        cin>>br[i];
        wt+=br[i];
    }
    ans=0;

    memset(dp,-1,sizeof dp);

    int hy=func(1,0);
    //cout<<hy<<endl;
    cout<<ans<<endl;
}


#include<stdio.h>
const int maxM=105000;
int T[2*maxM];
int A[1000];
int B[1000];
int max(int a,int b){return a>b?a:b;}
int main(void){
   // freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    for(int i=0; i<2*maxM; i++){
        T[i]=0;
    }
    int N,K;
        scanf("%d%d",&N,&K);
    for(int i=0; i<N; i++)
        scanf("%d",&A[i]);
    for(int i=0; i<N; i++){
        scanf("%d",&B[i]);
        B[i]=A[i]-K*B[i];
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<maxM*2; j++){
            if(T[j] &&  0<=j+B[i] && j+B[i]<maxM*2){
                T[j+B[i]]=max(A[i]+T[j],T[j+B[i]]);
            }
        }
        T[maxM+B[i]]=max(A[i],T[maxM+B[i]]);
    }
    printf("%d",T[maxM]?T[maxM]:-1);
    return 0;
}


#include<stdio.h>
const int maxM=205000;
int T[2*maxM];
int A[1000];
int B[1000];
int max(int a,int b){return a>b?a:b;}
int main(void){
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    for(int i=0; i<2*maxM; i++){
        T[i]=0;
    }
    int N,K;
        scanf("%d%d",&N,&K);
    for(int i=0; i<N; i++)
        scanf("%d",&A[i]);
    for(int i=0; i<N; i++){
        scanf("%d",&B[i]);
        B[i]=A[i]-K*B[i];
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<maxM*2; j++){
            if(T[j] &&  0<=j+B[i] && j+B[i]<maxM*2){
                T[j+B[i]]=max(A[i]+T[j],T[j+B[i]]);
            }
        }
        T[maxM+B[i]]=max(A[i],T[maxM+B[i]]);
    }
    printf("%d",T[maxM]?T[maxM]:-1);
    return 0;
}


#include<stdio.h>
#include<set>
#include<vector>
using namespace std;
const int maxN=10000;
int T[maxN][maxN];
int A[maxN];
int B[maxN];
int main(void){
    for(int i=0; i<maxN; i++)
        for(int j=0; j<maxN; j++)
            T[i][j]=0;

    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    int N,K;
    scanf("%d%d",&N,&K);

    for(int i=0; i<N; i++)
        scanf("%d",&A[i]);

    for(int i=0; i<N; i++)
        scanf("%d",&B[i]);
    T[0][0]=1;
    for(int i=0; i<N; i++){
        for(int j=maxN-1; j>=0; j--)
            for(int k=maxN-1; k>=0; k--)
                if(T[j][k]){
                    T[j+A[i]][k+B[i]]=1;
                }
    }
    for(int i=(maxN-1)/K; i>0; i--){
        if(T[i*K][i]){
            printf("%d",i*K);
            return 0;
        }
    }
    printf("-1");
    return 0;
}


#include<stdio.h>
const int maxM=205000;
int T[2*maxM];
int T2[2*maxM];
int A[1000];
int B[1000];
int max(int a,int b){return a>b?a:b;}
int main(void){
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    for(int i=0; i<2*maxM; i++){
        T[i]=0;
        T2[i]=0;
    }
    int N,K;
        scanf("%d%d",&N,&K);
    for(int i=0; i<N; i++)
        scanf("%d",&A[i]);
    for(int i=0; i<N; i++){
        scanf("%d",&B[i]);
        B[i]=A[i]-K*B[i];
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<maxM*2; j++){
            if(T[j] &&  0<=j+B[i] && j+B[i]<maxM*2){
                T2[j+B[i]]=max(A[i]+T[j],T[j+B[i]]);
            }
        }
        T2[maxM+B[i]]=max(A[i],T[maxM+B[i]]);
        for(int j=0; j<maxM*2; j++)
            T[j]=T2[j];
    }
    printf("%d",T[maxM]?T[maxM]:-1);
    return 0;
}


#include<stdio.h>
#include<set>
#include<vector>
using namespace std;
const int maxN=1005;
int T[maxN][maxN];
int A[maxN];
int B[maxN];
int main(void){
    for(int i=0; i<maxN; i++)
        for(int j=0; j<maxN; j++)
            T[i][j]=0;

    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    int N,K;
    scanf("%d%d",&N,&K);

    for(int i=0; i<N; i++)
        scanf("%d",&A[i]);

    for(int i=0; i<N; i++)
        scanf("%d",&B[i]);
    T[0][0]=1;
    for(int i=0; i<N; i++){
        for(int j=maxN-1; j>=0; j--)
            for(int k=maxN-1; k>=0; k--)
                if(T[j][k]){
                    T[j+A[i]][k+B[i]]=1;
                }
    }
    for(int i=(maxN-1)/K; i>0; i--){
        if(T[i*K][i]){
            printf("%d",i*K);
            return 0;
        }
    }
    printf("-1");
    return 0;
}


#include<stdio.h>
const int maxM=205000;
int T[2*maxM];
int T2[2*maxM];
int A[1000];
int B[1000];
int max(int a,int b){return a>b?a:b;}
int main(void){
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    for(int i=0; i<2*maxM; i++){
        T[i]=0;
        T2[i]=0;
    }
    int N,K;
        scanf("%d%d",&N,&K);
    for(int i=0; i<N; i++)
        scanf("%d",&A[i]);
    for(int i=0; i<N; i++){
        scanf("%d",&B[i]);
        B[i]=A[i]-K*B[i];
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<maxM*2; j++){
            if(T[j] &&  0<=j+B[i] && j+B[i]<maxM*2){
                T2[j+B[i]]=max(A[i]+T[j],T[j+B[i]]);
            }
        }
        T2[maxM+B[i]]=max(A[i]+T[maxM],T[maxM+B[i]]);
        for(int j=0; j<maxM*2; j++)
            T[j]=T2[j];
    }
    printf("%d",T[maxM]?T[maxM]:-1);
    return 0;
}


#include<stdio.h>
const int maxM=205000;
int T[2*maxM];
int T2[2*maxM];
int A[1000];
int B[1000];
int max(int a,int b){return a>b?a:b;}
int main(void){
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    for(int i=0; i<2*maxM; i++){
        T[i]=0;
        T2[i]=0;
    }
    int N,K;
        scanf("%d%d",&N,&K);
    for(int i=0; i<N; i++)
        scanf("%d",&A[i]);
    for(int i=0; i<N; i++){
        scanf("%d",&B[i]);
        B[i]=A[i]-K*B[i];
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<maxM*2; j++){
            if(T[j] &&  0<=j+B[i] && j+B[i]<maxM*2){
                T2[j+B[i]]=max(A[i]+T[j],T[j+B[i]]);
            }
        }
        T2[maxM+B[i]]=max(A[i]+T[maxM],T[maxM+B[i]]);
        for(int j=0; j<maxM*2; j++)
            T[j]=T2[j];
    }
    printf("%d",T[maxM]?T[maxM]:-1);
    return 0;
}


#include<stdio.h>
#include<set>
#include<vector>
using namespace std;
const int maxN=10001;
char T[maxN][maxN];
int A[maxN];
int B[maxN];
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int main(void){
    for(int i=0; i<maxN; i++)
        for(int j=0; j<maxN; j++)
            T[i][j]=0;

    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    int N,K;
    scanf("%d%d",&N,&K);

    for(int i=0; i<N; i++)
        scanf("%d",&A[i]);

    for(int i=0; i<N; i++)
        scanf("%d",&B[i]);
    T[0][0]=1;
    int maxA=0;
    int maxB=0;
    for(int i=0; i<N; i++){
        for(int j=maxA; j>=0; j--)
            for(int k=maxB; k>=0; k--)
                if(T[j][k]){
                    T[j+A[i]][k+B[i]]=1;
                    maxA=max(maxA,j+A[i]);
                    maxB=max(maxB,k+B[i]);
                }
    }
    for(int i=(maxN-1)/K; i>0; i--){
        if(T[i*K][i]){
            printf("%d",i*K);
            return 0;
        }
    }
    printf("-1");
    return 0;
}


#include<stdio.h>
#include<set>
#include<vector>
using namespace std;
const int maxN=10001;
char T[maxN][maxN];
int A[maxN];
int B[maxN];
int main(void){
    for(int i=0; i<maxN; i++)
        for(int j=0; j<maxN; j++)
            T[i][j]=0;

   // freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    int N,K;
    scanf("%d%d",&N,&K);

    for(int i=0; i<N; i++)
        scanf("%d",&A[i]);

    for(int i=0; i<N; i++)
        scanf("%d",&B[i]);
    T[0][0]=1;
    for(int i=0; i<N; i++){
        for(int j=maxN-1; j>=0; j--)
            for(int k=maxN-1; k>=0; k--)
                if(T[j][k]){
                    T[j+A[i]][k+B[i]]=1;
                }
    }
    for(int i=(maxN-1)/K; i>0; i--){
        if(T[i*K][i]){
            printf("%d",i*K);
            return 0;
        }
    }
    printf("-1");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

long m,k,a[110],b[110],dp[110][210000];
Long solve(long n, long val,long test)
{
    if(n==m)
    {
        if(val==10010)return dp[n][val]=test;
        else return -5555559;
    }
    long &rect=dp[n][val],r1,r2;
    if(rect!=-1)return rect;
    r1=solve(n+1,val+k*b[n]-a[n],test+a[n]);
    r2=solve(n+1,val,test);
    return rect=max(r1,r2);

}

int main()
{
   cin>>m>>k;
   for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
   int ans;
   memset(dp,-1,sizeof(dp));
   ans=solve(0,10010,0);
   if(ans>0)
   cout<<ans<<endl;
   else cout<<-1<<endl;
   return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int n,k,a[110],b[110],dp[110][210000];
int solve(int ind,int val)
{
    if(ind==n)
    {
        if(val==10010)return dp[ind][val]=0;
        else return -11111;
    }
    int &rect=dp[ind][val],r1,r2;
    if(rect !=-1)return rect;
    r1=solve(ind+1,val+k*b[ind]-a[ind])+a[ind];
    r2=solve(ind+1,val);
    return rect=max(r1,r2);
}

int main()
{
   cin>>n>>k;
   for(int i=0;i<n;i++)cin>>a[i];
   for(int i=0;i<n;i++)cin>>b[i];
  // for(int i=0;i<n;i++)cout<<a[i]<<" "<<b[i]<<endl;
   memset(dp,-1,sizeof(dp));
   int ans;
   ans=solve(0,10010);
   if(ans>0)cout<<ans<<endl;
   else cout<<-1<<endl;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

long m,k,a[110],b[110],dp[110][210000];
 long solve(long n, long val,long test)
{
    if(n==m)
    {
        if(val==10010)return dp[n][val]=test;
        else return -5555559;
    }
    long &rect=dp[n][val],r1,r2;
    if(rect!=-1)return rect;
    r1=solve(n+1,val+k*b[n]-a[n],test+a[n]);
    r2=solve(n+1,val,test);
    return rect=max(r1,r2);

}

int main()
{
   cin>>m>>k;
   for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
   int ans;
   memset(dp,-1,sizeof(dp));
   ans=solve(0,10010,0);
   if(ans>0)
   cout<<ans<<endl;
   else cout<<-1<<endl;
   return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int m,k,a[110],b[110],dp[110][21000];
int solve(int n, int val,int test)
{
    if(n==m)
    {
        if(val==10010)return dp[n][val]=test;
        else return -11111;
    }
    int &rect=dp[n][val],r1,r2;
    if(rect!=-1)return rect;
    r1=solve(n+1,val+k*b[n]-a[n],test+a[n]);
    r2=solve(n+1,val,test);
    return rect=max(r1,r2);

}

int main()
{
   cin>>m>>k;
   for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
   int ans;
   memset(dp,-1,sizeof(dp));
   ans=solve(0,10010,0);
   if(ans>0)
   cout<<ans<<endl;
   else cout<<-1<<endl;
   return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int m,k,a[110],b[110],dp[110][210000];
int solve(int n, int val,int test)
{
    if(n==m)
    {
        if(val==10010)return dp[n][val]=test;
        else return -555555;
    }
    int &rect=dp[n][val],r1,r2;
    if(rect!=-1)return rect;
    r1=solve(n+1,val+k*b[n]-a[n],test+a[n]);
    r2=solve(n+1,val,test);
    return rect=max(r1,r2);

}

int main()
{
   cin>>m>>k;
   for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
   int ans;
   memset(dp,-1,sizeof(dp));
   ans=solve(0,10010,0);
   if(ans>0)
   cout<<ans<<endl;
   else cout<<-1<<endl;
   return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

long m,k,a[110],b[110],dp[110][210000];
 long solve(long n, long val)
{
    if(n==m)
    {
        if(val==10010)return dp[n][val]=0;
        else return -11111;
    }
    long &rect=dp[n][val],r1,r2;
    if(rect!=-1)return rect;
    r1=solve(n+1,val+k*b[n]-a[n])+a[n];
    r2=solve(n+1,val);
    return rect=max(r1,r2);

}

int main()
{
   cin>>m>>k;
   for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
   int ans;
   memset(dp,-1,sizeof(dp));
   ans=solve(0,10010);
   if(ans>0)
   cout<<ans<<endl;
   else cout<<-1<<endl;
   return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int n,k,a[110],b[110],dp[110][210000];
int solve(int ind,int val)
{
    if(ind==n)
    {
        if(val==10010)return 0;
        else return -11111;
    }
    int &rect=dp[ind][val];
    int r1,r2;
    if(rect !=-1)return rect;
    r1=solve(ind+1,val+k*b[n]-a[n])+a[n];
    r2=solve(ind+1,val);
    return rect=max(r1,r2);
}

int main()
{
   cin>>n>>k;
   for(int i=0;i<n;i++)cin>>a[i];
   for(int i=0;i<n;i++)cin>>b[i];
   memset(dp,-1,sizeof(dp));
   int ans=solve(0,10010);
   if(ans>0)cout<<ans<<endl;
   else cout<<-1<<endl;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

long m,k,a[110],b[110],dp[110][210000];
 long solve(long n, long val)
{
    if(n==m)
    {
        if(val==10010)return dp[n][val]=0;
        else return -5555559;
    }
    long &rect=dp[n][val],r1,r2;
    if(rect!=-1)return rect;
    r1=solve(n+1,val+k*b[n]-a[n])+a[n];
    r2=solve(n+1,val);
    return rect=max(r1,r2);

}

int main()
{
   cin>>m>>k;
   for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
   int ans;
   memset(dp,-1,sizeof(dp));
   ans=solve(0,10010);
   if(ans>0)
   cout<<ans<<endl;
   else cout<<-1<<endl;
   return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int m,k,a[110],b[110],dp[110][11001];
int solve(int n, int val,int test)
{
    if(n==m)
    {
        if(val==10010)return dp[n][val]=test;
        else return -11111;
    }
    int &rect=dp[n][val],r1,r2;
    if(rect!=-1)return rect;
    r1=solve(n+1,val+k*b[n]-a[n],test+a[n]);
    r2=solve(n+1,val,test);
    return rect=max(r1,r2);

}

int main()
{
   cin>>m>>k;
   for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
   int ans;
   memset(dp,-1,sizeof(dp));
   ans=solve(0,10010,0);
   if(ans>0)
   cout<<ans<<endl;
   else cout<<-1<<endl;
   return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int m,k,a[110],b[110],dp[110][11001];
int solve(int n, int val,int test)
{
    if(n==m)
    {
        if(val==10010)return test;
        else return -11111;
    }
    int r1,r2;
   // if(rect!=-1)return rect;
    r1=solve(n+1,val+k*b[n]-a[n],test+a[n]);
    r2=solve(n+1,val,test);
    return max(r1,r2);

}

int main()
{
   cin>>m>>k;
   for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
   int ans;
   memset(dp,-1,sizeof(dp));
   ans=solve(0,10010,0);
   if(ans>0)
   cout<<ans<<endl;
   else cout<<-1<<endl;
   return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int m,k,a[110],b[110],dp[110][21000];
int solve(int n, int val,int test)
{
    if(n==m)
    {
        if(val==10010)return dp[n][val]=test;
        else return -11111;
    }
    int &rect=dp[n][val],r1,r2;
    if(rect!=-1)return rect;
    r1=solve(n+1,val+k*b[n]-a[n],test+a[n]);
    r2=solve(n+1,val,test);
    return rect=max(r1,r2);

}

int main()
{
   cin>>m>>k;
   for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
   int ans;
   memset(dp,-1,sizeof(dp));
   ans=solve(0,10010,0);
   if(ans>0)
   cout<<ans<<endl;
   return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

long m,k,a[110],b[110],dp[110][21000];
 long solve(long n, long val)
{
    if(n==m)
    {
        if(val==10010)return dp[n][val]=0;
        else return -11111;
    }
    long &rect=dp[n][val],r1,r2;
    if(rect!=-1)return rect;
    r1=solve(n+1,val+k*b[n]-a[n])+a[n];
    r2=solve(n+1,val);
    return rect=max(r1,r2);

}

int main()
{
   cin>>m>>k;
   for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
   int ans;
   memset(dp,-1,sizeof(dp));
   ans=solve(0,10010);
   if(ans>0)
   cout<<ans<<endl;
   else cout<<-1<<endl;
   return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int m,k,a[110],b[110],dp[110][1100000];
int solve(int n, int val,int test)
{
    if(n==m)
    {
        if(val==10010)return dp[n][val]=test;
        else return -11111;
    }
    int &rect=dp[n][val],r1,r2;
    if(rect!=-1)return rect;
    r1=solve(n+1,val+k*b[n]-a[n],test+a[n]);
    r2=solve(n+1,val,test);
    return rect=max(r1,r2);

}

int main()
{
   cin>>m>>k;
   for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
   int ans;
   memset(dp,-1,sizeof(dp));
   ans=solve(0,10010,0);
   if(ans>0)
   cout<<ans<<endl;
   return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int n , k , ans =0 ;
int B[1001 ] ,C[1001] ,dp[106][20020] ;
int solv (int i , int b  )
{
    if (i==n )
    {
        if (b==0)
            return 0 ;
        else
            return -1e9;

    }
    if (dp[i][b]!=-1)
        return dp[i][b];
    int j=solv(i+1,b+(B[i]-C[i]*k))+B[i];
    int y = solv(i+1,b);
    int u =abs(b-99000);
    return dp[i][u]=max(j,y);
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    int y=solv(0,0);
    if (y<=0)
        cout << "-1";
    else
    cout << y;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>

#define MAX 101
#define ll (0)
using namespace std;
int n , k , ans =0 ;
int B[MAX ] ,C[MAX] ,dp[MAX][ll*2] ;
int solv (int i , int b  )
{
    if (i==n )
    {
        if (b==0)
            return 0 ;
        else
            return -1e9;

    }
    if (dp[i][b+ll]!=-1)
        return dp[i][b+ll];
    return dp[i][b+ll]=max(solv(i+1,b),solv(i+1,b+(B[i]-C[i]*k))+B[i]);
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    int y=solv(0,0);
    if (y<=0)
        cout << "-1";
    else
    cout << y;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int n , k , ans =0 ;
int B[1001 ] ,C[1001] ,dp[1001][200020] ;
int solv (int i , int b  )
{
    if (i==n )
    {
        if (b==0)
            return 0 ;
        else
            return -1e9;

    }
    if (dp[i][b]!=-1)
        return dp[i][b];
    int j=solv(i+1,b+(B[i]-C[i]*k))+B[i];
    int y = solv(i+1,b);
    int u =abs(b-999000);
    return dp[i][u]=max(j,y);
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    int y=solv(0,0);
    if (y<=0)
        cout << "-1";
    else
    cout << y;
    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int n , k , ans =0 ;
int B[1001 ] ,C[1001] ,dp[1001][1000] ;
int solv (int i , int b  )
{
    if (i==n )
    {
        if (b==0)
            return 0 ;
        else
            return -1e10;

    }
    if (dp[i][b]!=-1)
        return dp[i][b];
    int j=solv(i+1,b+(B[i]-C[i]*k))+B[i];
    int y = solv(i+1,b);
    return dp[i][b]=max(j,y);
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    int y=solv(0,0);
    if (y<=0)
        cout << "-1";
    else
    cout << y;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>

#define MAX 101
#define ll (100000)
using namespace std;
int n , k , ans =0 ;
int B[MAX ] ,C[MAX] ,dp[MAX][ll*2] ;
int solv (int i , int b  )
{
    if (i==n )
    {
        if (b==0)
            return 0 ;
        else
            return -1e9;

    }
    if (dp[i][b+ll]!=-1)
        return dp[i][b+ll];
    return dp[i][b+ll]=max(solv(i+1,b),solv(i+1,b+(B[i]-C[i]*k))+B[i]);
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    int y=solv(0,0);
    if (y<=0)
        cout << "-1";
    else
    cout << y;
    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int n , k , ans =0 ;
int B[1001 ] ,C[1001] ,dp[1001] ;
int solv (int i , int b , int c  )
{
    if (i==n )
        return -1 ;
    if (dp[i]!=-1)
        return dp[i];

    if(b==k*c)
    {
        return dp[i]=max(b,solv(i+1,b+B[i],c+C[i]));
    }
    else
        return dp[i]=max (solv(i+1,b+B[i],c+C[i]),solv(i+1,b,c));
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    cout << solv(0,B[0],C[0]);
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int n , k , ans =0 ;
int B[1001 ] ,C[1001] ,dp[106][200020] ;
int solv (int i , int b  )
{
    if (i==n )
    {
        if (b==0)
            return 0 ;
        else
            return -1e9;

    }
    if (dp[i][b]!=-1)
        return dp[i][b];
    int j=solv(i+1,b+(B[i]-C[i]*k))+B[i];
    int y = solv(i+1,b);
    int u =abs(b-99000);
    return dp[i][u]=max(j,y);
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    int y=solv(0,0);
    if (y<=0)
        cout << "-1";
    else
    cout << y;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>

#define MAX 101
#define ll (100*100*10)
using namespace std;
int n , k , ans =0 ;
int B[MAX ] ,C[MAX] ,dp[MAX][ll*2] ;
int solv (int i , int b  )
{
    if (i==n )
    {
        if (b==0)
            return 0 ;
        else
            return -1e9;

    }
    if (dp[i][b+ll]!=-1)
        return dp[i][b+ll];
    return dp[i][b+ll]=max(solv(i+1,b),solv(i+1,b+(B[i]-C[i]*k))+B[i]);
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    int y=solv(0,0);
    if (y<=0)
        cout << "-1";
    else
    cout << y;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>

#define MAX 101
#define ll (100*100*10)
using namespace std;
int n , k , ans =0 ;
int B[MAX ] ,C[MAX] ,dp[MAX][ll*2] ;
int solv (int i , int b  )
{
    if (i==n )
    {
        if (b==0)
            return 0 ;
        else
            return -1e9;

    }
    if (dp[i][b+ll]!=-1)
        return dp[i][b];
    return dp[i][b+ll]=max(solv(i+1,b),solv(i+1,b+(B[i]-C[i]*k))+B[i]);
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    int y=solv(0,0);
    if (y<=0)
        cout << "-1";
    else
    cout << y;
    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int n , k , ans =0 ;
int B[1001 ] ,C[1001] ,dp[1001][2001] ;
int solv (int i , int b  )
{
    if (i==n )
    {
        if (b==0)
            return 0 ;
        else
            return -1e10;

    }
    if (dp[i][b]!=-1)
        return dp[i][b];
    int j=solv(i+1,b+(B[i]-C[i]*k))+B[i];
    int y = solv(i+1,b);
    return dp[i][b]=max(j,y);
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    int y=solv(0,0);
    if (y<=0)
        cout << "-1";
    else
    cout << y;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int n , k , ans =0 ;
int B[1001 ] ,C[1001] ,dp[1001][200020] ;
int solv (int i , int b  )
{
    if (i==n )
    {
        if (b==0)
            return 0 ;
        else
            return -1e9;

    }
    if (dp[i][b+100000]!=-1)
        return dp[i][b];
    return dp[i][b+100000]=max(solv(i+1,b),solv(i+1,b+(B[i]-C[i]*k))+B[i]);
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    int y=solv(0,0);
    if (y<=0)
        cout << "-1";
    else
    cout << y;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int n , k , ans =0 ;
int B[1001 ] ,C[1001] ,dp[1001][200020] ;
int solv (int i , int b  )
{
    if (i==n )
    {
        if (b==0)
            return 0 ;
        else
            return -1e9;

    }
    if (dp[i][b]!=-1)
        return dp[i][b];
    int j=solv(i+1,b+(B[i]-C[i]*k))+B[i];
    int y = solv(i+1,b);
    int u =abs(b+100000);
    return dp[i][u]=max(j,y);
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    int y=solv(0,0);
    if (y<=0)
        cout << "-1";
    else
    cout << y;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int n , k , ans =0 ;
int B[1001 ] ,C[1001] ,dp[1001][200020] ;
int solv (int i , int b  )
{
    if (i==n )
    {
        if (b==0)
            return 0 ;
        else
            return -1e9;

    }
    if (dp[i][b]!=-1)
        return dp[i][b];
    int j=solv(i+1,b+(B[i]-C[i]*k))+B[i];
    int y = solv(i+1,b);
    long long u =b+100000;
    return dp[i][u]=max(j,y);
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    int y=solv(0,0);
    if (y<=0)
        cout << "-1";
    else
    cout << y;
    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int n , k , ans =0 ;
int B[1001 ] ,C[1001] ,dp[1001] ;
int solv (int i , int b , int c  )
{
    if (i==n )
        return -1 ;
    if (dp[i]!=-1)
        return dp[i];

    if(b==k*c)
    {
        return dp[i]=max(b,solv(i+1,b+B[i],c+C[i]));
    }
    else
        return dp[i]=max (solv(i+1,b+B[i],c+C[i]),solv(i+1,b,c));
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    cout << solv(1,B[0],C[0]);
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int n , k , ans =0 ;
int B[1001 ] ,C[1001] ,dp[1001][200020] ;
int solv (int i , int b  )
{
    if (i==n )
    {
        if (b==0)
            return 0 ;
        else
            return -1e9;

    }
    if (dp[i][b+10000]!=-1)
        return dp[i][b];
    return dp[i][b+10000]=max(solv(i+1,b),solv(i+1,b+(B[i]-C[i]*k))+B[i]);
}
int main()
{
    cin >> n >> k ;
    memset(dp,-1,sizeof(dp));
    for ( int i=0 ; i<n ; i++ )
        cin >>B[i];
    for ( int i=0 ; i<n ; i++ )
        cin >>C[i];
    int y=solv(0,0);
    if (y<=0)
        cout << "-1";
    else
    cout << y;
    return 0;
}


/*
    author:ray007great
    version:1.0
*/
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<time.h>
#include<queue>
using namespace std;
typedef long long ll;
//c++
#pragma comment(linker, "/STACK:102400000,102400000")
// g++
//int size = 256 << 20; // 256MB
//char *p = (char*)malloc(size) + size;
//__asm__("movl %0, %esp\n" :: "r"(p) );

#define sf(a) scanf("%d",&a)
#define sfs(a) scanf("%s",a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define rep1(i,a,b) for(int i=(a);i<(b);i++)
#define clr(a) memset(a,0,sizeof(a))
#define clr1(a) memset(a,-1,sizeof(a))
#define pfk  printf("fuck\n")

/*  define */

/* clock  */

//clock_t start, finish;
//start = clock();
//finish = clock();
//double duration = (double)(finish - start)/CLOCKS_PER_SEC;
//printf( "%.10f seconds\n", duration );

/* clock */

/* data */
/* data */
int a[250],b[250],c[250];
int dp[2*100000+1000];
int main(){
    int n,k,ans,v=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++)   cin>>a[i];
    for(int i=1;i<=n;i++){
        cin>>b[i];
        c[i]=a[i]-k*b[i]+1000;
        v+=c[i];
    }
    //cout<<v<<endl;
    dp[0]=0;
    for(int i=1;i<=200000;i++) dp[i]=-9999999;
    for(int i=1;i<=n;i++){
        for(int V=v;V>=c[i];V--){
            //if(dp[V-c[i]]==-9999999) continue;
            dp[V]=max(dp[V],dp[V-c[i]]+a[i]);
        }
    }
//    cout<<dp[1000]<<endl;
//    cout<<dp[2000]<<endl;
//    cout<<dp[3000]<<endl;
//    cout<<dp[4000]<<endl;
    for(int i=n;i>=1;i--)
        if(dp[i*1000]>0){
            cout<<dp[i*1000]<<endl;
            return 0;
        }
    cout<<"-1"<<endl;
    return 0;
}