KOZE - Sheep


Mirko has a herd of sheep, surrounded by fences backyard. While he was asleep, wolves have sneaked into the fenced area and attacked the sheep.

Backyard is of a rectangular shape, and consists of fields arranged in rows and columns.

Character '.' (fullstop) represents a blank field.

Character '#' represents a fance.

Character 'k' represents a sheep.

Character 'v' represents a wolf.

 

Two fields belong to the same sector if we can move from the field A to the field B without going over the fence, by making only horizontal and vertical steps (we cannot move diagonally).

If we can escape from field A from the backyard, that field does not belong to any sector.

Luckily, Mirko taught his sheep Kung-Fu skills, and they can defend themselves against wolves only if they outnumber the wolves in that sector. When there are more sheep in the sector than wolves, all wolves die without sheep casualties. Otherwise all sheep perish and wolves are unharmed. If a field doesn't belong in any sector, sheep will flee and wolfs will be left without a prey, so every animal survives.

 

Write a program that will determine how many sheep and wolves will survive this bloody night.

 

Input

Integers N and M, number of rows and columns which represent Mirko's backyard.

In every of the N lines, there are M characters representing the appearence of Mirko's backyard - positions of the fences, wolves and sheep.

 

Constraints

3 <= N, M <= 250

 

Output

In the first and the only line, print the number of sheep and wolves that will survive.

 

Example

Input:
8 8  
.######.  
#..k...#  
#.####.#  
#.#v.#.#  
#.#.k#k#  
#k.##..#  
#.v..v.#  
.######. Output: 3 1

hide comments
Shikhar Kunal: 2015-12-26 14:36:10

take inputs as strings. Cost me one WA.

sarvagya: 2015-09-17 12:38:27

AC in one go! :D

utkarsh agarwal: 2015-07-02 23:51:12

very weak test cases!

rk: 2015-06-27 22:28:00

learnt new something today.

Tim Wargon: 2015-05-27 20:40:38

Use scanf("%s",...)... Do not use getchar() to input characters... seems some test case generating trouble there.

pingal tirkey: 2015-05-25 12:37:23

Nice question, Learnt something new.

getting started: 2015-03-10 14:15:26

" if sheep can escape backyard !" your test cases are missing the case !!
nevertheless !! my 50 th.

Bharath Reddy: 2014-09-26 13:21:07

After solving this, try MAKEMAZE and NATALIAG also

Archit Jain: 2014-07-19 13:58:05

nice and easy

Petar Bosnjak: 2014-04-07 23:33:15

Everyone from Croatia please be careful ,original task from our competition had 'o' char for a goat and here 'k' is for a goat , this costed me 5-6 WA until i noticed it , be aware!!

Last edit: 2014-07-01 16:10:23

Added by:Erik Lončarek
Date:2012-12-02
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:Croatian Regionals 2005