#abc366b. B - Vertical Writing

B - Vertical Writing

Score : 200200 points

问题陈述

你得到了一段水平书写的文本。将其转换为垂直书写,用 * 填充空格。

你得到了 NN 个字符串 S1,S2,,SNS_1, S_2, \dots, S_N,它们由小写英文字母组成。设 MM 为这些字符串的最大长度。

打印出 MM 个字符串 T1,T2,,TMT_1, T_2, \dots, T_M,满足以下条件:

  • 每个 TiT_i 由小写英文字母和 * 组成。
  • 每个 TiT_i 不以 * 结尾。
  • 对于每个 1iN1 \leq i \leq N,以下条件成立:
    • 对于每个 1jSi1 \leq j \leq |S_i|TjT_j 的第 (Ni+1)(N-i+1) 个字符存在,并且按顺序连接 T1,T2,,TSiT_1, T_2, \dots, T_{|S_i|} 的第 (Ni+1)(N-i+1) 个字符等于 SiS_i
    • 对于每个 Si+1jM|S_i| + 1 \leq j \leq MTjT_j 的第 (Ni+1)(N-i+1) 个字符要么不存在,要么是 *

在这里,Si|S_i| 表示字符串 SiS_i 的长度。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given a horizontally written text. Convert it to vertical writing, filling spaces with *.

You are given NN strings S1,S2,,SNS_1, S_2, \dots, S_N consisting of lowercase English letters. Let MM be the maximum length of these strings.

Print MM strings T1,T2,,TMT_1, T_2, \dots, T_M that satisfy the following conditions:

  • Each TiT_i consists of lowercase English letters and *.
  • Each TiT_i does not end with *.
  • For each 1iN1 \leq i \leq N, the following holds:
    • For each 1jSi1 \leq j \leq |S_i|, the (Ni+1)(N-i+1)-th character of TjT_j exists, and the concatenation of the (Ni+1)(N-i+1)-th characters of T1,T2,,TSiT_1, T_2, \dots, T_{|S_i|} in this order equals SiS_i.
    • For each Si+1jM|S_i| + 1 \leq j \leq M, the (Ni+1)(N-i+1)-th character of TjT_j either does not exist or is *.

Here, Si|S_i| denotes the length of the string SiS_i.

Constraints

  • NN is an integer between 11 and 100100, inclusive.
  • Each SiS_i is a string of lowercase English letters with length between 11 and 100100, inclusive.

Input

The input is given from Standard Input in the following format:

NN

S1S_1

S2S_2

\vdots

SNS_N

Output

Print the answer in the following format:

T1T_1

T2T_2

\vdots

TMT_M

Sample Input 1

3
abc
de
fghi

Sample Output 1

fda
geb
h*c
i

Placing * as the 2nd character of T3T_3 puts the c in the correct position. On the other hand, placing * as the 2nd and 3rd characters of T4T_4 would make T4T_4 end with *, which violates the condition.

Sample Input 2

3
atcoder
beginner
contest

Sample Output 2

cba
oet
ngc
tio
end
sne
ter
*r