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

Minimum Index

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1362    Accepted Submission(s): 456


Problem Description
Let s=$s_1$ $s_2$$ \cdots $$s_n$ be a string of length n. For any integer k between 1 to n, the $k^{th}$ suffix of s is defined as $s_k$ $s_{k+1}$$ \cdots $$s_n$. For example, the $4^{th}$ suffix of ¡°contest¡± is ¡°test¡± and the $1^{st}$ suffix of ¡°suffix¡± is ¡°suffix¡± itself.

One can consider lexicographically smallest suffix of s. Let the $k^{th}$ suffix is lexicographically minimum among all suffixes of s. Conveniently, let¡¯s call such k minimum index of s. Given a string t=$t_1$ $t_2 \cdots t_n$, your task is to calculate the sum of (minimum index of $t_1$ $t_2 \cdots t_i$)$ \cdot 1112^{i-1}$ over all i=1,2,3,$ \cdots $,n. This value may be too large, you are only required to print it modulo $10^9$+7.
 

Input
The first line of the input contains a single integer T (1¡ÜT¡Ü10 000), the number of test cases. Each of the next T lines contains a non-empty string with at most $10^6$ lowercase English letters. The total length of the input string over all test cases doesn¡¯t exceed $2 \cdot 10^7$.
 

Output
For each test case, you should print the answer in a single line.
 

Sample Input
1 aab
 

Sample Output
1238769
 

Hint

The minimum index of ¡°a¡±, ¡°aa¡±, ¡°aab¡± is 1, 2, 1 respectively. So the answer is (1+2∙1112+1112^2) mod (10^9+7)=1238769.
 

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-11-22 06:35:59, Gzip enabled