The Destruction of the Crystals
Time limit2sMemory limit512 MB
Given a board with crystals and bombs, find the most crystals a chain of bomb explosions can destroy when each bomb blasts its row or column.
Statement
Once upon a time, Zenyk came up with a new magical game for his friends. He brought an board and placed crystals on it. After that, he also placed bombs on the board.
Upon explosion, each bomb destroys all the crystals either in its row or in its column. It also detonates all the bombs in the chosen direction. The direction of the explosion (row or column) for each bomb is chosen by the friends. Different bombs may have different directions.
The objective of the game is to choose the first bomb and the directions to detonate in such a way that the number of destroyed crystals is the largest possible.
Input
The first line contains four integers , , , (, ). They are the dimensions of the board, the number of crystals on it, and the number of bombs.
The next lines describe the board with characters per line:
- "." is an empty cell,
- "k" is a crystal,
- "b" is a bomb.
Output
Print a single integer: the maximum possible number of destroyed crystals.