P1671 [USACO05FEB] Rigging the Bovine Election S
Description
The farm is divided into a $5\times 5$ grid, with one cow in each cell, and only two breeds: Holstein (denoted by `H`) and Jersey (denoted by `J`). If one cow is in any of the four cells directly above, below, left, or right of another cow, they are considered connected. The Jersey cows want to form an election district by selecting $7$ connected cows such that the number of Jersey cows in the district is greater than the number of Holsteins.
Write a program to compute the total number of such districts.
Input Format
$5$ lines describing the farm. Each line is a string of length $5$ consisting only of the characters `H` and `J`.
Output Format
Output the total number of valid districts.
Explanation/Hint
Translated by ChatGPT 5