두 수열에서 같은 값을 갖는 증가하는 인덱스 쌍을 골라 그 값들이 웨이브(증가, 감소 교대)를 이루는 경우의 수를 센다.
어려움8동적 계획법조합론누적 합배열아직 제출이 없습니다시간 제한1초메모리 제한512 MBHave 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_n is a wavel if and only if a_1<a_2>a_3<a_4>a_5<a_6….
Now, given two sequences a_1,a_2,…,a_n and b_1,b_2,…,b_m, Little Q wants to find two sequences f_1,f_2,…,f_k and g_1,g_2,…,g_k (1≤f_i≤n, f_i<f_i+1 and 1≤g_i≤m, g_i<g_i+1) such that a_f_i=b_g_i always holds and the sequence a_f_1,a_f_2,…,a_f_k is a wavel. Moreover, Little Q is wondering how many pairs of such sequences f and g exist. Please write a program to help him figure out the answer.
The first line of the input contains two integers n and m: the lengths of a and b, respectively (1≤n,m≤2000).
The second line contains n integers a_1,a_2,…,a_n: the sequence a (1≤a_i≤2000).
The third line contains m integers b_1,b_2,…,b_m: the sequence b (1≤b_i≤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,353.
Here is the list of such sequences.