F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

CRB and Substrings

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 397    Accepted Submission(s): 33


Problem 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
 

Hint

Query 1:
2-length substrings are ¡°ba¡± and ¡°aa¡±.
Value of ¡°ba¡± is 3, and value of ¡°aa¡± is 2.
Query 2:
1-length substrings are ¡°b¡± and ¡°a¡±.
Both have value 1, but ¡°a¡± is lexicographically smaller.
 

Author
KUT£¨DPRK£©
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-06-18 19:43:45, Gzip enabled