#P9873. [EC Final 2021] Beautiful String

[EC Final 2021] Beautiful String

题目描述

Prof. Pang recently got a dictionary of the elvish language, including many strings representing their words. He thinks a partition of string ss is beautiful if both of the following conditions are satisfied:

  • s=s1+s2+s3+s4+s5+s6s = s_1 + s_2 + s_3 + s_4 + s_5 + s_6, where si(1i6)s_i (1\leq i\leq 6) are nonempty substrings. a+ba + b means the concatenation of string aa and bb here.
  • s1=s2=s5,s3=s6s_1 = s_2 = s_5, s_3 = s_6.

For example, you can partition the string 114514 into 66 parts : 114514 = 1 + 1 + 4 + 5 + 1 + 4. The first, second, fifth parts are the same, and the third and sixth parts are the same. Thus, the partition of s=s=114514 into s1=s_1=1, s2=s_2=1, s3=s_3=4, s4=s_4=5, s5=s_5=1, and s6=s_6=4 is beautiful.

Accordingly, the beauty of a string ss is defined as the number of beautiful partitions of ss.

Given a string tt, please help Prof. Pang to figure out the sum of beauties of all substrings of tt.

输入格式

The first line contains a single integer T (1T50)T~(1\leq T \le 50) indicating the number of test cases.

For each test case, there is one single line containing the string tt, consisting of digits from 0' to 9'.

It is guaranteed that the length of each tt in each test case will not exceed 50005000 and the total length will not exceed 3000030000.

输出格式

For each test case, output a single line containing an integer, indicating the sum of beauties of all substrings of tt.

题目大意

当字符串 ss 的一个划分满足如下条件:

  • s=s1+s2+s3+s4+s5+s6s = s_1 + s_2 + s_3 + s_4 + s_5 + s_6,其中 si(1i6)s_i (1\leq i\leq 6) 为非空子串,a+ba + b 表示将字符串 bb 接于 aa 后。

  • s1=s2=s5,s3=s6s_1 = s_2 = s_5, s_3 = s_6

则称该划分美丽的

字符串 ss美丽值定义为 ss 的不同的美丽的划分的个数。

给出字符串 ss,求其所有子串美丽值之和

2
114514
0000000
1
3