Permutations that contain a word

Count distinct permutations of A that contain B as a contiguous substring, modulo 10007.

Hard8Dynamic programmingCombinatoricsString matchingMathNo attempts yetTime limit2sMemory limit128 MB

Problem

You are given two words AA and BB, both written with lowercase English letters. Rearranging all the letters of AA produces many words. Count the distinct words obtained this way that contain BB as a contiguous substring. Two rearrangements that produce the same word count once.

Compute the remainder of that count divided by 1000710007.

Input

The first line contains the word AA, written with lowercase English letters. The length of AA is at most 500500.

The second line contains the word BB, written with lowercase English letters. The word BB is not longer than the word AA.

Output

Print the remainder of the number of such words divided by 1000710007 on the first line.

Note

If AA is mirko and BB is mir, the six words are kmiro, komir, mirko, mirok, okmir, omirk.