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

#QHD0000049. Hiệu sách II (Book Shop II)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Hiệu sách II (Book Shop II)

Book Shop II

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

A bookstore sells nn different titles. Title ii costs hih_i per copy, each copy has sis_i pages, and at most kik_i copies are available. Your budget is xx. You may buy any integer number of copies from 00 to kik_i of each title; each purchased copy contributes sis_i pages. Find the maximum number of pages obtainable within your budget.

Input

The first line contains n,xn,x. The next three lines contain the nn prices hih_i, the nn page counts sis_i, and the nn copy limits kik_i, respectively.

Output

Print the maximum number of pages.

Subtasks

The independent scoring groups have the following complete constraints:

  • Subtask 1 (20%): 1≤n≤81\le n\le8, 1≤x≤1001\le x\le100, 1≤hi,si≤10001\le h_i,s_i\le1000, 1≤ki≤101\le k_i\le10.
  • Subtask 2 (30%): 1≤n≤401\le n\le40, 1≤x≤10001\le x\le1000, 1≤hi,si≤10001\le h_i,s_i\le1000, 1≤ki≤1001\le k_i\le100.
  • Subtask 3 (50%): 1≤n≤1001\le n\le100, 1≤x≤1000001\le x\le100000, 1≤hi,si≤10001\le h_i,s_i\le1000, 1≤ki≤10001\le k_i\le1000.

Examples

Input

3 10
2 6 3
8 5 4
3 5 2

Output

28

Explanation

Buy three copies of book 1 and one copy of book 3. Cost is 3⋅2+3=93\cdot2+3=9 and page count is 3⋅8+4=283\cdot8+4=28, which is optimal.