#P1648C. Tyler and Strings

    ID: 1330 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>combinatoricsdata structuresimplementation*1900

Tyler and Strings

Description

While looking at the kitchen fridge, the little boy Tyler noticed magnets with symbols, that can be aligned into a string ss.

Tyler likes strings, and especially those that are lexicographically smaller than another string, tt. After playing with magnets on the fridge, he is wondering, how many distinct strings can be composed out of letters of string ss by rearranging them, so that the resulting string is lexicographically smaller than the string tt? Tyler is too young, so he can't answer this question. The alphabet Tyler uses is very large, so for your convenience he has already replaced the same letters in ss and tt to the same integers, keeping that different letters have been replaced to different integers.

We call a string xx lexicographically smaller than a string yy if one of the followings conditions is fulfilled:

  • There exists such position of symbol mm that is presented in both strings, so that before mm-th symbol the strings are equal, and the mm-th symbol of string xx is smaller than mm-th symbol of string yy.
  • String xx is the prefix of string yy and xyx \neq y.

Because the answer can be too large, print it modulo 998244353998\,244\,353.

The first line contains two integers nn and mm (1n,m2000001 \le n, m \le 200\,000) — the lengths of strings ss and tt respectively.

The second line contains nn integers s1,s2,s3,,sns_1, s_2, s_3, \ldots, s_n (1si2000001 \le s_i \le 200\,000) — letters of the string ss.

The third line contains mm integers t1,t2,t3,,tmt_1, t_2, t_3, \ldots, t_m (1ti2000001 \le t_i \le 200\,000) — letters of the string tt.

Print a single number — the number of strings lexicographically smaller than tt that can be obtained by rearranging the letters in ss, modulo 998244353998\,244\,353.

Input

The first line contains two integers nn and mm (1n,m2000001 \le n, m \le 200\,000) — the lengths of strings ss and tt respectively.

The second line contains nn integers s1,s2,s3,,sns_1, s_2, s_3, \ldots, s_n (1si2000001 \le s_i \le 200\,000) — letters of the string ss.

The third line contains mm integers t1,t2,t3,,tmt_1, t_2, t_3, \ldots, t_m (1ti2000001 \le t_i \le 200\,000) — letters of the string tt.

Output

Print a single number — the number of strings lexicographically smaller than tt that can be obtained by rearranging the letters in ss, modulo 998244353998\,244\,353.

Sample Input 1

3 4
1 2 2
2 1 2 1

Sample Output 1

2

Sample Input 2

4 4
1 2 3 4
4 3 2 1

Sample Output 2

23

Sample Input 3

4 3
1 1 1 2
1 1 2

Sample Output 3

1

Note

In the first example, the strings we are interested in are [122][1\, 2\, 2] and [212][2\, 1\, 2]. The string [221][2\, 2\, 1] is lexicographically larger than the string [2121][2\, 1\, 2\, 1], so we don't count it.

In the second example, all strings count except [4321][4\, 3\, 2\, 1], so the answer is 4!1=234! - 1 = 23.

In the third example, only the string [1112][1\, 1\, 1\, 2] counts.