This page is still under construction.

Parts of this page are still being built. What you see may change.

Experiment "X": Explosions Expected

Time limit1sMemory limit512 MB

Summary
Count valid mixtures (at most S total ounces, at least two ingredients used) that are not dominated coordinatewise by any of M given exploding mixtures, modulo nothing.
Level

Hard8 of 10

Topics
Combinatorics, Dynamic programming, Intervals, Math
Solved
No attempts yet

Problem

Vasya has taken the post of court alchemist, and his task is to brew the philosopher's stone by mixing ingredients.

There are KK ingredients. An experiment is a plan (a1,a2,…,aK)(a_1, a_2, \dots, a_K): Vasya takes aia_i ounces of the ii-th ingredient, pours everything into the crucible, and heats it. Every aia_i is a non-negative integer, and the total amount may not exceed the crucible capacity SS, so a1+a2+⋯+aK≤Sa_1 + a_2 + \dots + a_K \le S. In every experiment at least two ingredients are actually used: at least two of the aia_i are strictly positive.

So far every mixture has exploded. Vasya has spotted a monotonicity rule: if a plan (a1,…,aK)(a_1, \dots, a_K) explodes, then every plan (b1,…,bK)(b_1, \dots, b_K) with bi≥aib_i \ge a_i for all ii explodes as well.

Vasya has already carried out MM experiments, and all of them exploded. Call a plan definitely unsuccessful when the monotonicity rule guarantees it will explode, i.e. when at least one of the MM exploded plans (c1,…,cK)(c_1, \dots, c_K) satisfies ai≥cia_i \ge c_i for every ii.

Count how many valid experiment plans are not definitely unsuccessful. A plan is valid when every aia_i is a non-negative integer, a1+⋯+aK≤Sa_1 + \dots + a_K \le S, and at least two of the aia_i are positive.

Input

The first line contains three integers KK, SS, and MM (2≤K≤302 \le K \le 30, 2≤S≤100002 \le S \le 10000, 0≤M≤200 \le M \le 20), where MM is the number of experiments already conducted. Each of the next MM lines contains KK integers describing one already-conducted experiment (all of which exploded).

Output

Print one integer: the number of valid experiment plans that are not definitely unsuccessful. This count can be very large, so print the exact value.

Examples4

  1. Example 1

    Input
    2 4 2
    1 3
    2 1
    
    Expected output
    2
    
  2. Example 2

    Input
    3 5 0
    
    Expected output
    40
    
  3. Example 3

    Input
    2 4 1
    2 2
    
    Expected output
    5
    
  4. Example 4

    Input
    2 4 1
    1 1
    
    Expected output
    0