CF176B.Word Cut

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let's consider one interesting word game. In this game you should transform one word into another through special operations.

Let's say we have word ww , let's split this word into two non-empty parts xx and yy so, that w=xyw=xy . A split operation is transforming word w=xyw=xy into word u=yxu=yx . For example, a split operation can transform word "wordcut" into word "cutword".

You are given two words startstart and endend . Count in how many ways we can transform word startstart into word endend , if we apply exactly kk split operations consecutively to word startstart .

Two ways are considered different if the sequences of applied operations differ. Two operation sequences are different if exists such number ii ( 1<=i<=k1<=i<=k ), that in the ii -th operation of the first sequence the word splits into parts xx and yy , in the ii -th operation of the second sequence the word splits into parts aa and bb , and additionally xax≠a holds.

输入格式

The first line contains a non-empty word startstart , the second line contains a non-empty word endend . The words consist of lowercase Latin letters. The number of letters in word startstart equals the number of letters in word endend and is at least 22 and doesn't exceed 10001000 letters.

The third line contains integer kk ( 0<=k<=1050<=k<=10^{5} ) — the required number of operations.

输出格式

Print a single number — the answer to the problem. As this number can be rather large, print it modulo 10000000071000000007 (109+7)(10^{9}+7) .

输入输出样例

  • 输入#1

    ab
    ab
    2
    

    输出#1

    1
    
  • 输入#2

    ababab
    ababab
    1
    

    输出#2

    2
    
  • 输入#3

    ab
    ba
    2
    

    输出#3

    0
    

说明/提示

The sought way in the first sample is:

ab a|b ba b|a ab

In the second sample the two sought ways are:

  • ababab abab|ab ababab
  • ababab ab|abab ababab
首页