Back
Close

Manhattan distance

Statement

 Goal

Manhattan isle is known for its streets that intersect at right angles. Thus, if Alice want to meet Bob, she can't move diagonally: she had to follow the streets.
The manhattan distance is defined as the sum of the vertical and the horizontal difference between their position.

In this problem, for simplicity, the Manhattan isle is considered a rectangle. A schematic map of Manhattan is given in input: A represent the position of Alice, B the position of Bob, and all other positions are marked by a point '.'.

If Bob or Alice is not in Manhattan isle, it is impossible to calculate the distance between them, thus print Unknown.
Input
Line 1 : Two integers H and W for height and width of the map.
H next lines : The map described line by line.
Output
The manhattan distance between Alice and Bob.
Constraints
1 ≤ H,W ≤ 100
Example
Input
4 5
.....
.A...
...B.
.....
Output
3

Game modes
Fastest, Shortest, Reverse

Test cases
Test 1 Test
Input
4 5 ..... .A... ...B. .....
Output
3

Validator 1 Validator
Input
4 5 ..... .B... ...A. .....
Output
3

Test 2 Test
Input
2 5 ....A B....
Output
5

Validator 2 Validator
Input
2 5 B.... ....A
Output
5

Test 3 Test
Input
4 4 .... .... ..A. ....
Output
Unknown

Validator 3 Validator
Input
4 4 .... .... ..B. ....
Output
Unknown

Test 4 Test
Input
1 17 ....B......A.....
Output
7

Validator 4 Validator
Input
1 16 ....A.....B.....
Output
6

Test 5 Test
Input
4 5 ..... ..B.. ..... ..A..
Output
2

Validator 5 Validator
Input
4 5 ..B.. ..A.. ..... .....
Output
1

Test 6 Test
Input
3 1 . B .
Output
Unknown

Validator 6 Validator
Input
3 1 A . .
Output
Unknown

Solution language

Solution

Stub generator input