Tetris
Anton recently discovered a game called "Tetris++", which is similar to the classic Tetris but with some unique twists.
**Rules of "Tetris++":**
The game is played on a grid with a height of N and a width of M squares. At the bottom of this grid, there may be squares of various sizes. At the start of the game, a piece begins to fall from the top left corner. This piece is a vertical rectangle measuring 3×1, with each square painted a specific color.
When the piece appears on the board, the player can immediately move it any number of cells to the right and can also cyclically shift the colors of the piece upwards any number of times. The piece then falls until it lands on another square or reaches the bottom of the grid.
Once the piece has landed, the game gets interesting: any sequence of at least 3 squares of the same color, aligned vertically, horizontally, or diagonally, will disappear instantly. All colored squares above the vanished ones will fall down simultaneously. If new sequences of 3 or more squares of the same color are formed after this, they will also disappear, and this process continues.
The objective is to minimize the number of colored squares left on the board.
Help Anton figure out how many positions to move the falling piece to the right and how many times to cyclically shift it upwards to leave as few squares as possible on the board.
**Input**
The first line contains the numbers N and M, separated by a space (4 ≤ N ≤ 26, 1 ≤ M ≤ 15). Each of the next N lines contains M numbers, separated by spaces, representing the initial state of the playing field (from top to bottom). Numbers from 1 to 9 denote the color of the corresponding square, and the number 0 indicates no colored square is present at that location. The last three lines contain three numbers, representing the colors (from 1 to 9) of the squares (from top to bottom) of the falling piece.
It is guaranteed that the top four rows of the playing field do not contain any colored squares.
**Output**
You need to output 3 numbers, separated by spaces. The first number is the number of units to move the piece to the right (from 0 to M-1). The second number is the number of cyclic shifts required (from 0 to 2). The third is the total number of squares that disappeared as a result of the piece's fall. If there are multiple optimal solutions, choose the one with the fewest rightward movements of the piece, and if there are still multiple solutions, choose the one with the fewest movements and shifts.