Farmer John's cows have created a fun "word finder" puzzle. Their only word of interest is "MOO", which can appear in the word finder horizontally, vertically, or diagonally.
The cows have encrypted the puzzle's contents using a "substitution cipher" that replaces each letter of the alphabet with some different letter. No letter maps to itself, and no two letters map to the same letter.
The cows have lost track of the substitution cipher needed to decrypt their puzzle. Please help them determine the maximum possible number of MOOs that could exist in the puzzle for an appropriate choice of substitution cipher.
Input
Line 1: N and M, the number of rows and columns (both at most 50). The next N lines each contain M characters, describing one row of the encrypted puzzle. Each character is an uppercase letter A..Z.
Output
The maximum possible number of MOOs contained in the puzzle if decrypted with an appropriate substitution cipher.
Example 1
4 6 TAMHGI MMQVWM QMMQSM HBQUMQ
6
Output details: Replacing "Q" with "M" and "M" with "O" reveals 6 MOOs.
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.