QOJ.ac

QOJ

時間限制: 4 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#18672. Making a Plaster Model

统计

Hyunwoo has a hobby of making various shapes by pouring plaster into a mold and letting it harden. The mold he prepared this time is a rectangular parallelepiped with height $R$, width $C$, and depth $1$.

If the resulting shape is too simple, making plaster models is less fun. So Hyunwoo brought $R \times C$ cylinders with diameter and height $1$. He plans to place all the cylinders inside the mold and then pour plaster into the empty spaces.

When placing the cylinders in the mold, the mold is divided into $R \times C$ unit cubes, and each cylinder must fit exactly into one unit cube. There are three possible orientations for a cylinder: its axis can be horizontal (along the width direction), vertical (along the height direction), or perpendicular to the floor.

After Hyunwoo places all the cylinders, he will pour plaster into the mold, let it harden, and then remove all the cylinders. This produces several separate plaster pieces. For example, if two cylinders are placed with their axes perpendicular to the floor in a rectangular mold with height $1$ and width $2$, a total of $6$ plaster pieces are created.

On the other hand, if the orientation of one cylinder is changed so that its axis is vertical (along the height direction) in the same example, a total of $5$ plaster pieces are created.

Given the arrangement of cylinders in the mold, determine the total number of plaster pieces that will be produced.

Input

The first line contains two integers $R$ and $C$ representing the height and width of the mold, respectively, separated by a space. ($1 \le R, C \le 200$)

The next $R$ lines describe how Hyunwoo places the cylinders in the mold. Each line contains a string of length $C$, and the characters have the following meanings:

  • H: a cylinder whose axis is horizontal (along the width direction)
  • I: a cylinder whose axis is vertical (along the height direction)
  • O: a cylinder whose axis is perpendicular to the floor

Output

Output the number of plaster pieces that are created after the plaster hardens and all cylinders are removed.

Examples

Input 1

1 2
OO

Output 1

6

Input 2

1 2
OI

Output 2

5

Input 3

1 2
OH

Output 3

4

Input 4

2 2
IH
HI

Output 4

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.