import Control.Monad
import Control.Applicative
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Debug.Trace

type STDP s = STArray s Int Int
type DP = Array Int Int

main :: IO ()
main = do
  [n, w] <- getInts
  ns <- replicateM n $ do
    [v, w, m] <- getInts
    return (v, w, m)
  let ns' = concatMap (\(v, w, m) -> replicate m (v, w)) ns
      ans = solve n w ns'
--  print ns'
  print $ maximum $ elems ans

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: Int -> Int -> [(Int, Int)] -> DP
solve num weight items = runST $ do
  array <- newArray (0, weight) 0 :: ST s (STDP s)
  arr' <- solve' items array
  freeze arr'
  where
    solve' :: [(Int, Int)] -> STDP s -> ST s (STDP s)
    solve' [] arr = return arr
    solve' ((v, w):ns) arr = do
      forM_ (reverse [0..weight])  $ \j -> do
                            val <- readArray arr j
                            when (j >= w)
                              $ do
                              val' <- readArray arr (j - w)
                              when (val' + v > val) $
--                                trace (show (j, val'+v)) $
                                writeArray arr j (val' + v)
      solve' ns arr