Under construction

Still being built. Things may change

Computer Dialogue

Time limit1sMemory limit128 MB

Summary
Given file names split into name and extension parts, simulate the alternating 'I don't know' messages between two clients and list files still possible after M messages.
Level

Medium7 of 10

Topics
Simulation, Hash map, Implementation, String
Solved
No attempts yet

Problem

Three computers are connected by a network: one is a server and the other two are clients. The server stores several files, each with a distinct full name. A full name has two parts, a name and an extension, written as name.extension. Both clients know the full names of every file on the server.

The server chooses one file and sends the name part of that file to one client and the extension part to the other client. The two clients then try to work out which file was chosen (that is, its full name), but they may communicate only in a very restricted way. They take turns exchanging messages, and the only thing a client may ever say is "I don't know the full file name." A client sends this message only when it still cannot determine the full name. The client that received the name part always waits for the other client (the one holding the extension) to speak first. The exchange continues until one client learns the full name or the two of them give up.

Suppose you know every full file name on the server and you overhear the conversation. Given the number of messages exchanged, determine which files could still have been the one chosen by the server. Such files are called candidate files.

Input

The first line contains two integers NN and MM separated by a space. NN (1≤N≤10001 \le N \le 1000) is the number of files on the server, and MM (1≤M≤1001 \le M \le 100) is the number of "I don't know" messages the clients exchanged.

Each of the next NN lines contains one full file name in MS-DOS 8.3 style name.extension, where both the name and the extension consist only of uppercase letters (A–Z) and digits (0–9). The name has between 1 and 8 characters; the extension has at most 3 characters and may be empty. If the extension is empty, the separating dot may be omitted (so both FILEID. and LICENCE are valid). Every full file name appears at most once.

Output

On the first line, print the number of candidate files (print 0 if there are none). Then print the full name of each candidate file on its own line. The candidates must appear in the same order and with exactly the same spelling as in the input: if the separating dot was omitted in the input, omit it in the output too, and vice versa. Do not print any file more than once.

Examples1

  1. Example 1

    Input
    19 2
    LICENCE.TMP
    WIN32.LOG
    FILEID.
    PSTOTEXT.TXT
    GSVIEW32.EXE
    GSVIEW32.ICO
    GSVIEWDE.HLP
    LICENCE
    GSVIEWEN.HLP
    GSVW32DE.DLL
    FILEID.TMP
    GSVW32EN.DLL
    PSTOTXT3.DLL
    PSTOTXT3.EXE
    GSV16SPL.EXE
    GVWGS32.EXE
    ZLIB32.DLL
    PRINTER.INI
    README.TXT
    
    Expected output
    6
    LICENCE.TMP
    FILEID.
    LICENCE
    FILEID.TMP
    PSTOTXT3.DLL
    PSTOTXT3.EXE