#P15689. [ICPC 2023 Jakarta R] Twin Friends

[ICPC 2023 Jakarta R] Twin Friends

题目描述

You meet two new friends who are twins. The name of the elder twin is A A , which consists of N N characters. While the name of the younger twin is B B , which consists of M M characters. It is known that NM N \leq M .

You want to call each of them with a nickname. For the elder twin, you want to pick any permutation of A A as the nickname. For the younger twin, you want to remove exactly MN M - N characters from any permutation of B B . Denote the nicknames of the elder twin and the younger twin as A A' and B B' , respectively.

You want the nicknames to satisfy the following requirement. For each i i that satisfies 1iN 1 \leq i \leq N , Bi B'_i must be equal to either Ai A'_i or the next letter that follows alphabetically after Ai A'_i (if such a next letter exists).

Determine the number of different pairs of nicknames (A,B) (A', B') that satisfy the requirement. Two pairs of nicknames are considered different if at least one of the nicknames are different. As the result might be large, find the answer modulo 998244353 998\,244\,353 .

输入格式

The first line consists of two integers N N M M ( 1NM200000 1 \leq N \leq M \leq 200\,000 ).

The second line consists of a string A A of length N N .

The third line consists of a string B B of length M M .

All strings consist of only upper-case letters.

输出格式

Output a single integer representing number of different pairs (A,B) (A', B') that satisfy the requirement, modulo 998244353 998\,244\,353 .

3 4
AMA
ANAB
9
5 8
BINUS
BINANUSA
120
15 30
BINUSUNIVERSITY
BINANUSANTARAUNIVERSITYJAKARTA
151362308
4 4
UDIN
ASEP
0

提示

Explanation for the sample input/output #1

The 9 9 pairs are:

  • (AAM, AAN),
  • (AAM, ABN),
  • (AAM, BAN),
  • (AMA, ANA),
  • (AMA, ANB),
  • (AMA, BNA),
  • (MAA, NAA),
  • (MAA, NAB), and
  • (MAA, NBA).

Explanation for the sample input/output #2

The 120 120 pairs are the pairs where A A' is a permutation of BINUS and B=A B' = A' .