#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    UL dp[101][10001] = {};

    void Solve() {
        UL N, W; cin >> N >> W;
        rep(i, N) {
            UL v, w, m; cin >> v >> w >> m;
            rep(M, w) {
                deque<UL> Q;
                for (UL t = 0; t * w + M <= W; t++) {
                    if (Q.size()) if (Q.front() + m < t) Q.pop_front();
                    UL p = t * w + M;
                    while (Q.size()) {
                        if (dp[i][Q.back() * w + M] + t * v > dp[i][p] + Q.back() * v) break;
                        Q.pop_back();
                    }
                    Q.push_back(t);
                    dp[i + 1][p] = dp[i][Q.front() * w + M] + v * (t - Q.front());
                }
            }
        }
        cout << dp[N][W] << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    //cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}


