#include<bits/stdc++.h>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;
const int mxn=2e5+5,mod=1e9+7;
int main(void){
fast;
int n,m,i,j;
cin>>n>>m;
string s[n];
char t[n];
int sw[n],p[n];
for(i=0;i<n;i++)
cin>>s[i]>>t[i]>>sw[i]>>p[i];
int dp[n+1][m+1][2];
memset(dp,0,sizeof dp);
for(i=0;i<n;i++){
for(j=1;j<=m;j++){
if(t[i]=='S'){
if(sw[i]<=j){
dp[i+1][j][0]=max(dp[i][j][0],dp[i][j-sw[i]][0]+p[i]);
dp[i+1][j][1]=max({dp[i][j][1],dp[i][j-sw[i]][1]+p[i],dp[i][j-sw[i]/2][0]+p[i]});
}
else if(sw[i]/2<=j){
dp[i+1][j][1]=max(dp[i][j-sw[i]/2][0]+p[i],dp[i][j][1]);
dp[i+1][j][0]=dp[i][j][0];
}
else{
dp[i+1][j][0]=dp[i][j][0];
dp[i+1][j][1]=dp[i][j][1];
}
}
else{
dp[i+1][j][0]=dp[i][j][0];
dp[i+1][j][1]=dp[i][j][1];
}
}
}
cout<<max(dp[n][m][0],dp[n][m][1]);
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBmYXN0IHtpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTtjaW4udGllKE5VTEwpO30KdXNpbmcgbmFtZXNwYWNlIHN0ZDsJCgpjb25zdCBpbnQgbXhuPTJlNSs1LG1vZD0xZTkrNzsKCmludCBtYWluKHZvaWQpewoJZmFzdDsKCWludCBuLG0saSxqOwoJY2luPj5uPj5tOwoJc3RyaW5nIHNbbl07CgljaGFyIHRbbl07CglpbnQgc3dbbl0scFtuXTsKCWZvcihpPTA7aTxuO2krKykKCQljaW4+PnNbaV0+PnRbaV0+PnN3W2ldPj5wW2ldOwoJaW50IGRwW24rMV1bbSsxXVsyXTsKCW1lbXNldChkcCwwLHNpemVvZiBkcCk7Cglmb3IoaT0wO2k8bjtpKyspewoJ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