CRB and Substrings

Time Limit: 3000ms
Memory Limit: 131072KB
This problem will be judged on HDU. Original ID: 5415
64-bit integer IO format: %I64d      Java class name: Main

Description

Value of a string is defined as the number of distinct substrings of it.
For example, value of “ab” is 3(“a”, “b”, “ab”), and value of “xyx” is 5(“x”, “y”, “xy”, “yx”, “xyx”).
Now CRB has a string s.
For some integer $k$, CRB wants to know $k$-length substring of $s$ which has maximum value. But it seems not so easy. Can you help him?

Input

There are multiple test cases.
The first line contains a string $s$. The next line contains an integer $Q$ denoting the number of queries. Each of the next $Q$ lines contains a single integer $k$.
1 ≤ $|s|$ ≤ $10^{5}$
$s$ consists only of lowercase English letters.
1 ≤ $Q$ ≤ 10
1 ≤ $k$ ≤ $|s|$

Output

For each query $k$, output the string whose value is maximum among all $k$-length substrings of $s$, followed by its value.
If multiple substrings have same maximum value, output the lexicographically smallest one.

Sample Input

baa
2
2
1

Sample Output

ba 3
a 1

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .