408488: GYM103150 B Arrowing Process
Description
There is a grid of arrows with $$$n$$$ rows and $$$m$$$ columns. A move consists of swapping two adjacent arrows that point at each other. (Two cells are adjacent if they share a side.) What is the maximum number of moves that can be performed?
InputThe input consists of a single test case. The first line of each test case consists of two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 1000$$$) — the number of rows and the number of columns in the grid, respectively.
The next $$$n$$$ lines each contain a string of length $$$m$$$. Each character of this string is one of the characters $$$\texttt{<}$$$, $$$\texttt{>}$$$, $$$\texttt{v}$$$, $$$\texttt{^}$$$, representing an arrow pointing left, right, down, and up, respectively.
OutputOutput a single integer — the maximum number of moves that can be performed.
ExamplesInput3 3 ^v< v^> ><>Output
2Input
6 4 >>vv >>vv >>vv ^^<< ^^<< ^^<<Output
0Note
In the second test case, there is no pair of adjacent cells in the grid that contain arrows pointing at each other, so the answer is $$$0$$$.