Time limit
2s
Memory limit
128 MB
Donghyuk plays a game similar to Tetris. The game field is a rectangle 3 cells wide and 300 cells tall, and the seven available tiles are shown below.

Each tile may be rotated left or right by 90 degrees. Rotations by 180 and 270 degrees are also allowed, but reflection is not allowed. Therefore tile 2 cannot be turned into tile 3 by rotation.
The field is empty at first. When the game starts, tiles fall from top to bottom in the given order. Before each tile starts falling, you may choose its rotation and horizontal position. After that choice is made, the tile cannot move or rotate while falling. Tiles may not overlap, and no part of a tile may leave the field.
If tile 1 is rotated, its width becomes 4 cells, so that rotated position cannot be placed in the 3-cell-wide field. A width-2 orientation of tile 2 may be placed in columns 1-2 or columns 2-3.
Once a tile has fallen and been stacked, it cannot be moved or rotated after the next tile starts falling.
Stack all tiles in the given order so that the final height is as small as possible. The height K is the smallest number such that every occupied cell in all three columns lies within the lowest K rows.
The first line contains the number of tiles N. (1 ≤ N ≤ 100)
Each of the next N lines contains one integer, the number of the tile that falls at that position in the order. Each number is between 1 and 7, inclusive.
Print the minimum possible final height K on the first line.