QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#10359. Genome Reconstruction

Statistics

Biologist Little T is currently researching the synthesis of gene strings, where a gene string is defined as a string over the alphabet {A, C, G, T}.

For a research task, the objects are three gene strings $X$, $Y$, and $Z$. Little T selects an arbitrary contiguous substring $X_1$ from $X$, an arbitrary contiguous substring $Y_1$ from $Y$, and an arbitrary contiguous substring $Z_1$ from $Z$, and then concatenates them in order to obtain $X_1 + Y_1 + Z_1$. Let $f(X, Y, Z)$ be the number of distinct gene strings that can be formed in this way. (Note that any of the aforementioned arbitrary contiguous substrings can be an empty string.)

Little T now has three gene strings $A$, $B$, and $C$, each of length $n$, and $Q$ research tasks. Each task is described by six positive integers $A_l$, $A_r$, $B_l$, $B_r$, $C_l$, and $C_r$, representing the need to calculate the value of $f(A[A_l:A_r], B[B_l:B_r], C[C_l:C_r]) \bmod 998244353$.

Input

The first line contains two positive integers $n$ and $Q$.

The next three lines each contain a string of length $n$ consisting of characters from {A, C, G, T}, representing the gene strings $A$, $B$, and $C$ respectively.

The next $Q$ lines each contain six positive integers $A_l$, $A_r$, $B_l$, $B_r$, $C_l$, and $C_r$, describing a query.

Output

Output $Q$ lines, each containing a non-negative integer representing the answer.

Examples

Input 1

2 1
AC
CC
AA
1 2 1 2 1 1

Output 1

15

Input 2

3 1
ACG
GCA
TTT
1 3 1 3 2 1

Output 2

35

Note

If $l > r$, then $S[l:r]$ is an empty string, and an empty string is a contiguous substring of any string.

Constraints

  • For 100% of the data, $n, Q \leq 10^5$, $1 \leq A_l, A_r, B_l, B_r, C_l, C_r \leq n$.
  • Constraint 1 is defined as: for all queries, $B_l > B_r$ and $C_l > C_r$.
  • Constraint 2 is defined as: for all queries, $C_l > C_r$.
Number $n$ $Q$ Other Constraints
1 10 10
2 20 20
3 50 50
4 100 100
5 100 100
6 500 500
7 500 500
8 100 100000
9 250 100000
10 3000 100000
11 3000 100000 Constraint 1
12 3000 100000 Constraint 2
13 5000 5000 Constraint 1
14 5000 5000 Constraint 2
15 5000 5000
16 50000 50000 Constraint 2
17 100000 100000 Constraint 1
18 50000 50000
19 70000 70000
20 100000 100000

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.