#P10101. [ROIR 2023] 一个普通的字符串问题 (Day 2)

[ROIR 2023] 一个普通的字符串问题 (Day 2)

Background

Translated from ROIR 2023 D2T4

If for any string uu of length 22, the number of occurrences of uu in string ss is the same as the number of occurrences of uu in string tt, then the two strings ss and tt are called equivalent strings. Therefore, the strings aaaba, abaaa, and baaab are equivalent to each other (the substring aa appears twice, ab appears once, ba appears once, and bb does not appear as a substring), while cff and ccf are not equivalent. A string is equivalent to itself.

Problem Description

In this problem, you are given QQ strings consisting of the characters a, b, and c. For each string, you need to compute the number of non-empty strings consisting of the characters a, b, and c that are equivalent to it. Since this number can be very large, output it modulo 109+710^9 + 7.

Input Format

The first line contains an integer GG, which indicates the index of the current subtask. In the sample, G=0G=0. This problem also provides an additional Subtask 0 with score 00 to store the sample testdata.

The second line contains an integer qq.

The next qq lines each contain a string.

Output Format

For each string, output one line with one integer representing the answer, modulo 109+710^9+7.

0
4
abaa
abca
ccbca
bacc
3
3
2
1

Hint

Sample explanation:

  • The string abaa is equivalent to abaa, aaba, baab
  • The string abca is equivalent to abca, bcab, cabc
  • The string ccbca is equivalent to ccbca and cbcca
  • The string bacc is only equivalent to bacc.

This problem uses bundled tests.

Let nin_i be the length of the ii-th input string, LL be the sum of lengths of all strings, and ww be the maximum (not modulo) answer among all queries.

Constraints

Subtask ID Score Special Property
00 The input testdata is the same as the sample
11 1111 ss contains no c
22 1313 a and c are not adjacent in ss
33 1111 ni13n_i\le13
44 1010 L40L\le40
55 99 L60L\le60
66 1313 L105,w100L\le10^5,w\le100
77 3333 None

For 100%100\% of the testdata, 1q1051\le q\le10^5 and L106L\le10^6.

Translated by ChatGPT 5