409440: GYM103561 E Changing Names

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Changing Namestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

admin'OR1=1 is tired of celebrating Singles Awareness Day – not once have they ever had success with dating! This year, things are going to be different. admin'OR1=1 is going to change their name!

The reason is simple: admin'OR1=1 is simply not a name that is compatible with many other names. And as we all know, name compatibility is the key to successful relationships. The compatibility score $$$t$$$ of two names, $$$s_1$$$ and $$$s_2$$$ is defined as the sum of minimum occurrences of each letter. In other words, $$$$$$t = \sum_{a \in A} min(c_{s_1,a}, c_{s_2,a})$$$$$$ where $$$A$$$ denotes the set of letters, and $$$c_{s,a}$$$ denotes the number of times $$$a$$$ appears in $$$s$$$.

admin'OR1=1 has already compiled the names of $$$n$$$ people they plan on asking out (after the name change). In order to maximize their chances, admin'OR1=1 wants to maximize the total sum of compatability scores between their new name and all of the $$$n$$$ names. However, due to governmental restrictions, their new name can only be $$$m$$$ characters long. Can you help admin'OR1=1 pick a new name?

Input

The first line contains two integers, $$$n$$$ and $$$m$$$ ($$$1 \leq n,m \leq 1000$$$), representing the number of names and the maximum length of admin'OR1=1's new name.

Then, $$$n$$$ lines follow, where the $$$i$$$-th line contains $$$s_i$$$, the name of the $$$i$$$-th person. Names will only consist of lowercase Latin letters.

The sum of lengths of all $$$s_i$$$ will be no more than $$$1000$$$.

Output

Output a string consisting only of lowercase Latin characters of length at most $$$m$$$, which maximizes the sum of compatibility scores with all given names.

If there are multiple names that maximize the compatibility, output any of them.

ExamplesInput
3 5
alice
bob
charlie
Output
alice
Input
3 3
umar
winston
lulu
Output
uwu

加入题单

算法标签: