Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Game of Strings

By techboy · Limits 2s, 512 MB

Redoan is very fond of strings. He wants to go on a spree of solving string problems. His own teammate Nafis is very jealous of him. He wants to stop the streak of "Accepted" in Redoan's string problem solving. So he decides to take help from Pizon. Pizon thought for whole night and then an idea came to his mind. He went to Redoan and gave him the following problem.
There are N strings given to Redoan. They have at most M length each. Redoan has to make another string joining K distinct strings from the given list. If there are not K unique strings available then he can join as many as possible. Of course those also have to be unique.
Nafis is still not convinced. He wants to make this problem harder. So he added another constraint. Redoan must pick lexicographically smaller strings first.

Input

First line contains N.
N strings follow.
Then K is given.
1 <= N <= 1000000,
K <= N,
M <= 4.
Each of the number mentioned earlier will be positive.

Output

Print one line containing the resulting string.

Sample

InputOutput
6
babc
ab
b
a
baaa
cbca
4
aabbbaaa

Discussion

Statistics


92% Solution Ratio

koushikEarliest, Jan '17

md_jakariyaFastest, 0.2s

rajdipsahaLightest, 16 MB

Being_GoromShortest, 210B

Submit

Login to submit

Toph uses cookies. By continuing you agree to our Cookie Policy.