This page is still under construction.

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

The last wizard

Time limit1sMemory limit256 MB

Summary
Ten counters start at 1 and grow through T random additive updates; output their expected product scaled by A to the T modulo 1000000007.
Level

Hard8 of 10

Topics
Probability, Combinatorics, Matrix, Dynamic programming
Solved
No attempts yet

Problem

The last wizard in the world, Jaeui, is close to his final moment. Jaeui understands every natural phenomenon and carries vast mana in his body, yet against an incurable disease of unknown cause he could do nothing. Writhing in pain, Jaeui kept preparing an arrangement that stops magic from dying out in the world, and only the finishing touch is left. His closest friend Taehyun receives this arrangement.

Jaeui numbered the 10 kinds of mana he considered essential from 0 to 9 and made them trainable for Taehyun. Taehyun is an ordinary person, so he holds amount 1 of each of the 10 kinds of mana.

One training session has NN ways for mana to increase. Number the ways from 1 to NN. Way ii happens with probability Pi/AP_i / A, and then each of the 10 kinds of mana grows by a fixed amount. The sum of all PiP_i can be smaller than AA, so a session can leave every mana unchanged. The result of one session is independent of the results of the other sessions.

Jaeui takes the product of the amounts of all 10 kinds of mana after training ends as the strength of magic. As the last step of the arrangement, Jaeui wants the expected strength of magic after TT training sessions. He handed the work to you, a friend he is not close to. Help Jaeui.

Input

The first line contains three natural numbers TT, NN, AA separated by spaces. (1≤T≤10121 \le T \le 10^{12}, 1≤N≤10 0001 \le N \le 10\,000, 1≤A≤1091 \le A \le 10^9)

Each of the next NN lines contains 11 integers separated by spaces. The first integer is PiP_i, and the remaining 10 are the increase of mana 0, the increase of mana 1, ..., the increase of mana 9, in that order. Every PiP_i is at least 0 and the sum of all PiP_i is at most AA. Each increase is an integer between 0 and 9,999, and at least one of the 10 increases on a line is 1 or more.

Output

Multiplying the expected product of the amounts of all 10 kinds of mana after TT training sessions by ATA^T gives an integer. Print that integer modulo 1,000,000,007 on the first line.

Examples2

  1. Example 1

    Input
    1 2 3
    1 1 1 1 1 0 0 0 0 0 0
    1 0 0 0 0 1 0 0 0 0 0
    
    Expected output
    19
    
  2. Example 2

    Input
    10 3 22
    4 1 4 2 5 0 0 0 1 0 1
    7 2 0 3 2 0 7 1 0 2 0
    9 0 1 0 0 1 0 1 1 7 0
    
    Expected output
    313884062