Under construction

Still being built. Things may change

Golden Tickets

Interview

Time limit1sMemory limit2048 MB

Summary
Given ranked teams and their institutions, pick the top M teams plus up to K more teams from new institutions, then print them in rank order.
Level

Easy3 of 10

Topics
Hash map, Simulation
Solved
No attempts yet

Problem

There are NN teams participating in INC 2023. The team ranked iith is team SiS_i, representing institution TiT_i. The top MM teams in INC 2023 are eligible to participate in The ICPC Asia Jakarta 2023.

Apart from the top MM teams, Golden Tickets are given to at most the top KK teams whose institutions are not in the top MM of INC 2023. Each institution receives at most one Golden Ticket, and only the highest-ranked team from each institution qualifies. Teams that receive a Golden Ticket can participate in The ICPC Asia Jakarta 2023.

Determine the number of teams that receive Golden Tickets. Then output the names of those teams, sorted by rank.

Input

The first line contains three integers NN, MM, KK (1≤M,K≤N≤1001 \le M, K \le N \le 100).

Each of the next NN lines contains two strings SiS_i and TiT_i separated by a space (1≤∣Si∣,∣Ti∣≤101 \le |S_i|, |T_i| \le 10). All strings consist of uppercase letters. No two teams have the same name, so Si≠SjS_i \ne S_j for 1≤i<j≤N1 \le i < j \le N.

Output

On the first line, print the number XX of teams that receive Golden Tickets. Then print XX lines, each containing the name of one such team, sorted by rank. If X=0X = 0, print no names.

Hint

Disclaimer

All team names and institution names in the samples are fictional. Any similarities with actual participants in INC 2023 are purely coincidental.

Examples4

  1. Example 1

    Input
    3 1 2
    ARUA UOGX
    NOIHS UHOLO
    IKUBUF UHOLO
    
    Expected output
    1
    NOIHS
    
  2. Example 2

    Input
    3 2 1
    ARUA UOGX
    NOIHS UHOLO
    IKUBUF UHOLO
    
    Expected output
    0
    
  3. Example 3

    Input
    5 1 2
    ARUA UOGX
    NOIHS UHOLO
    IKUBUF UHOLO
    ANUZAN UVSH
    LAMLA UNIJI
    
    Expected output
    2
    NOIHS
    ANUZAN
    
  4. Example 4

    Input
    9 3 3
    ARUA UOGX
    ANUZAN UVSH
    NOIHS UHOLO
    IKUBUF UHOLO
    LAMLA UNIJI
    IKASAS UNIJI
    ESUOMNORI UVSH
    AIHSUR URIP
    AYNEH UVSH
    
    Expected output
    2
    LAMLA
    AIHSUR