#P1178F1. Short Colorful Strip
Short Colorful Strip
No submission language available for this problem.
Description
This is the first subtask of problem F. The only differences between this and the second subtask are the constraints on the value of and the time limit. You need to solve both subtasks in order to hack this one.
There are distinct colours in the universe, numbered through . There is a strip of paper centimetres long initially painted with colour .
Alice took a brush and painted the strip using the following process. For each from to , in this order, she picks two integers , such that the segment is currently painted with a single colour, and repaints it with colour .
Alice chose the segments in such a way that each centimetre is now painted in some colour other than . Formally, the segment is painted with colour (). Every colour other than is visible on the strip.
Count the number of different pairs of sequences , that result in this configuration.
Since this number may be large, output it modulo .
The first line contains a two integers , (, ) — the number of colours excluding the colour and the length of the paper, respectively.
The second line contains space separated integers () — the colour visible on the segment after the process ends. It is guaranteed that for all between and there is an index such that .
Note that since in this subtask , this means that is a permutation of integers through .
Output a single integer — the number of ways Alice can perform the painting, modulo .
Input
The first line contains a two integers , (, ) — the number of colours excluding the colour and the length of the paper, respectively.
The second line contains space separated integers () — the colour visible on the segment after the process ends. It is guaranteed that for all between and there is an index such that .
Note that since in this subtask , this means that is a permutation of integers through .
Output
Output a single integer — the number of ways Alice can perform the painting, modulo .
Samples
Note
In the first example, there are ways, all depicted in the figure below. Here, is white, is red, is green and is blue.
Below is an example of a painting process that is not valid, as in the second step the segment 1 3 is not single colour, and thus may not be repainted with colour .