#P15073. [ICPC 2024 Chengdu R] Athlete Welcome Ceremony

[ICPC 2024 Chengdu R] Athlete Welcome Ceremony

题目描述

Chengdu is about to host the 2025 World Games. During the athlete welcome ceremony at the opening event, there will be nn volunteers dressed in one of three different types of traditional folk costumes, lined up to welcome the athletes. These costumes are denoted by type a\texttt{a}, b\texttt{b}, and c\texttt{c}. The positions of the volunteers have been determined, and now we need to assign costumes to the volunteers. To achieve a specific visual effect, adjacent volunteers must not wear the same type of costume.

Among the nn volunteers, some already have one of the three types of folk costumes, while others do not have any and require custom-made costumes provided by the organizers. There are QQ custom-making plans, each specifying: making xx sets of costumes a\texttt{a}, yy sets of costumes b\texttt{b}, and zz sets of costumes c\texttt{c}.

For each custom-making plan, determine how many different valid costume arrangements can be made after distributing the custom-made costumes to the volunteers who do not have any costumes. Specifically, determine the number of ways for assigning costumes a\texttt{a}, b\texttt{b} and c\texttt{c} under the condition of not exceeding the limits of the given plan. If two arrangements differ in the type of costume assigned to the same volunteer, they are considered different. Note that the same type of costumes are not distinguished from each other. As the number may be very large, please output the answer modulo 109+710^9+7.

输入格式

The first line contains two integers nn (1n3001\le n\le 300) and QQ (1Q1051\le Q\le 10^5), representing the number of volunteers and the number of custom-making plans, respectively.

The second line is a string ss of length nn. It is guaranteed that the string ss contains only the characters a\texttt{a}, b\texttt{b}, c\texttt{c}, and ?\texttt{?}. If the ii-th character is one of a\texttt{a}, b\texttt{b}, and c\texttt{c}, it indicates that the ii-th volunteer already has the corresponding costume; otherwise, if it is ?\texttt{?}, it indicates that the ii-th volunteer does not have any costume.

Each of the next QQ lines contains three integers x,y,zx, y, z (0x,y,z3000 \le x, y, z \le 300), representing a custom-making plan. It is guaranteed that the sum x+y+zx+y+z is no less than the number of volunteers without costumes.

输出格式

Output QQ lines, with the ii-th line containing an integer that represents the number of valid costume arrangements that satisfy the requirements for the ii-th custom-making plan. Please output the answer modulo 109+710^9+7.

6 3
a?b??c
2 2 2
1 1 1
1 0 2
3
1
1
6 3
??????
2 2 2
2 3 3
3 3 3
30
72
96

提示

In the first sample, the valid costume arrangements for the first custom-making plan are acbabc\texttt{acbabc}, acbcac\texttt{acbcac}, and acbcbc\texttt{acbcbc}.