I Am Pokemon Master Dasom

Interview

Time limit2sMemory limit256 MB

Summary
Build a bidirectional mapping between Pokemon numbers and names, then answer up to 100,000 lookup queries either way.
Level

Easy3 of 10

Topics
Hash map, Implementation, String
Solved
No attempts yet

Problem

Dasom is preparing for a test on a Pokemon encyclopedia. The encyclopedia lists Pokemon names in order from number 1 through number N.

Then M queries are given. If a query consists only of digits, print the Pokemon name with that number. If a query consists only of letters, print the number assigned to that name.

Input

The first line contains two natural numbers N and M: the number of Pokemon in the encyclopedia and the number of queries. Both N and M are between 1 and 100,000, inclusive.

The next N lines contain the names of Pokemon number 1 through number N, one per line and in order. Each name consists only of English letters and has length between 2 and 20, inclusive. The first character is uppercase and the remaining characters are lowercase, although some names may have only their last character uppercase as well.

The following M lines each contain one query. A digit-only query is a number between 1 and N, inclusive. A letter-only query is guaranteed to be a Pokemon name in the encyclopedia.

Output

For each query, print one answer on its own line. If the query is a number, print the corresponding Pokemon name. If the query is a name, print the corresponding number.

Examples1

  1. Example 1

    Input
    26 5
    Bulbasaur
    Ivysaur
    Venusaur
    Charmander
    Charmeleon
    Charizard
    Squirtle
    Wartortle
    Blastoise
    Caterpie
    Metapod
    Butterfree
    Weedle
    Kakuna
    Beedrill
    Pidgey
    Pidgeotto
    Pidgeot
    Rattata
    Raticate
    Spearow
    Fearow
    Ekans
    Arbok
    Pikachu
    Raichu
    25
    Raichu
    3
    Pidgey
    Kakuna
    
    Expected output
    Pikachu
    26
    Venusaur
    16
    14