Under construction

Still being built. Things may change

Tokyo2020

Interview

Time limit8sMemory limit1024 MB

Summary
Given medal records for each year, find the earliest year with the most golds and the earliest year with the most total medals.
Level

Easy3 of 10

Topics
Implementation, Hash map, Sorting
Solved
No attempts yet

Problem

The Japanese team at the 2020 Tokyo Olympics finished every event on August 8, 2021, and won 58 medals in total: 27 gold, 14 silver, and 17 bronze.

Setting that aside, you are given the results of Olympic events, and you must find the year with the most gold medals and the year with the most medals. If several years qualify, find the earliest among them.

Input

The input consists of multiple data sets. Each data set has the following format.

N
Y1 S1 M1
...
YN SN MN

Each data set has N+1 lines. The first line contains the number of medals N (1 ≤ N ≤ 200) won in Olympic events. The following N lines list the results of Olympic events, one per line. Each line contains the year Yi (1896 ≤ Yi ≤ 2021) in which the event was held, the event name Si (1 ≤ |Si| ≤ 20), a string of English letters only, and the medal color Mi (Mi ∈ { "Gold", "Silver", "Bronze" }), in that order. Mi = "Gold" means a gold medal was won, Mi = "Silver" means a silver medal was won, and Mi = "Bronze" means a bronze medal was won. The given event results are guaranteed to contain at least one j (1 ≤ j ≤ N) with Mj = "Gold".

The end of the input is indicated by a line containing a single zero. The number of data sets does not exceed 50.

Output

For each data set, output the earliest year among the years with the most gold medals and the earliest year among the years with the most medals, separated by a single space.

Examples1

  1. Example 1

    Input
    6
    2021 Judo Gold
    2021 Swimming Silver
    2019 Baseball Gold
    2019 Soccer Gold
    2021 Skateboard Bronze
    2020 Baseball Bronze
    5
    2000 ABC Gold
    2000 DEF Gold
    2000 GHI Gold
    2000 JKL Gold
    2000 MNO Gold
    7
    2009 Donut Bronze
    2011 Honeycomb Silver
    2011 Ice Silver
    2013 KitKat Silver
    2017 Oreo Gold
    2015 Marshmallow Gold
    2009 Eclair Silver
    3
    2000 abc Gold
    2004 abc Gold
    2004 abc Gold
    0
    
    Expected output
    2019 2021
    2000 2000
    2015 2009
    2004 2004