#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    int n,w; scanf("%d%d",&n,&w);
    vector<int> x(n),y(n),z(n);
    rep(i,0,n)scanf("%d%d%d",&x[i],&y[i],&z[i]);
    int dp[10010]={},idx[10010],deq[10010];
    rep(i,0,n)rep(a,0,y[i]){
        int s=0,t=0;
        for(int j=0;j*y[i]+a<=w;j++){
            int val=dp[j*y[i]+a]-j*x[i];
            while(s<t&&deq[t-1]<=val)t--;
            idx[t]=j; deq[t++]=val;
            dp[j*y[i]+a]=deq[s]+j*x[i];
            if(idx[s]==j-z[i])s++;
        }
    }
    printf("%d\n",dp[w]);
    return 0;
}
