#P6480. [CRCI2006-2007] TETRIS
[CRCI2006-2007] TETRIS
Problem Description
There are the following seven types of Tetris blocks:

When using them, you may rotate them by degrees, degrees, degrees, or not rotate them.
Now there is a grid with columns and unlimited height. In the -th column, the bottom cells are already filled with blocks (that is, the lowest cells have been placed previously). In each column, only a continuous segment of cells at the bottom is filled.
The next falling block is block number . Please compute how many placements after it lands satisfy that there is no cell which is empty but has a filled cell directly above it. In other words, compute how many placements satisfy that in every column, only a continuous segment of cells at the bottom is filled.
Two placements are considered different if and only if there exists a cell that is filled in one placement but not filled in the other.
Input Format
The first line contains two integers, representing the number of columns and the index of the next falling block.
The second line contains integers. The -th integer means that in the -th column, only the bottom continuous cells are filled.
Output Format
Output one integer in one line, representing the answer.
6 5
2 1 1 1 0 1
5
5 1
0 0 0 0 0
7
9 4
4 3 5 4 6 5 7 6 6
1
Hint
Explanation for Sample 1
Among the six figures below, the upper-left figure is the initial grid, and the other five figures are the five valid cases.

Constraints
For all test points, it is guaranteed that:
- , .
- .
Note
This problem is translated from COCI2006-2007 Regional Competition T2 TETRIS. Translation credit: @一扶苏一。
Translated by ChatGPT 5