include
include
include
using namespace std;
int n, x;
int F[9000];
int win[1010], lose[1010], v[1010];
int main() {
cin >> n >> x;
for (int i = 1; i <= n; i++) {
cin >> lose[i] >> win[i] >> v[i];
}
for (int i = 1; i <= n; i++) {
for (int j = x; j >= 0; j--) {
if (j >= v[i])
F[j] = max(F[j], F[j - v[i]] + win[i]);
else
F[j] = max(lose[i], F[j]);
}
}
cout << (long long)F[x] * 5;
return 0;
}