Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

Ti vengono date $N$ stringhe $S_1, \dots, S_N$, ciascuna composta da lettere minuscole dell'alfabeto inglese e di lunghezza $M$.

Inizialmente, poni $X = S_1$ ed esegui la seguente operazione $N - 1$ volte.

Nella $i$-esima operazione, sia $Y$ la stringa formata concatenando $X$ e $S_{i+1}$ in questo ordine. Quindi, scegli una qualsiasi sottostringa contigua di $Y$ di lunghezza $M$ e sostituisci $X$ con tale sottostringa.

Stampa la stringa lessicograficamente più piccola che può essere il valore finale di $X$.

Input

La prima riga contiene gli interi $N, M$ in questo ordine. ($2 \le N \le 2000, 1 \le M \le 2000$)

Ciascuna delle successive $N$ righe contiene una stringa $S_i$ di lunghezza $M$, composta da lettere minuscole dell'alfabeto inglese.

Output

Stampa la risposta.

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

Nel primo esempio, inizialmente $X = \texttt{cat}$. Nella prima operazione, $Y = \texttt{catcut}$. Se scegliamo la sottostringa contigua dal $2$-o al $4$-o carattere, allora $X = \texttt{atc}$, che è la più piccola possibile in ordine lessicografico.

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.