Problem list
Log in
#usaco0185 · USACO 2014-2015 US Open Bronze

Moocryption

Silver IV 2.0 s 256 MB

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

Input
4 6
TAMHGI
MMQVWM
QMMQSM
HBQUMQ
Output
6

Output details: Replacing "Q" with "M" and "M" with "O" reveals 6 MOOs.

Source
USACO 2014-2015 US Open Bronze
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code