As usual, Masha recieved an array $$$a$$$ consisting of $$$n$$$ positive integers for her birthday. Every number in the array is greater or equal to $$$1$$$ and less or equal to $$$m$$$. Masha is fond of the number three, so the length of the array is divisble by three.
Masha decided to combine the numbers into triplets: each triplet must be formed of either three equal numbers or three consecutive numbers. In other words, each triplet looks like $$$(x, x, x)$$$ or $$$(x, x+1, x+2)$$$, where $$$x$$$ is an arbitrary positive integer.
Masha wants to play with the gifted array, and she wants to know the number of ways to split the numbers of the array into such triplets. Two ways of splitting are considered distinct if it is not possible to find a one-one mapping between the triplets of the first splitting and the triplets of the second splitting in the way that the number in the corresponding triplets are equal to each other. Since the number of ways to split the array can be large, Masha only wishes to know it modulo $$$10^9+7$$$.
Please help Masha count the number of ways to split the numbers of the gifted array into triplets (modulo $$$10^9+7$$$).
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 5000$$$, $$$1 \le m \le 5000$$$, $$$n=3\cdot k$$$ for some integer $$$k$$$).
The second line contains $$$n$$$ integers $$$a_i$$$ — the numbers of the array ($$$1 \le a_i \le m$$$).
In a single line output one number — the number of ways to split the numbers of the array into triplets modulo $$$10^9+7$$$.
The points for each subtask are earned only if all tests passed for that subtask and all required subtasks.
| |c|c|} Subtask | Points | Additional constraints | Required subtasks | Information about testing |
| 1 | 10 | $$$m \le 3$$$ | first error | |
| 2 | 8 | $$$m \le 4$$$ | 1 | first error |
| 3 | 10 | each number from $$$1$$$ to $$$m$$$ occurs in | ||
| the array no more than two times | first error | |||
| 4 | 12 | the array $$$a$$$ does not contain | ||
| numbers, which are divisible by $$$4$$$ | 1 | first error | ||
| 5 | 29 | $$$n \leqslant 500$$$, $$$m \leqslant 500$$$ | first error | |
| 6 | 31 | — | 1, 2, 3, 4, 5 | first error |
9 43 4 2 4 4 2 3 3 2
2
6 31 2 3 1 2 1
0
There are two ways to split the numbers into triplets in the first sample: {$$$(2, 2, 2)$$$, $$$(3, 3, 3)$$$, $$$(4, 4, 4)$$$} and {$$$(2, 3, 4)$$$, $$$(2, 3, 4)$$$, $$$(2, 3, 4)$$$}.
| Name |
|---|


