Under construction

Still being built. Things may change

MBTI

Interview

Time limit1sMemory limit1024 MB

Summary
Count how many times each of the 16 four-letter MBTI type codes appears in any of the eight directions on an N by M letter grid.
Level

Easy3 of 10

Topics
Matrix, String matching, Brute force
Solved
No attempts yet

Problem

The Myers-Briggs Type Indicator (MBTI) is a self-report questionnaire that describes psychological preferences in how people perceive the world and make decisions.

MBTI divides personality into 16 types. Each type is written with 4 letters.

  • The first letter is extroversion (E) or introversion (I), which shows how a person gains energy.
  • The second letter is intuition (N) or sensation (S), which shows how a person understands and interprets new information.
  • The third letter is feeling (F) or thinking (T), which shows how a person makes decisions.
  • The last letter is perception (P) or judgment (J), which shows how a person organizes their time and lifestyle.

All 16 types are formed by choosing one letter from each pair, for example ENFP, ISTP, or ENTJ.

You find an alphabet board on the way to the lab. You are obsessed with MBTI, so you want to count how many MBTI types appear on the board.

If four letters in a horizontal, vertical, or diagonal line form one of the MBTI types, shout "MBTI!". The direction of reading does not matter. The word can be read from bottom right to top left, from left to right, and so on. A type that was already found still earns a shout if it appears at a different location or in a different direction.

Find every MBTI type on the board and shout "MBTI!" for each one.

Input

The first line contains two integers NN and MM (1≤N,M≤2001 \leq N, M \leq 200), the number of rows and columns of the board.

The next NN lines each contain MM uppercase letters, which form the alphabet board.

Output

Print one line with the total number of times "MBTI!" is shouted. This equals the total number of occurrences of the 16 MBTI types on the board.

Hint

Figure 1.Figure 2.Figure 3.

In Figure 1, ENFP is found along the diagonal from (0,3) to (3,0).

In Figure 2, INFP is found along the diagonal from (3,3) to (0,0), and ISTJ is found along the horizontal line from (3,3) to (3,0).

In Figure 3, ISFJ is found along the diagonal from (0,0) to (3,3). A second ISFJ is found along the horizontal line from (1,0) to (1,3), and ESTJ is found along the vertical line from (0,1) to (3,1).

Examples2

  1. Example 1

    Input
    5 5
    JICDE
    TFSFN
    SESTF
    EWERP
    ABCDE
    
    Expected output
    3
    
  2. Example 2

    Input
    5 4
    ENFP
    ENFP
    ENFP
    ENFP
    ENFP
    
    Expected output
    9