cswork / OAOpen practice workspace

AmazonOA #124

Count Secured Strings

Estimated HardJudge-ready

Topics (AI-labelled)SubsequencesString DPBits & Math

Choose a subsequence of the customer password s by index, and count the choices that are lexicographically strictly greater than t, modulo 1000000007. When the same resulting string comes from different index choices, each is counted separately.

Input

Two lines, s and t; 1≤|s|≤100000, 1≤|t|≤100, both lowercase.

Output

Output a single integer answer.

Example 1

Input:

aba
ab

Output:

3

Example 2

Input:

bab
ab

Output:

5

Example 3

Input:

aaa
aa

Output:

1

Example notes

Example 1: the three choices b, ba and aba are strictly greater, so the answer is 3. Example 2: the two b's at different positions plus ba, bb and bab, 5 in total. Example 3: only the full aaa is greater than aa, so the answer is 1.

Editorial

Loading solution…