import sys from collections import defaultdict def main(): n, k = map(int, sys.stdin.readline().split()) a = list(map(str, sys.stdin.readline().split())) # Create a frequency dictionary for the cards count = defaultdict(int) for s in a: count[s] += 1 # Remove cards that have zero count (though initially all have positive) count = {s: cnt for s, cnt in count.items() if cnt > 0} # Initialize the current list with all possible first steps current = [] for s in count: new_count = count.copy() new_count[s] -= 1 if new_count[s] == 0: del new_count[s] current.append((s, new_count)) # Sort the current list in descending order based on the partial string current.sort(key=lambda x: x[0], reverse=True) # Keep only the top 1000 to manage computational load current = current[:1000] for _ in range(n - 1): next_current = [] for partial_str, remaining in current: # Generate all possible next steps for s in remaining: new_count = remaining.copy() new_count[s] -= 1 if new_count[s] == 0: del new_count[s] new_partial = partial_str + s next_current.append((new_partial, new_count)) # Sort the next_current list in descending order next_current.sort(key=lambda x: x[0], reverse=True) # Keep only the top 1000 current = next_current[:1000] # After processing all steps, collect the top K results current.sort(key=lambda x: x[0], reverse=True) # Output the first K results, each on a new line for i in range(k): print(current[i][0]) if __name__ == "__main__": main()