#P4199. 万径人踪灭

    ID: 3129 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串枚举,暴力快速傅里叶变换 FFT

万径人踪灭

Description

If the computer room is about to close, or you are in a hurry, please skip directly to the sixth paragraph.

VFleaKing noticed that along the dirt road going up and down the mountain, some places offer beautiful views while others do not. Divide the uphill road into segments of 1010 cm each. For every segment, use a to indicate that a nice view can be enjoyed, and b to indicate that it cannot. Then you get a string ss containing only a and b. Since going downhill uses the same road, the string for the downhill road is the reverse of the uphill string.

Let the uphill string have length nn, with characters s1,s2,,sns_1, s_2, \ldots, s_n in order. On the way up and down, VFleaKing will choose certain segments to look at the scenery, and keep his head down the rest of the time. That is, VFleaKing chooses kk segments x1,x2,,xkx_1, x_2, \ldots, x_k, where k>0k > 0 and 1x1<x2<<xkn1 \le x_1 < x_2 < \cdots < x_k \le n, and he will look at the scenery at these positions both uphill and downhill.

VFleaKing wants the results of seeing scenery to be the same uphill and downhill. That is, the sequence of whether he sees scenery uphill is sx1,sx2,,sxks_{x_1}, s_{x_2}, \cdots, s_{x_k}, denoted by T1T_1, and the sequence downhill is sxk,sxk1,,sx1s_{x_k}, s_{x_{k-1}}, \cdots, s_{x_1}, denoted by T2T_2. VFleaKing wants T1=T2T_1 = T_2.

VFleaKing also wants the intervals between these checks to be equal uphill and downhill. That is, the uphill intervals are x2x1,x3x2,,xkxk1x_2 - x_1, x_3 - x_2, \ldots, x_k - x_{k-1}, denoted by P1P_1. The downhill intervals are $x_k - x_{k-1}, x_{k-1} - x_{k-2}, \ldots, x_2 - x_1$, denoted by P2P_2. VFleaKing wants P1=P2P_1 = P_2.

VFleaKing thinks that if, between the first and the last time he looks at the scenery, there is not a single moment when he keeps his head down, he will fall. That is, if for all 1ik1 \le i \le k we have xi=x1+i1x_i = x_1 + i - 1, then VFleaKing will fall, and he does not want this to happen.

In short, select a subsequence from a string containing only a and b such that:

  1. Both positions and characters are symmetric about some axis.
  2. It is not a contiguous segment.

Take s="abaaaaabbabbabaa"s = \texttt{"abaaaaabbabbabaa"} as an example. If we use [a1,a2,,ak][a_1, a_2, \ldots, a_k] to denote a sequence, then [1,4][1, 4] is a valid sequence xx, [5,8,10,12,15][5, 8, 10, 12, 15] is also valid, and [4,5,8,9,10,11,12,15,16][4, 5, 8, 9, 10, 11, 12, 15, 16] is also valid. However, [1,2][1, 2] does not satisfy VFleaKing’s first and third wishes, so it is not valid. [1,2,4][1, 2, 4] does not satisfy the second wish, so it is not valid. [9,10,11][9, 10, 11] does not satisfy the third wish, so it is not valid.

Given the string ss, VFleaKing wants to know how many valid sequences xx there are. The answer can be large; please output it modulo 10000000071000000007.

Input Format

One line, a string containing only the two characters a and b.

Output Format

One line, a non-negative integer representing the answer.

abaabaa
14
aaabbbaaa
44
aaaaaaaa
53

Hint

Sample Explanation 1

There are 1414 valid sequences:

  • [1,3][1, 3], [1,4][1, 4], [2,5][2, 5], [1,6][1, 6], [3,6][3, 6], [4,6][4, 6], [1,7][1, 7], [3,7][3, 7], [4,7][4, 7];
  • [1,4,7][1, 4, 7], [3,5,7][3, 5, 7];
  • [1,3,4,6][1, 3, 4, 6], [1,2,5,6][1, 2, 5, 6], [3,4,6,7][3, 4, 6, 7].

Sample Explanation 2

I have come up with a brilliant explanation, but there are too many cases to fit here.

Sample Explanation 3

I have come up with a brilliant explanation, but there are too many cases to fit here.

Constraints

  • For 10%10\% of the testdata, the string contains only the letter a or only the letter b.
  • For another 20%20\% of the testdata, n1000n \le 1000.
  • For another 20%20\% of the testdata, either the number of a does not exceed 1010, or the number of b does not exceed 1010.
  • For another 10%10\% of the testdata, n10000n \le 10000.
  • For 100%100\% of the testdata, n100000n \le 100000.

Source

  • 2013 Hubei Mutual Test week 1
  • bzoj 3160
  • A Mathematical Textbook for the Informatics Olympiad
  • Compiled by stong9070

Translated by ChatGPT 5