Problem list
Log in
#coci00603 · COCI 2021/2022 Contest 2

Magneti

Platinum I 1.0 s 512 MB

Little Marko is bored of playing with shady cryptocurrencies such as Shiba Inu or XRC, which is why he decided to play with magnets. He has $n$ different magnets and a board which has $l$ available empty slots in a row, in which the magnets can be placed. Each pair of adjacent slots is exactly one centimeter apart. Each of the $n$ magnets has a radius of activity that is equal to $r_{i}$. This means that it will attract all magnets that are located strictly less than $r_{i}$ centimeters away (regardless of the radius of activity of the other magnet). It is possible that some magnets have the same radius of activity, but they are considered as different magnets. Marko doesn’t like it when the magnets attract each other, so he is interested in the number of ways to place the magnets on the board so that no magnet attracts any other. All of the magnets should be placed on the board, and each empty slot may contain at most one magnet. Two ways of placing the magnets are considered different if there is magnet which is at a different position in the first way than in the second way. As the required number can be quite large, you should output it modulo $10^{9} + 7$.

Input

The first line contains positive integers $n$ and $l$, the number of magnets and the number of empty slots. The second line contains $n$ positive integers $r_{i}$ ($1 \le r_{i} \le l$), the radii of activity of the $n$ magnets.

Output

Print the required number of ways to place the magnets on the board so that no magnet attracts any other, modulo $10^{9} + 7$.

Example 1

Input
1 10
10
Output
10

Example 2

Input
4 4
1 1 1 1
Output
24

Example 3

Input
3 4
1 2 1
Output
4

Clarification of the second example: All permutations of the magnets are valid because no two magnets can attract each other. Clarification of the third example: If we denote the magnets with 1, 2 and 3, and an empty slot with _, the possible arrangements of magnets are 13_2, 31_2, 2_13 and 2_31.

Source
COCI 2021/2022 Contest 2
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code