Under construction

Still being built. Things may change

Election

Interview

Time limit1sMemory limit128 MB

Summary
Count the votes each candidate receives in one riding, ignore unknown names, and report the winner's party or independent, or tie if there is no strict winner.
Level

Easy3 of 10

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

Problem

Canada has a multi-party system of government. Each candidate is generally associated with a party, and the party whose candidates win the most ridings generally forms the government. Some candidates run as independents, meaning they are not associated with any party. Your job is to count the votes for a particular riding and to determine the party with which the winning candidate is associated.

Input

The first line contains a positive integer nn (2≤n≤202 \le n \le 20), the number of candidates in the riding.

Then nn pairs of lines follow. In each pair, the first line is the name of the candidate (up to 80 characters), and the second line is the name of the party (up to 80 characters), or the word independent if the candidate has no party. No candidate name is repeated and no party name is repeated. No line contains leading or trailing blanks.

The next line contains a positive integer mm (m≤10000m \le 10000), followed by mm lines, each giving the name of a candidate for which a ballot is cast. Any name not in the list of candidates is ignored.

Output

Output a single line containing one of the following:

  • The name of the party with which the winning candidate is associated, if there is a winning candidate and that candidate belongs to a party.
  • The word independent if there is a winning candidate and that candidate has no party.
  • The word tie if there is no winner; that is, if no candidate receives more votes than every other candidate.

Examples5

  1. Example 1

    Input
    3
    Marilyn Manson
    Rhinoceros
    Jane Doe
    Family Coalition
    John Smith
    independent
    6
    John Smith
    Marilyn Manson
    Marilyn Manson
    Jane Doe
    John Smith
    Marilyn Manson
    
    Expected output
    Rhinoceros
    
  2. Example 2

    Input
    2
    Alice
    Red Party
    Bob
    Blue Party
    2
    Alice
    Bob
    
    Expected output
    tie
    
  3. Example 3

    Input
    2
    Alice
    Red Party
    Bob
    independent
    3
    Bob
    Bob
    Alice
    
    Expected output
    independent
    
  4. Example 4

    Input
    3
    Anna Lee
    Green
    Ben Ross
    Yellow
    Cara Kim
    independent
    5
    Anna Lee
    Nobody
    Anna Lee
    Cara Kim
    Ghost
    
    Expected output
    Green
    
  5. Example 5

    Input
    2
    Mary Jane Watson
    Web Party
    Peter B Parker
    Spider Coalition
    3
    Mary Jane Watson
    Peter B Parker
    Mary Jane Watson
    
    Expected output
    Web Party