eolymp
bolt
Try our new interface for solving problems
Problems

The Timetable from "Diez-Product"

The Timetable from "Diez-Product"

After the computerization of schools completed, when computers were set in every cabinet, a director and his deputy from educational part understood, that can’t anything to do without the program "Timetable" from the firm "Diez-product". There are \textbf{N} cabinets in the school. It is needed to take \textbf{K} lessons in every of them. The computers are different in all of cabinets -- that is why it is possible to work during different time in different cabinets. There is the schedule of the necessary cleanings up during special time in every cabinet (it is different for every cabinet, so as an areas of cabinets are different, and technical workers have different age) after taking of the indicated quantity of the lessons (again, it is possibly that it is different for different cabinets) according to the requirements of technique of safety and sanitary standards. Help please to the administration of school to found out the minimum time during which they will be able to take all the lessons which planned. \InputFile There is two numbers: a quantity of cabinets \textbf{N} and a quantity of the lessons \textbf{K} in the first line. Absence is between them. There are duration of the taking of the lessons \textbf{U_I} in the cabinet with number \textit{\textbf{i}}, a quantity of lessons in the cabinet with number \textbf{C_i}, after that is a technical break, and its duration \textbf{T_i} in next \textbf{N} lines. \textbf{1} ≤ \textbf{N} ≤ \textbf{50}, \textbf{1} ≤ \textbf{K} ≤ \textbf{2000}, \textbf{30} ≤ \textbf{U_i} ≤ \textbf{120}, \textbf{1} ≤ \textbf{C_i} ≤ \textbf{100}, \textbf{10} ≤ \textbf{T_i} ≤ \textbf{50}. \OutputFile There is one number in the file. It is minimum time during what all of lessons will be taking.
Time limit 1.5 second
Memory limit 64 MiB
Input example #1
3 100
10 30 40
30 100 30
20 50 20
Output example #1
570