Under construction

Still being built. Things may change

Crossing the Border

Time limit15sMemory limit2048 MB

Summary
Pack n weighted items into knapsacks of capacity W so that the sum of each knapsack's maximum tax is minimal, and count the optimal packings.
Level

Hard8 of 10

Topics
Dynamic programming, Bit manipulation, Combinatorics
Solved
No attempts yet

Statement

Kostya F. is crossing the border of a certain country with nn taxable items. Each item ii is described by two integers wiw_i (its weight) and cic_i (the tax paid to carry it across the border).

Kostya must distribute all items among knapsacks. He may use any number of knapsacks. The total weight of the items in each knapsack cannot exceed WW.

Customs uses a special rule. The officers open each knapsack and set its tax to the maximum cic_i among the items inside it. The total tax is the sum of the taxes of all knapsacks.

Find the minimum total tax Kostya can pay, and the number of ways to achieve it. Since the count can be very large, output it modulo 998 244 353998\,244\,353. Two distributions are the same if there is a bijection between knapsacks such that matching knapsacks hold exactly the same sets of items.

Input

The first line contains two integers nn and WW (1≤n≤221 \le n \le 22; 1≤W≤5⋅1071 \le W \le 5 \cdot 10^7).

Each of the next nn lines contains two integers wiw_i and cic_i (1≤wi≤W1 \le w_i \le W; 1≤ci≤5⋅1071 \le c_i \le 5 \cdot 10^7).

Output

Print two integers: the minimum total tax, and the number of ways to achieve it modulo 998 244 353998\,244\,353.

Hint

In the example, items are numbered from 1 to 5. There are 4 ways to reach the total tax of 9:

  • [1, 3], [2, 4, 5]: tax 5 + 4 = 9
  • [1, 4], [2, 3, 5]: tax 5 + 4 = 9
  • [1, 5], [2, 3, 4]: tax 5 + 4 = 9
  • [1, 2], [3, 4], [5]: tax 5 + 3 + 1 = 9

Examples1

  1. Example 1

    Input
    5 5
    3 5
    1 4
    2 3
    2 2
    2 1
    
    Expected output
    9 4