Under construction

Still being built. Things may change

Skewers

Interview

Time limit1sMemory limit1024 MB

Summary
Given a grid of meat, scallion, and mushroom cells, find the most skewers that each take one adjacent meat and scallion in a line with a mushroom at one end.
Level

Medium6 of 10

Topics
Graph, Matrix
Solved
No attempts yet

Problem

Sejong is threading ingredients onto skewers to roast over a campfire during a camping trip. His mother asked him to put one meat, one scallion, and one mushroom on each skewer so the family eats a balanced mix. Sejong dislikes mushrooms, so he wants skewers with only meat and scallion. He plans to thread one meat and one scallion, then pretend to add a mushroom at the end and roast the skewer without actually adding one.

The ingredients are laid out in an N×MN\times M grid. Each cell holds meat, scallion, or mushroom. To make a skewer, choose three cells in a row, column, or diagonal that are consecutive, and thread the ingredients in that order. The mushroom must be at an end of the skewer, because it is only a pretend addition. A meat or scallion cell cannot go onto more than one skewer, but one mushroom can be used for several skewers.

Input

The first line contains two integers NN and MM, separated by a space. (1≤N,M≤100)(1\le N,M\le 100)

From the second line onward, NN lines each contain a string of length MM. The jj-th character of the ii-th string is the ingredient in row ii, column jj. Each string consists only of S, G, and M, which stand for meat, scallion, and mushroom.

Output

Print the maximum number of mushroom-free skewers Sejong can make.

Examples1

  1. Example 1

    Input
    5 3
    MSG
    SGM
    GMS
    SMG
    MGS
    
    Expected output
    5