Codegon (I got TLE) Can Anybody help me out in this Question?

You are given three strings A , B and C. From the strings Aand B, you can create all possible strings X such that X contains atleast one character from both the strings, and the order of all the selected characters in individual strings is preserved.

For example:

A = "ab", B= "cd"

All possible strings are: { abc, abcd, abd, ac, acb, acbd, acd, acdb, ad, adb, bc, bcd, bd, ca, cab, cabd, cad, cadb, cb, cbd, cda, cdab, cdb, da, dab, db }

Count the number of ways to create C string using string A and B .

As the answer could be very large, print the answer modulo 10^9 + 7 .

Note:

Python2 and Python3 users should submit their code to Pypy2 and Pypy3 respectively.
Input Format

The first line contains three space separated strings , and respectively.

Constraints

All the strings contains lowercase english letters.
Output Format

Print the required answer modulo .

Sample Input 0

ab ba aba
Sample Output 0

2
Explanation 0

The two ways to form "aba" are:

Pick the first two characters of "ab", and then second character of "ba".
Pick the first character of "ab", and both the characters of "ba".
Sample Input 1

abd bcd abcd
Sample Output 1

4
Explanation 1

The four ways to form "abcd" are:

Pick the first character of "abd", followed by all the characters of "bcd".
Pick the first character of "abd", followed by first two characters of "bcd", followed by last character of "abd".
Pick the first two characters of "abd", followed by the last two characters of "bcd".
Pick the first two characters of "abd", then second character of "bcd", followed by the last character of "abd".

Comments (3)