Under construction

Still being built. Things may change

Twin Friends

Time limit2sMemory limit1024 MB

Summary
Count pairs of a permutation A' of A and a length-N string B' from B, where each B' letter equals or follows the matching A' letter, modulo 998244353.
Level

Medium6 of 10

Topics
Combinatorics, Dynamic programming, Prefix sum
Solved
No attempts yet

Problem

You meet two new friends who are twins. The elder twin's name is AA, which has NN characters. The younger twin's name is BB, which has MM characters. N≤MN \le M.

You want to give each of them a nickname. For the elder twin, you choose any permutation of AA as the nickname A′A'. For the younger twin, you remove exactly M−NM - N characters from some permutation of BB to form the nickname B′B'.

The nicknames must satisfy this condition: for each ii with 1≤i≤N1 \le i \le N, Bi′B'_i is either Ai′A'_i or the letter that follows Ai′A'_i in the alphabet (if that letter exists).

Count the number of different pairs (A′,B′)(A', B') that satisfy the condition. Two pairs are different if at least one of their nicknames differs. Print the count modulo 998244353998244353.

Input

The first line contains two integers NN and MM (1≤N≤M≤2000001 \le N \le M \le 200000).

The second line contains the string AA of length NN.

The third line contains the string BB of length MM.

All strings consist only of uppercase letters.

Output

Print one integer, the number of valid pairs (A′,B′)(A', B') modulo 998244353998244353.

Examples4

  1. Example 1

    Input
    3 4
    AMA
    ANAB
    
    Expected output
    9
    
  2. Example 2

    Input
    5 8
    BINUS
    BINANUSA
    
    Expected output
    120
    
  3. Example 3

    Input
    15 30
    BINUSUNIVERSITY
    BINANUSANTARAUNIVERSITYJAKARTA
    
    Expected output
    151362308
    
  4. Example 4

    Input
    4 4
    UDIN
    ASEP
    
    Expected output
    0