AlgoUniversity
  • Go Back
Discussion
String Shift Transformation :

Author

Gurankit Pal Singh

Difficulty Level : Hard

Submissions : 140

Asked In : standard-chartered

Marks :10

: 4 | : 0

Given two strings $$$src$$$ and $$$target$$$, and an integer $$$k$$$.

In one operation you can remove the suffix of any length from the $$$src$$$ string and add it to the front of the remaining string.

You have to tell the number of ways to transform $$$src$$$ string to $$$target$$$ string in exactly $$$k$$$ operations modulo $$$10^9+7$$$.

Input

The first line contains a string $$$src, (2 \le |src| \le 1000)$$$

The second line contains a string $$$target, (2 \le |target| \le 1000)$$$

The third line contains an integer $$$k, ( 1 \le k \le 10^6)$$$

Output

Print the number of ways to transform $$$src$$$ to $$$target$$$ in exactly $$$k$$$ operations modulo $$$10^9+7$$$.

Examples

Input
abcd
cdab
2
Output
2
Input
ababab
ababab
1
Output
2

Note

In the given example, there are following ways:

  • "abcd" can be transformed to "bcda" by selecting suffix "bcd" and "bcda" can be transformed to "cdab" by selecting the suffix "cda"

  • "abcd" can be transformed to "dabc" by selecting "d" and "dabc" can be transformed to "cdab" by selecting suffix "c".

So, there are 2 ways to transform in exactly $$$k$$$ steps. Hence, the answer is 2.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.