Word Square

Special Judge Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Problem Description

      Some sets of n words of length n have a nice property — it is possible to arrange them in the n × n grid so that this set of words is read both vertically and horizontally.
      An example of such set is { “DATE”, “FIND”, “IDEA”, “NEXT” }. You can arrange them in the following way:

      Note that you can find each word exactly once as a horizonatal word, and as a vertical word. Such squares are called word squares, the largest known word square is 10 × 10.
      Another example of the 4 × 4 word square is:

      You are given 2n words such that it is possible to construct two different n × n word squares from them. You task is to divide the words into two groups of n words and construct the words square from each group.
      You are guaranteed that all words are the English words (however, some of them are really rare ones, human names, or some extremely special terms).

Input

      The first line of the input file contains n (2 ≤ n ≤ 10). The following 2n lines contain n-letter word each, words consist of capital English letters.

Output

      Output two n × n word squares constructed from the given words. Separate squares by a blank line.

Sample Input

4
ARTS
BEST
CRAB
DATE
FIND
IDEA
NEXT
RARE

Sample Output

FIND
IDEA
NEXT
DATE

CRAB
RARE
ARTS
BEST

Hint

注意格式

Source

Andrew Stankevich Contest 16

Manager

Information
Solved Number71
Submit Number176
Problem Tags
No tag edit access
温馨提示:AC后可以编辑标签哦. ^-^
Login
LoginCancel