Twin Friends

시간 제한2초메모리 제한1024 MB

요약
A의 순열 A'와 B의 순열에서 M-N개를 지운 길이 N 문자열 B' 중, 모든 i에서 B'_i가 A'_i이거나 그 다음 알파벳인 쌍의 수를 센다.
난이도

어려움10점 중 8점

유형
조합론, 정렬, 그리디, 수학
정답자
아직 제출이 없습니다

문제

You meet two new friends who are twins. The name of the elder twin is AA, which consists of NN characters. While the name of the younger twin is BB, which consists of MM characters. It is known that N≤MN ≤ M.

You want to call each of them with a nickname. For the elder twin, you want to pick any permutation of AA as the nickname. For the younger twin, you want to remove exactly M−NM - N characters from any permutation of BB. 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 that satisfies 1≤i≤N1 ≤ i ≤ N, B′_iB'\_i must be equal to either A′_iA'\_i or the next letter that follows alphabetically after A′_iA'\_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 998,244,353998\\, 244\\, 353.

입력

The first line consists of two integers NN MM (1≤N≤M≤200,0001 ≤ N ≤ M ≤ 200\\, 000).

The second line consists of a string AA of length NN.

The third line consists of a string BB of length MM.

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 998,244,353998\\, 244\\, 353.

예제4

  1. 예제 1

    입력
    3 4
    AMA
    ANAB
    
    예상 출력
    9
    
  2. 예제 2

    입력
    5 8
    BINUS
    BINANUSA
    
    예상 출력
    120
    
  3. 예제 3

    입력
    15 30
    BINUSUNIVERSITY
    BINANUSANTARAUNIVERSITYJAKARTA
    
    예상 출력
    151362308
    
  4. 예제 4

    입력
    4 4
    UDIN
    ASEP
    
    예상 출력
    0