Computer DJ
Time limit1sMemory limit128 MB
Given N labeled songs, map the k-th character of the infinite string of all words over A..Z in length-then-lex order back to its song title.
- Level
Medium5 of 10
- Topics
- Math, Combinatorics, Implementation, Brute force
- Solved
- No attempts yet
Problem
A very famous DJ has recently been invited to play at the closing party of a Computer Science conference. To impress the participants, he decided to use a program to choose the songs he would play. The result, however, was a disaster, because the way the program picked songs was quite strange and repetitive.
First, the DJ selected songs from those available. The program then labels each song with a distinct character from 'A' to 'Z': the -th song is labeled with the -th character of the sequence 'A'-'Z'. The program plays the songs in the order their labels appear in the following infinite string of characters: first come all words of length 1 in lexicographical order, then all words of length 2 in lexicographical order, then all words of length 3, and so on. For , this string begins ABCAAABACBABBBCCACBCCAAAAABAACABAABBABC...
After the party, some people asked the DJ which song was played first. Others wanted to know which one was the 25th, and so on. The DJ remembers nothing but this strange repetition pattern, so he asks you to write a program that answers such queries.
Input
The input contains several test cases. Each test case consists of three lines. The first line contains two integers and , the number of songs the DJ chose and the number of queries the participants made ( and ). The second line contains the song titles separated by single spaces (each title is a string of alphanumeric characters, at least 1 and at most 100 characters long). The third line contains a sequence of queries. Each query is a number () referring to the -th song played at the party. The end of the input is indicated by .
Output
For each query in a test case, print a single line with the name of the -th song played at the party. Print a blank line after each test case.