Universal Cup Judging System

Universal Cup

时间限制: 2.0 s 内存限制: 1024 MB 总分: 100 可 Hack ✓
统计

Сізге кіші ағылшын әріптерінен тұратын және әрқайсысының ұзындығы $M$ болатын $N$ жол $S_1, \dots, S_N$ берілген.

Бастапқыда $X = S_1$ болсын, және келесі амалды $N - 1$ рет орындаңыз.

$i$-ші амалда $Y$ — осы ретпен $X$ пен $S_{i+1}$ жолдарын біріктіру арқылы алынған жол болсын. Содан кейін $Y$ жолының ұзындығы $M$ болатын кез келген іргелес ішкі жолын таңдап, $X$-ті сол ішкі жолмен алмастырыңыз.

$X$-тің соңғы мәні бола алатын лексикографиялық тұрғыдан ең кіші жолды шығарыңыз.

Input

Бірінші жолда осы ретпен $N, M$ бүтін сандары берілген. ($2 \le N \le 2000, 1 \le M \le 2000$)

Келесі $N$ жолдың әрқайсысында кіші ағылшын әріптерінен тұратын ұзындығы $M$ болатын $S_i$ жолы берілген.

Output

Жауапты шығарыңыз.

Examples

Input 1

2 3
cat
cut

Output 1

atc

Input 2

2 1
a
b

Output 2

a

Input 3

3 8
jastaway
tatesoto
soryuusi

Output 3

asoryuus

Note

Бірінші мысалда бастапқыда $X = \texttt{cat}$. Бірінші амалда $Y = \texttt{catcut}$. Егер $2$-ші таңбадан $4$-ші таңбаға дейінгі іргелес ішкі жолды таңдасақ, онда $X = \texttt{atc}$ болады, бұл — лексикографиялық тұрғыдан мүмкін болатын ең кіші жол.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1629EditorialOpenO(n^3 log \sum /w) 做法tzl_Dedicatus545View
#1523EditorialOpen题解jianglyView
#1506EditorialOpenO(n^3) 做法incentView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.