#include<cstdio>
#include<iostream>
#include<stdio.h>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
typedef long long LL;
namespace IO
{
template<typename T>void write(T x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9) write(x/10);
putchar(x%10+'0');
}
template<typename T> void read(T &x)
{
x = 0;char ch = getchar();int f = 1;
while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
while(isdigit(ch)){x = x*10+(ch-'0');ch=getchar();}x*=f;
}
};
using namespace IO;
struct a{
LL lose;
LL win;
LL med;
}friends[1000];
signed main()
{
LL dp[1000];
LL n,x;
memset(dp,0,sizeof dp);
read(n);
read(x);
for (LL i=1;i<=n;i++)
{
read(friends[i].lose);
read(friends[i].win);
read(friends[i].med);
}
for (LL j=1;j<=n;j++)
{
for (LL i=x;i>=0;i--)
{
if (i-friends[j].med>=0)
dp[i]=max(dp[i]+friends[j].lose,dp[i-friends[j].med]+friends[j].win);
else
dp[i]+=friends[j].lose;
}
//write(dp[x]);
//
//cout<<" ";
}
write(dp[x]*5);
return 0;
}