Samtris is a game less popular than Tetris. Only bars of size 3×1 appear in it, and the screen is 7 columns wide. A bar appears at the top of the screen and comes down, and you may rotate it before it lands. A bar placed vertically takes three cells stacked in one column, and a bar placed horizontally takes three neighboring columns in one row. A bar stops as soon as the cell right below it is the floor or a cell that already holds another bar. A horizontal bar stops when even one of its three cells is blocked, so empty cells that can never be filled are sometimes left under it. A row that becomes full is never cleared.
The goal is different from Tetris. The game ends once all N cells marked on the screen are filled by bars. Cells that are not marked may be filled as well. Find the smallest number of bars needed to end the game.
The picture below shows the first example.
