Walking Machine
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Given a maze of size , where upper left corner is and lower right corner is . For each cell , there is exactly one character on it, denoting the moving restriction:

* If , you can only go up from this cell, specifically go from to

* If , you can only go left from this cell, specifically go from to

* If , you can only go down from this cell, specifically go from to

* If , you can only go right from this cell, specifically go from to

We say one is out if or or or holds, now you should determine the number of cells that one can be out if start walking on it.

输入描述:

The first line contains two integers , denoting the size of the maze.

Following lines each contains a string of length , where the -th character in -th line denotes the character on cell .

输出描述:

Only one line containing one integer, denoting the number of cells that can make one out.
示例1

输入

复制
3 4
DDSD
AWAA
WASD

输出

复制
6

说明

The 6 cells are (1, 4), (2, 1), (3, 1), (3, 2), (3, 3), (3, 4)_{} respectively.