5455: Crossword填字游戏

内存限制:256 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:3 通过:3

题目描述

C. Crossword
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya trains to compose crossword puzzles. He can only compose crosswords of a very simple type so far. All of them consist of exactly six words; the words can be read only from top to bottom vertically and from the left to the right horizontally. The words are arranged in the form of a rectangular "eight" or infinity sign, not necessarily symmetrical.
The top-left corner of the crossword coincides with the top-left corner of the rectangle. The same thing is correct for the right-bottom corners. The crossword can't degrade, i.e. it always has exactly four blank areas, two of which are surrounded by letters. Look into the output for the samples for clarification.
Help Vasya − compose a crossword of the described type using the given six words. It is allowed to use the words in any order.

瓦夏训练创作填字游戏。到目前为止,他只能创作非常简单类型的填字游戏。它们都由六个字组成;这些单词只能从上到下垂直阅读,从左到右水平阅读。这些单词以矩形“八”或无穷大符号的形式排列,不一定对称。

填字游戏的左上角与矩形的左上角重合。右下角也是如此。填字游戏不能降级,即它总是有四个空白区域,其中两个被字母包围。查看示例的输出以进行澄清。

帮助 Vasya — 使用给定的六个单词编写描述类型的填字游戏。允许按任何顺序使用这些单词。


Input
Six lines contain the given words. Every word consists of no more than 30 and no less than 3 uppercase Latin letters.
Output
If it is impossible to solve the problem, print Impossible. Otherwise, print the sought crossword. All the empty squares should be marked as dots.
If there can be several solutions to that problem, print the lexicographically minimum one. I.e. the solution where the first line is less than the first line of other solutions should be printed. If the two lines are equal, compare the second lines and so on. The lexicographical comparison of lines is realized by the < operator in the modern programming languages.
Examples
Input
NOD
BAA
YARD
AIRWAY
NEWTON
BURN
Output
BAA...
U.I...
R.R...
NEWTON
..A..O
..YARD
Input
AAA
AAA
AAAAA
AAA
AAA
AAAAA
Output
AAA..
A.A..
AAAAA
..A.A
..AAA
Input
PTC
JYNYFDSGI
ZGPPC
IXEJNDOP
JJFS
SSXXQOFGJUZ
Output
JJFS....
Y..S....
N..X....
Y..X....
F..Q....
D..O....
S..F....
G..G....
IXEJNDOP
...U...T
...ZGPPC

输入样例 复制


输出样例 复制