#P1234. Count 'hehe' Occurrences in a Rectangle

    ID: 14439 Type: Default 1000ms 256MiB

Count 'hehe' Occurrences in a Rectangle

Count 'hehe' Occurrences in a Rectangle

Little A has recently adopted a catchphrase "呵呵". In his playful mood, he presents you with a rectangular grid filled with lowercase letters, and challenges you to count the number of occurrences of the string \(\verb!hehe!\) that appear along a straight line in one of the four cardinal directions: upward, downward, leftward, or rightward.

More formally, you are given an \(n \times m\) grid. You need to count how many contiguous sequences of 4 characters, when read in one of the four directions (up, down, left, or right), form the string "hehe". Note that the check should be performed in the reading order (for instance, when checking upward, start from the bottom cell and move upward).

inputFormat

The first line of input contains two integers \(n\) and \(m\) (the number of rows and columns, respectively).

Then \(n\) lines follow, each containing a string of length \(m\) that represents a row of the grid.

It is guaranteed that all characters are lowercase English letters.

outputFormat

Output a single integer — the total number of occurrences of the string "hehe" found along any of the four directions (up, down, left, or right) in the grid.

sample

3 4
hehe
hehe
hehe
6