Under construction

Still being built. Things may change

Making ChatGPT

Time limit1sMemory limit1024 MB

Summary
Given a corpus of bracketed sentences, each character is followed by its most frequent next character, and the task is to output characters K to K+M-1 of the generated string.
Level

Medium4 of 10

Topics
String, Hash map, Simulation
Solved
No attempts yet

Problem

Jiwon is a graduate student in the AI graduate school at GIST, and in principle should be able to build a home ChatGPT-style model without much trouble. But Jiwon is lazy, so instead of a deep learning language model, Jiwon will use a slightly modified n-gram model, a basic NLP technique.

Given a single character, Jiwon's language model predicts the next character by looking at the training corpus. The training corpus consists of several strings. When a character cc is given, the model searches the training corpus for every occurrence of cc, then finds the character c′c' that appears most often immediately after cc, and predicts that the next character after cc is c′c'. Note that c=c′c=c' is possible. If several characters tie for the most frequent, the model chooses the one with the smallest ASCII code. If the character cc does not appear in the training corpus, the model cannot predict the next character and an error occurs.

The training corpus uses only the character [ marking the start of a sentence, the character ] marking the end of a sentence, the lowercase letters a to z, and the character -, which replaces spaces. Every sentence in the corpus starts with [, ends with ], and has length at least 33. The character [ appears only at the start of a sentence, and the character ] appears only at the end of a sentence.

To generate a sentence with the model, first input the start character [. When the model predicts the next character c1c_1, append it to the sentence being generated. Then input c1c_1 into the model to predict the next character c2c_2, and repeat. If the end character ] appears during this process, stop generating. Otherwise, the prediction keeps going forever. You can prove that as long as the training corpus is not empty, the model never reaches a state where it cannot predict the next character.

Given the training corpus, guess a substring of the string that this model generates, together with Jiwon.

Input

The first line contains three integers NN, KK, and MM, separated by spaces. The training corpus consists of NN sentences, and the program must output the characters from the KK-th to the (K+M−1)(K+M-1)-th of the string generated by the language model trained on this corpus. (1≤N≤100 0001 \leq N \leq 100\,000, 1≤K≤10181 \leq K \leq 10^{18}, 1≤M≤1 0001 \leq M \leq 1\,000)

From the second line onward, the NN lines each contain one sentence of the training corpus as a string. Each line starts with [ and ends with ], and has length at least 33. The character [ appears only at the start of each line, and the character ] appears only at the end of each line.

The total length of all strings in the training corpus does not exceed 300 000300\,000.

Output

Output the characters from the KK-th to the (K+M−1)(K+M-1)-th of the string generated by the language model trained on the given corpus. When printing the ii-th character, if the generated string is too short and has no ii-th character, print . instead.

Hint

The ASCII code of - is 45, the ASCII code of [ is 91, the ASCII code of ] is 93, and the ASCII code of a is 97.

Examples2

  1. Example 1

    Input
    3 1 15
    [i-love-you]
    [my-name-is-james]
    [gist-algorithm-masters]
    
    Expected output
    [gis]..........
    
  2. Example 2

    Input
    4 1 15
    [i-love-you]
    [my-name-is-james]
    [gist-algorithm-masters]
    [dresscode]
    
    Expected output
    [de-ame-ame-ame