QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100

#3742. Emoticon

统计

The following 4 patterns are considered "cute faces" (blank spaces can be any character; vertical bars are separators for display purposes and have no actual meaning):

^ ^ |  ^  | <  |  >
 v  | v v |  > | <
    |     | <  |  >

Given an $n \times m$ character matrix, Bobo wants to find the maximum number of non-overlapping cute faces. Non-overlapping means that each character belongs to at most one cute face.

Input

The input contains multiple test cases. Process until the end of the file.

The first line of each test case contains two integers $n$ and $m$.

The next $n$ lines, the $i$-th line contains a string of length $m$, representing the $i$-th row of the character matrix.

Output

For each test case, output a single integer representing the maximum number of non-overlapping cute faces.

Constraints

  • $1 \leq n, m \leq 1000$
  • The matrix contains only the 4 characters ^, v, <, >.
  • The sum of $n \times m$ does not exceed $2 \times 10^6$.

Examples

Input 1

2 4
^^^^
>vv<
2 4
vvvv
>^^<
4 2
v>
<>
<>
^>
3 4
^>^>
<v>v
>>>>

Output 1

2
0
2
2

Note

In the first example, there are 2 of the first type of cute face.

In the fourth example, there are 3 cute faces in total, but the maximum number of non-overlapping cute faces is 2.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.