Under construction

Still being built. Things may change

Asian Informatics Olympiad

Interview

Time limit1sMemory limit128 MB

Summary
Sort students by descending score and pick the top three medalists while capping each country to at most two medals.
Level

Easy3 of 10

Topics
Sorting, Greedy, Simulation
Solved
No attempts yet

Problem

An online informatics olympiad is held for students from Asia. There is no limit on how many students may participate from each country.

The gold, silver, and bronze medalists are chosen by considering students in descending order of score. There are no tied scores. However, each country may receive at most two medals. If two students from a country have already received medals, another student from that country cannot receive the next medal even with a higher score.

Given the contest results, write a program that prints the gold, silver, and bronze medalists in order.

Input

The first line contains N, the number of participating students. 3 <= N <= 100.

Each of the next N lines contains one student's country number, student number, and score, separated by spaces. Country numbers are integers assigned in order starting from 1, and student numbers are integers assigned within each country starting from 1. Scores are integers from 0 to 1000, and no two students have the same score.

At least two countries appear in the input.

Output

Print the students who receive medals in the order gold, silver, and bronze, one student per line.

Each line must contain the medalist's country number and student number separated by one space.

Examples1

  1. Example 1

    Input
    9
    1 1 230
    1 2 210
    1 3 205
    2 1 100
    2 2 150
    3 1 175
    3 2 190
    3 3 180
    3 4 195
    
    Expected output
    1 1
    1 2
    3 4