

Time Limit: 3 sec / Memory Limit: 1024 MB
配点: 点
問題文
E869120 は, 文字列を square1001 に今年から 年間, 毎年プレゼントすることにした.
彼は, 文字列 が大好きであった. そのため, プレゼントする文字列は, 文字列 から取ることに決めた. また, 古から伝わる, AtCoder 社の教えに基づいて, プレゼントする文字列を決めることにした.
AtCoder 社の教えは, 以下のようなものである.
- 友達に文字列をプレゼントするときは, 以下の方法で文字列を決めなさい. ここでは, あなたの大好きな文字列を とおく.
- 文字列 の部分列の集合を とおく. ただし, 文字列 の部分列とは, から 個以上の文字を取り去ってできた 文字以上の長さの文字列のことを指す.
- 部分列の集合 を辞書順でソートしたときに, 番目となる文字列をプレゼントするべきである.
例えば, 大好きな文字列が aqua
である場合, は [a
,aa
,aq
,aqa
,aqu
,aqua
,au
,aua
,q
,qa
,qu
,qua
,u
,ua
] となる. のとき, 辞書順で 番目となる qa
をプレゼントするべきである.
しかし, の値は年ごとに変わってしまう.
そこで, 年目の の値 が与えられるので, 各年ごとのプレゼントすべき文字列の最後の 文字を求めてほしい.
入力
入力は以下の形式で標準入力から与えられる.
...
出力
行出力すること.
行目には, 年目にプレゼントすべき文字列の最後の 文字を出力すること.
ただし, 該当する文字列が存在しない場合 "-1" と出力せよ.
また, プレゼントすべき文字列が 文字未満の場合, プレゼントすべき文字列をそのまま出力せよ. 例えば, プレゼントすべき文字列が "abcde" であり, のとき, この行には "abcde" と出力すること.
制約
- は 以上 以下の整数.
- は英小文字から成る, 文字以上 文字以下の文字列.
- は 以上 以下の整数.
- は 以上 以下の整数.
小課題
小課題 [ 点]
- を満たす.
小課題 [ 点]
- を満たす.
小課題 [ 点]
- 追加の制約はない.
入力例 1Copy
aqua 16 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 11 10 12 10 13 10 14 10 15 10 16 10
出力例 1Copy
a aa aq aqa aqu aqua au aua q qa qu qua u ua -1 -1
問題文の例の通りです.
入力例 2Copy
tourist 2 76 10 76 4
出力例 2Copy
tourist rist
個目のクエリにおいて, "tourist" の後ろ 文字は "rist" なので, これを出力すること.
入力例 3Copy
eightsixnineonetwozero 6 869120 100 869120 10 869120 8 869120 6 869120 4 869120 2
出力例 3Copy
eihinieonetwoze ieonetwoze onetwoze etwoze woze ze
score: points
Problem Statement
E869120 the Coder decided to give a string to square1001 as a present each year for the next years.
Since E869120's favorite string is , he also decided to "pick" the string, which he'll give as a present, from .
Moreover, there's "AtCoder percepts" which has been told from ancient times, so he also decided to determine the string based on this percepts.
The contents of "AtCoder percepts" is as follows:
- When you will give a string as a present, you should decide the string as follows.
- Let be the set of substring (not necessarily contiguous) of .
- You should give -th string of in lexicographical order.
For example, if his favorite string is aqua
, will be [a
,aa
,aq
,aqa
,aqu
,aqua
,au
,aua
,q
,qa
,qu
,qua
,u
,ua
]. If , you should give qa
as a present, because qa
is the -th string in .
However, the value of will change every year. The -th year of will be .
Please answer the last characters of string which you should give to square1001 in -th year.
Input
Input is given from Standard Input in the following format:
...
Output
- Print lines.
- In -th line, print the last characters of substring of the string which he should give in -th year.
- If there is no string which is applicable, print "-1".
- If the string which he should give is less than characters, print the string. For example, if and string = "abcde", print "abcde".
Constraints
- .
- .
- consists of lowercase alphabets: from
a
toz
. - .
- .
- .
- All input values are integers.
Subtasks
Subtask [ points]
- .
Subtask [ points]
- .
Subtask [ points]
- There is no additional constraints.
Sample Input 1Copy
aqua 16 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 11 10 12 10 13 10 14 10 15 10 16 10
Sample Output 1Copy
a aa aq aqa aqu aqua au aua q qa qu qua u ua -1 -1
Please look the example in the problem statement.
Sample Input 2Copy
tourist 2 76 10 76 4
Sample Output 2Copy
tourist rist
In -nd query, the answer is "tourist". But you should output the last characters: "rist", because .
Sample Input 3Copy
eightsixnineonetwozero 6 869120 100 869120 10 869120 8 869120 6 869120 4 869120 2
Sample Output 3Copy
eihinieonetwoze ieonetwoze onetwoze etwoze woze ze