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 '.' (full stop) represents a blank field.
  • Character '#' represents a fence.
  • 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 appearance 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

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

hide comments
2016-08-03 22:02:01
@iharsh234: If the area is unbounded then the sheep and wolves will be saved as in the case for kvv###. Hence the answer.
2016-07-30 13:33:53
Easy one. :)
AC in 0.00s!
Also try Slick (Code-UCV2013H)
2016-07-12 21:36:32
6 6
######
#kkvv#
######
kvv###
##kkv#
######
ans should be 0 5? is it?toolkit says 3 5
2016-06-28 19:35:30 kaynaat
any of the bfs or dfs will do. doesn't matters.
2016-06-26 22:10:54
easy one:)

Last edit: 2016-06-26 22:11:03
2016-06-16 11:23:29 ABHISHEK BERA
in Java use Scanner class for input... otherwise it will give NZEC ..
2016-06-12 06:42:02
Admin improve the test cases
Output of the case
6 6
######
#kkvv#
######
kv####
##kv##
######
should be 1 4
but a program giving 0 4 also gets accepted
2016-03-29 22:41:39 Shubham Sinha
ac in one go
2016-01-27 17:47:32 Liquid_Science
NZEC -_- repeatedly with java ,i am getting nzec atleast after an year now ,something is wrong here
2016-01-27 14:17:44
My first bfs problem
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.