object Main { 
 def main(args: Array[String]): Unit = {
    val (num, limit) = {
      val nw = io.StdIn.readLine().split(" ").map(_.toInt)
      (nw(0), nw(1))
    }
    val items = new Array[(Int, Int, Int)](num)
    for (i <- 0 until num) {
      val vwm = io.StdIn.readLine().split(" ").map(_.toInt)
      items(i) = (vwm(0), vwm(1), vwm(2))
    }

    val dp = solve(limit, items)
    println(dp(num)(limit))
  }

  def solve(weightLimit: Int, items: Array[(Int, Int, Int)]): Array[Array[Int]] = {
    val length = items.length
    val dp = Array.ofDim[Int](length + 1, weightLimit + 1)

    items.zipWithIndex.foreach { case ((v, w, m), i) =>
      for (limit <- 1 to weightLimit) {
        if (w <= limit) {
          for (c <- 0 to Math.min(m, limit / w)) {
            dp(i + 1)(limit) = Math.max(dp(i + 1)(limit), dp(i)(limit - c * w) + c * v)
          }
        } else {
          dp(i + 1)(limit) = dp(i)(limit)
        }
      }
    }
    dp
  }
}