#include<bits/stdc++.h>
using namespace std;
int n,H,K,ans,sum;
struct hp{
int h,k,w;
}a[1005];
bool cmp(hp x,hp y){return (x.w/(x.h+x.k))>(y.w/(y.h+y.k));}
int main(){
cin>>n>>H>>K;
sum=H+K;
for(int i=0;i<n;i++) cin>>a[i].h>>a[i].k>>a[i].w;
sort(a,a+n,cmp);
for(int i=0;i<n;i++){
if(sum>=a[i].h+a[i].k){
if(H<a[i].h) break;
else{
if(K>=a[i].k) ans+=a[i].w,H-=a[i].h,K-=a[i].k,
sum-=a[i].h+a[i].k;
else{
H-=a[i].k-K;
if(H<a[i].h) break;
else ans+=a[i].w,H-=a[i].h,
sum-=a[i].h+a[i].k;
}
}
}
}
cout<<ans;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll n,q;
map<ll,bool>a;
int main(){
freopen("set.in","r",stdin);
freopen("set.out","w",stdout);
cin>>n>>q;
for(ll i=1;i<=n;i++){
ll x;cin>>x;
a[x]=1;
}
for(;q--;){
ll op,x;cin>>op>>x;
if(!(op-1)) a[x]=0;
else if(!(op-2)) a[x]=1;
else{
ll mx=-1;
for(ll i=2;i<=N;i++){
if(!a[i]) continue;
ll cnt=0;
for(ll j=i;j<=x&&!(x%j);j*=i) cnt++;
mx=max(mx,cnt);
}
cout<<mx<<'\n';
}
}
return 0;
}