#include <iostream>
#include <string.h>
using namespace std;
int word[11][11],f[10001],bag,n;
void ZeroOnePack(int cost,int weight);
void CompletePack(int cost,int weight);
void MultiplePack(int cost,int weight,int count);
int main()
{
int i,j,value,complexity;
char str[15];
while(scanf("%d%d",&n,&bag) != EOF)
{
memset(word,0,sizeof(word));
for(i = 1; i <= n; i++)
{
scanf("%s%d%d",str,&value,&complexity);
word[complexity][value]++;
}
memset(f,0,sizeof(f));
for(int i=0;i<11;i++)
for(int j=0;j<11;j++)
if(word[i][j])
MultiplePack(i,j,word[i][j]);
printf("%d\n",f[bag]);
}
return 0;
}
void ZeroOnePack(int cost,int weight){
for(int i=bag;i>=cost;i--)
if(f[i]<f[i-cost]+weight)
f[i]=f[i-cost]+weight;
}
void CompletePack(int cost,int weight){
for(int i=cost;i<=bag;i++)
if(f[i]<f[i-cost]+weight)
f[i]=f[i-cost]+weight;
}
void MultiplePack(int cost,int weight,int count){
if(cost*count>=bag)
CompletePack(cost,weight);
else{
int k=1;
while(k<count){
ZeroOnePack(k*cost,k*weight);
count-=k;
k*=2;
}
ZeroOnePack(count*cost,count*weight);
}
}