407219: GYM102697 190 Contact Tracing

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

190. Contact Tracingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
This problem is worth 30 points.

During the coronavirus pandemic, your town is attempting to trace the origins of recent COVID-19 cases.

You're given a list of people who had the disease, and who they got it from, and you're trying to find the names of "superspreaders". For this problem, we'll define a superspreader as someone who gave at least three other people COVID-19.

Given this information, your task is to figure out the names of all of the superspreaders in the town.

Input

The first line of input contains a single positive integer $$$n$$$: the number of people in the town.

The next $$$n$$$ lines contain two space-separated strings: the name of each person, and the name of the person they got the coronavirus from. Exactly one person in the town will have "OTHER" (no quotes) as the person they got the disease from, indicating that this person got the disease from a different town.

Output

Output $$$k$$$ lines, where $$$k$$$ is the number of superspreaders in the town. On each line, print the name of each superspreader in the order they were given in the input.

If there aren't any superspreaders in the town, output "NONE" (no quotes).

ExamplesInput
10
Alice OTHER
Bob Alice
Cheryl Alice
Darryl Bob
Ernie Alice
Frank Darryl
Greta Darryl
Hank Cheryl
Irene Bob
John Darryl
Output
Alice
Darryl
Input
4
Keith OTHER
Larry Keith
Marshall Larry
Nancy Marshall
Output
NONE
Input
6
Alice Frank
Bob Ernie
Cheryl Darryl
Darryl Ernie
Ernie OTHER
Frank Ernie
Output
Ernie

加入题单

算法标签: