PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000130. Phô mai cho bánh pizza (Cheese)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Phô mai cho bánh pizza (Cheese)

Cheese

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn types of cheese. Type ii has tastiness aia_i per gram and bib_i grams available. You may take any integer amount from 00 to bib_i grams of each type, with total weight at most WW. Maximize total tastiness.

Input

The first line has n,Wn,W. Each of the next nn lines contains ai,bia_i,b_i.

Output

Print the maximum possible tastiness.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤W≤3⋅1081\le W\le3\cdot10^8; 1≤ai≤1091\le a_i\le10^9; 1≤bi≤10001\le b_i\le1000.
  • Subtask 2 (30 points): 1≤n≤16001\le n\le 1600; 1≤W≤3⋅1081\le W\le3\cdot10^8; 1≤ai≤1091\le a_i\le10^9; 1≤bi≤10001\le b_i\le1000.
  • Subtask 3 (50 points): 1≤n≤3000001\le n\le 300000; 1≤W≤3⋅1081\le W\le3\cdot10^8; 1≤ai≤1091\le a_i\le10^9; 1≤bi≤10001\le b_i\le1000.

Examples

Input

3 5
10 2
5 7
8 1

Output

38

Explanation

Take two grams of type one (2020), one gram of type three (88), and two grams of type two (1010), for five grams and total tastiness 3838.