#include <bits/stdc++.h>
using namespace std;
int w[10000], v[10000], m[10000], dp[10000], T, n, W;
int main(){
cin >> n >> W;
for (int _w, _v, _m, i = 1; i <= n; i++){
cin >> _v >> _w >> _m;
int t = 1;
while (_m >= t){
T++;
w[T] = _w * t;
v[T] = _v * t;
_m -= t;
t <<= 1;
}
if (_m){
T++;
w[T] = _w * _m;
v[T] = _v * _m;
}
}
for (int i = 1; i <= T; i++){
for (int c = W; c >= w[i]; c--)
dp[c] = max(dp[c], dp[c - w[i]] + v[i]);
}
cout << dp[W] << endl;
return 0;
}