#P1671. Seven-Cow Election

    ID: 14957 Type: Default 1000ms 256MiB

Seven-Cow Election

Seven-Cow Election

The farm is divided into a 5×5 grid. In each cell there is one cow, which is either a Holstein (denoted by H) or a Jesse cow (denoted by J). Two cells are considered adjacent (connected) if they share a side (up, down, left, or right).

The Jesse cows are about to hold an election. They want to choose a contiguous group of exactly 7 cells (i.e. any two cells in this group are connected through a sequence of adjacent cells within the group) so that in the chosen group, the number of Jesse cows is strictly greater than the number of Holsteins. In other words, if we denote by \(J\) the number of Jesse cows and by \(H\) the number of Holstein cows in the group, then the group is valid if:

[ J > H \quad\text{.} ]

Your task is to count the total number of valid ways to select such a group of 7 cells.

Note: The grid cells are numbered implicitly (each cell given by its row and column) and two cells are connected if one is immediately above, below, left, or right of the other.

inputFormat

The input consists of 5 lines, each line containing exactly 5 characters. Each character is either H or J, representing Holstein and Jesse cows respectively.

outputFormat

Output a single integer which is the total number of valid ways to select 7 connected cells such that the number of Jesse cows is greater than the number of Holsteins.

sample

JJJJJ
JJJJJ
JJJJJ
JJJJJ
JJJJJ
1