#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,w;
    cin>>n>>w;
    ll a,b,m;
    vector<ll> dp(w+1,0);
    for(int i=0;i<n;i++){
    	cin>>a>>b>>m;
    	vector<ll> v;
    	for(ll j=1;m;j*=2){
    		if(j>m) v.pb(m),m=0;
    		else m-=j,v.pb(j);
    	}
    	for(auto& j:v){
    		ll c=a*j,d=b*j;
    		for(int k=w-d;k>=0;k--){
    			dp[k+d]=max(dp[k+d],dp[k]+c);
    		}
    	}
    }
    cout << dp[w] << endl;
    return 0;
}

