cho.sh
Notes
Loading...

Word Puzzle

Time limit

2s

Memory limit

128 MB

Problem

A 5 x 5 grid contains one uppercase English letter in each cell. Determine how many words from the fixed dictionary dict.txt can be formed in the grid.

To form a word, choose any starting cell and repeatedly move to one of the 8 neighboring cells, appending each letter you visit. The same cell cannot be used more than once while forming one word. If the same dictionary word can be formed by multiple paths, count it only once.

Input

Five lines are given. Each line contains 5 uppercase English letters separated by spaces, describing the 5 x 5 puzzle.

Output

Print one integer: the total number of dictionary words that can be formed in the puzzle.

Hint

The fixed dictionary file for this problem is included as .