Picking up coins P69865


Statement
 

pdf   zip

html

In a n × m board there are golden coins and some traps. There are also some pieces: bishops and knights, which move according to chess rules. The pieces can move as many times as you wish, and can cross any square that does not have a trap, even if occupied by another piece. Coins dissapear when some piece picks them up.

Write a program that prints the total number of coins that can be picked up.

Input

Input includes several cases. Each case consists of a line with n and m, followed by n lines with m characteres each one. A ‘B’ indicates a bishop. A ‘K’ indicates a knight. A ‘T’ indicates a trap. A dot indicates an empty square. A digit indicates a number of golden coins. Both n and m are between 1 and 200.

Output

For each case, print a line with the number of golden coins that can be picked up.

Public test cases
  • Input

    5 7
    8.T...T
    .B1..T.
    T...T..
    ...4.2.
    ..T..9.
    
    7 6
    .K.T..
    .....3
    9..T..
    ..8.T.
    ......
    ...1.K
    .K....
    
    1 1
    .
    
    1 10
    99K9999B99
    
    3 3
    KB.
    0.7
    KB.
    

    Output

    14
    18
    0
    0
    7
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Go