#P8296. 3x3 Crossword Puzzle
3x3 Crossword Puzzle
3x3 Crossword Puzzle
You are given six distinct three-letter words. Your task is to arrange them into a 3x3 grid such that the three words in the rows and the three words in the columns are exactly the given words, each used exactly once.
Formally, let the grid be represented as follows:
\[ \begin{matrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{matrix} \]
If we denote the rows as R1, R2, R3 and the columns as C1, C2, C3, then we have:
- R1 = a11a12a13,
- R2 = a21a22a23,
- R3 = a31a32a33,
- C1 = a11a21a31,
- C2 = a12a22a32,
- C3 = a13a23a33.
Your task is to select three of the six words as rows and assign the remaining three words to the columns so that for every column j (1 ≤ j ≤ 3), the jth column word formed by the jth characters of R1, R2, R3 exactly equals one of the remaining words. If there are multiple solutions, you may output any one of them. If no such arrangement exists, output a single line containing "0".
inputFormat
The input consists of a single line with six space-separated three-letter words.
For example:
BAT ORE ACE BOA ARC TEE
outputFormat
If a valid arrangement exists, output the 3x3 grid in three lines, each line representing a row of the grid.
If no valid arrangement is possible, output a single line containing the number 0.
For the sample input above, one possible output is:
BAT ORE ACE
sample
BAT ORE ACE BOA ARC TEE
BAT
ORE
ACE
</p>