This page is still under construction.

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

Block Stacking

Time limit1sMemory limit32 MB

Summary
Count distinct front-view colorings of supported stacks of width W and height at most H built from unlimited blocks of widths 1 to K, modulo 1e9+7.
Level

Medium7 of 10

Topics
Dynamic programming, Combinatorics, Prefix sum
Solved
No attempts yet

Problem

Yeonggeul plays with blocks. He owns KK kinds of blocks. Every block has height 1, and the widths are 1 through KK. Blocks of the same width always have the same color, but two blocks of different widths may still have the same color. Every kind is available without limit. For example, if K=3K=3 and the three blocks have three different colors, he can use as many of the following three blocks as he wants.

Yeonggeul stacks these blocks on a floor block of width WW. A tall stack is awkward to play with, so he keeps the height at most HH. The picture below shows an example with W=6W=6.

A block must line up exactly with the cells, and no empty space may be left under a placed block. The left picture follows the rules and the right picture does not.

In the left picture every block follows the rules and the height is 4. In the right picture the leftmost red block does not line up with the cells. The middle of the blue block has empty space under it, and the rightmost red block also has empty space under it. The right picture is therefore not a correct stacking.

Count the stackings that follow the rules. Two stackings that show the same color in every cell when seen from the front count as one. Stacking nothing at all counts as one case.

Input

The first line has three integers separated by spaces: the number of block kinds KK (1≤K≤3001 \le K \le 300), the width of the floor block WW, and the largest allowed height HH (1≤W,H≤3001 \le W, H \le 300).

The second line has KK integers. The ii-th number CiC_i (1≤Ci≤K1 \le C_i \le K) is the color of the block of width ii.

Output

Print the number of stackings that follow the rules, modulo 1,000,000,007.

Examples4

  1. Example 1

    Input
    2 2 2
    1 1
    
    Expected output
    9
    
  2. Example 2

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

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

    Input
    1 5 1
    1
    
    Expected output
    32