Problem F
Magic Word Square
Cornelius has always enjoyed the fact that his name has nine unique letters. Recently he wrote his name as a $3 \times 3$ grid, but was disappointed to find that none of the rows or columns made words. Now he is wondering: is there a set of eight words such that a $3 \times 3$ grid of letters makes three words across the rows, three words across the columns, and words reading down both diagonals, and with nine different letters in the grid? Your job is to find the answer to his question, for various lists of possible words.
Input
The first line of input is a positive integer $n\leq 500$ representing the number of words in the list. Each of the following $n$ lines contains one of these words, a string of exactly three lowercase letters.
Output
A single integer representing the number of unique $3 \times 3$ grids of letters that can be made with nine different letters in which all three rows (reading left to right), all three columns (reading top to bottom) and both diagonals (reading top to bottom) appear in the given input.
Sample Input 1 | Sample Output 1 |
---|---|
8 mob eau try met oar buy may bat |
1 |
Sample Input 2 | Sample Output 2 |
---|---|
10 abc bcd cde def efg ahi bij cjk dkl elm |
0 |