#include<bits/stdc++.h>
using namespace std;
const int N=1e7+10;
int n,W;
int f[40010],v[N],m[N],w[N];
int main(){
cin>>n>>W;
int x,y,z,cnt=0;
for(int i=1;i<=n;i++){
cin>>x>>y>>z;
int b=1;
while(z>=b){
v[++cnt]=b*x;
w[cnt]=b*y;
z-=b;
b*=2;
}
if(z>0){
v[++cnt]=z*x;
w[cnt]=z*y;
}
}
for(int i=1;i<=cnt;i++){
for(int j=W;j>=w[i];j--){
f[j]=max(f[j],f[j-w[i]]+v[i]);
}
}
cout<<f[W]<<endl;
return 0;
}