Problem: You are given two arrays and . Array is sorted in ascending order ( for each from to ).
You have to divide the array into consecutive subarrays so that, for each from to , the minimum on the -th subarray is equal to . Note that each element belongs to exactly one subarray, and they are formed in such a way: the first several elements of compose the first subarray, the next several elements of compose the second subarray, and so on.
For example, if and then there are two good partitions of array :
- ;
- .
You have to calculate the number of ways to divide the array . Since the number can be pretty large print it modulo 998244353.
Input Format: The first line contains two integers and () — the length of arrays and respectively.
The second line contains integers () — the array .
The third line contains integers () — the array .
Output Format: In only line print one integer — the number of ways to divide the array modulo 998244353.