Stick Game
Time limit1sMemory limit512 MB
Place non-overlapping horizontal sticks of given lengths on a grid with obstacles; find the winner under optimal play.
- Level
Medium6 of 10
- Topics
- Game theory, Implementation
- Solved
- No attempts yet
Problem
Yeongseon and Hyobin are running this contest. There are only two of them, so they work as the staff as well. The contest is small and, unlike a real one, nobody has to tie balloons to chairs, so as long as nothing goes wrong they have almost nothing to do.
They prepared a game to pass the time during the contest. It is called the stick game, and the rules are these.
- There is an grid board.
- Some cells hold an obstacle, and a stick may not cover such a cell.
- For each given length there is an unlimited supply of sticks.
- The two players take turns. On a turn a player picks one stick and places it anywhere on the board.
- The player who has no place left to put a stick loses.
- Sticks may not overlap, and they may not be rotated.
Because a stick may not be rotated, a stick of length covers consecutive empty cells inside one row.

The picture shows legal placements.
Both players have plenty of time to think, so both always play optimally. Yeongseon always moves first. Given the board, print the id of the player who wins.
Input
The first line contains and ().
Each of the next lines contains a string of length describing one row of the board. An empty cell is . and an obstacle is @.
The next line contains the number of stick kinds ().
The next line contains integers in ascending order (), where is the length of the -th kind of stick.
Output
Print nein if Yeongseon wins, and hyo123bin if Hyobin wins.