#include <stdio.h>          // printf(), scanf()

#define MAX_N 100
#define MAX_W 10000

int n, W;
int v[MAX_N], w[MAX_N], m[MAX_N];

int
solve()
{
	int dp[MAX_W + 1];
	int deq[MAX_W + 1];  // ?????????(??????????????????)
	int deqv[MAX_W + 1]; // ?????????(???)
	int a;
	int i, j;

	for (i = 0; i <= MAX_W; ++i)
		dp[i] = 0;

	for (i = 0; i < n; ++i)
	{
		for (a = 0; a < w[i]; ++a)
		{
			int s = 0, t = 0; // ????????????????????¨????°?
			for (j = 0; j * w[i] + a <= W; ++j)
			{
				// ????????????????°???? j ?????????
				int val = dp[j * w[i] + a] - j * v[i];
				while (s < t && deqv[t - 1] <= val)
					t--;

				deq[t] = j;
				deqv[t++] = val;

				// ?????????????????????????????????
				dp[j * w[i] + a] = deqv[s] + j * v[i];
				if (deq[s] == j - m[i])
					s++;
			}
		}
	}

	return dp[W];
}

int
main(int argc, char** argv)
{
	int i;

	scanf("%d %d", &n, &W);
	for (i = 0; i < n; ++i)
		scanf("%d %d %d", &v[i], &w[i], &m[i]);

	printf("%d\n", solve());
	return 0;
}