logo AlgoBeat OnlineJudge
登录 注册

#215744. [ICPC 2023 Jakarta R] Twin Friends

内存限制:1024 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

You meet two new friends who are twins. The name of the elder twin is , which consists of characters. While the name of the younger twin is , which consists of characters. It is known that .

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

You want the nicknames to satisfy the following requirement. For each that satisfies , must be equal to either or the next letter that follows alphabetically after (if such a next letter exists).

Determine the number of different pairs of nicknames 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 .

输入格式

The first line consists of two integers ( ).

The second line consists of a string of length .

The third line consists of a string of length .

All strings consist of only upper-case letters.

输出格式

Output a single integer representing number of different pairs that satisfy the requirement, modulo .

样例

样例输入 1

3 4
AMA
ANAB

样例输出 1

9

样例输入 2

5 8
BINUS
BINANUSA

样例输出 2

120

样例输入 3

15 30
BINUSUNIVERSITY
BINANUSANTARAUNIVERSITYJAKARTA

样例输出 3

151362308

样例输入 4

4 4
UDIN
ASEP

样例输出 4

0

数据范围与提示

Explanation for the sample input/output #1

The 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 pairs are the pairs where is a permutation of BINUS and .