cswork / OAOpen practice workspace

AmazonOA #95

countSecurePasswordVariations

Estimated HardJudge-ready

Topics (AI-labelled)SubsequencesString DPBits & Math

Among all index subsequences of customer, count those that are lexicographically strictly greater than system. Identical strings chosen from different indices are counted separately; when system is a prefix, the longer string is greater. Output the result modulo 10⁹+7.

Input

Two lines with the lowercase strings customer and system, of lengths 1..100000 and 1..100 respectively.

Output

Output a single integer answer.

Example 1

Input:

bab
ab

Output:

5

Example 2

Input:

aa
a

Output:

1

Example 3

Input:

a
z

Output:

0

Example notes

Example 1: the two b at different indices, plus ba, bb, bab, 5 in total. Example 2: only aa is greater than a; the two single a are equal, so the answer is 1. Example 3: a is smaller than z, so there is no qualifying subsequence, and the answer is 0.

Editorial

Loading solution…