Wavel Sequence

두 수열에서 같은 값을 갖는 증가하는 인덱스 쌍을 골라 그 값들이 웨이브(증가, 감소 교대)를 이루는 경우의 수를 센다.

어려움8동적 계획법조합론누적 합배열아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Have you ever seen a wave? It's a wonderful display of nature. Little Q is attracted to this wonderful thing, he even likes everything that looks like a wave. Formally, he says that a sequence a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n is a wavel if and only if a_1<a_2>a_3<a_4>a_5<a_6a\_1 < a\_2 > a\_3 < a\_4 > a\_5 < a\_6 \ldots.

Now, given two sequences a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n and b_1,b_2,,b_mb\_1, b\_2, \ldots, b\_m, Little Q wants to find two sequences f_1,f_2,,f_kf\_1, f\_2, \ldots, f\_k and g_1,g_2,,g_kg\_1, g\_2, \ldots, g\_k (1f_in1 \leq f\_i \leq n, f_i<f_i+1f\_i < f\_{i + 1} and 1g_im1 \leq g\_i \leq m, g_i<g_i+1g\_i < g\_{i + 1}) such that a_f_i=b_g_ia\_{f\_i} = b\_{g\_i} always holds and the sequence a_f_1,a_f_2,,a_f_ka\_{f\_1}, a\_{f\_2}, \ldots, a\_{f\_k} is a wavel. Moreover, Little Q is wondering how many pairs of such sequences ff and gg exist. Please write a program to help him figure out the answer.

입력

The first line of the input contains two integers nn and mm: the lengths of aa and bb, respectively (1n,m20001 \leq n, m \leq 2000).

The second line contains nn integers a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n: the sequence aa (1a_i20001 \leq a\_i \leq 2000).

The third line contains mm integers b_1,b_2,,b_mb\_1, b\_2, \ldots, b\_m: the sequence bb (1b_i20001 \leq b\_i \leq 2000).

출력

Print a single line containing a single integer: the answer to the problem. As the answer can be very large, print it modulo 998,244,353998\\,244\\,353.

힌트

Here is the list of such sequences.

  1. f=(1)f=(1), g=(2)g=(2).
  2. f=(1)f=(1), g=(3)g=(3).
  3. f=(2)f=(2), g=(4)g=(4).
  4. f=(3)f=(3), g=(5)g=(5).
  5. f=(1,2)f=(1,2), g=(2,4)g=(2,4).
  6. f=(1,2)f=(1,2), g=(3,4)g=(3,4).
  7. f=(1,3)f=(1,3), g=(2,5)g=(2,5).
  8. f=(1,3)f=(1,3), g=(3,5)g=(3,5).
  9. f=(1,2,3)f=(1,2,3), g=(2,4,5)g=(2,4,5).
  10. f=(1,2,3)f=(1,2,3), g=(3,4,5)g=(3,4,5).