Under construction

Still being built. Things may change

Birthday Memorization

Interview

Time limit1sMemory limit1024 MB

Summary
Given friends with distinct like-scores and birthdays, keep only the highest-scoring friend for each date and print the survivors' names in alphabetical order.
Level

Easy3 of 10

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

Problem

Krarkl wants to memorize the birthdays of all NN of his friends so that every day he knows whom to congratulate. Unfortunately, collisions often occur, meaning several friends have their birthday on the same day. This confuses Krarkl, so he decides that for each date with a collision he will only remember the birthday of the friend he likes the most. Given a list of each friend's birthday and how much Krarkl likes the friend, output which friends Krarkl will remember the birthday of.

Input

The first line of input contains the integer NN (1≤N≤2 0001 \leq N \leq 2\,000), the number of friends.

Then follow NN lines, one for each friend. The iith line consists of a string with the iith friend's first name, S_iS\_i (S_iS\_i is between 1 and 10 characters long), an integer C_iC\_i (0≤C_i≤100 0000 \leq C\_i \leq 100\,000) that says how much Krarkl likes the friend, and the friend's birthday in the format DD/MM (where DD is a day between 01 and 31 and MM is a month between 01 and 12). A higher value of C_iC\_i means Krarkl likes the friend more.

The birthdays will be real dates during 2020 (a leap year), e.g. 28/02 for the twenty-eighth of February. The names will consist of only lowercase English letters (a-z), with an uppercase first letter (A-Z). All C_iC\_i will be distinct.

Output

You shall output a line with an integer KK, the number of friends whose birthday Krarkl will remember.

It shall be followed by KK lines with one word each, the first names of the selected friends, in alphabetical order.

Hint

In the first example, Sanna and Simon have the same birthday. Since Krarkl likes Sanna less than Simon (1<21 < 2), Krarkl will only remember Simon's and Saga's birthdays.

In the second example, Krarkl has terrible luck and will miss half of his friends' birthdays.

Examples2

  1. Example 1

    Input
    3
    Sanna 1 16/03
    Simon 2 16/03
    Saga 3 14/10
    
    Expected output
    2
    Saga
    Simon
    
  2. Example 2

    Input
    10
    Oden 78 03/12
    Tor 132 14/05
    Freja 10000 14/05
    Loke 512 12/10
    Hel 14 04/05
    Fjorgynn 532 13/05
    Hildegun 500 13/05
    Vindsval 17 03/12
    Snotra 20 04/05
    Kvaser 420 03/12
    
    Expected output
    5
    Fjorgynn
    Freja
    Kvaser
    Loke
    Snotra