P29825 [洛谷] [COCI2012-2013#2] KRIZALJKA
普及+
题目描述

Problem Background

This problem's score is set according to the original COCI contest, with a maximum score of $80$.

Problem Description

Do you enjoy playing crossword puzzles? If so, you might be familiar with the traditional beginner's game, as shown below:


  • Horizontally:
  1. Device used to cool computers

  2. Solid state of water

  3. Used to obtain

  • Vertically:
  1. Small, soft, and sweet fruit

  2. Strong paper card

  3. Fisherman's tool


Given six three-letter words, you need to place them in a $3\times 3$ grid such that these words appear both horizontally and vertically.

Input Format

The input consists of 6 lines, each containing a three-letter uppercase word. The words are guaranteed to be given in lexicographical order.

Output Format

If no solution exists, output $0$. Otherwise, output the letter matrix in a 3x3 format.

If there are multiple solutions, output the one with the smallest lexicographical order when the nine characters formed by concatenating the first and last characters of each row are considered.

Sample Input and Output

Sample Input #1

ANA
ANA
DAR
DAR
RAD
RAD

Sample Output #1

DAR
ANA
RAD

Sample Input #2

EVO
HEP
HIR
IVA
PAD
ROD

Sample Output #2

HEP
IVA
ROD

Sample Input #3

AKO
CES
DOC
DON
ESI
KES

Sample Output #3

0
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
ANA ANA DAR DAR RAD RAD
样例输出
DAR ANA RAD