问题 B: Distance

内存限制:512 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:3 通过:2

题目描述

For the two multisets AAA and BBB , In an operation, we can choose one between the following two operations:

1. Update an element aia_iai in the multiset AAA, to ai=ai+1a_i=a_i+1ai=ai+1

2. Update an element bib_ibi in the multiset BBB, to bi=bi+1b_i=b_i+1bi=bi+1

We define C(A,B)C(A,B)C(A,B) as the minimum number of operations to make the multisets AAA and BBB identical,meaning that both multisets have the same elements, If there is no way to transform multisets AAA and BBB into the same multiset, then C(A,B)=0C(A,B)=0C(A,B)=0.

Now you have two multisets SSS and TTT, and calc the value of ∑A⊆S∑B⊆TC(A,B)\sum\limits_{A\subseteq S}\sum\limits_{B\subseteq T}C(A,B)ASBTC(A,B) modulo 998244353998244353998244353.


Note: Subsets in the multiset are allowed to duplicate values, that is, the number of solutions selected from each of the two sets SSS and TTT is (2∣S∣−1)(2∣T∣−1)(2^{|S|}-1)(2^{|T|}-1)(2S1)(2T1).

输入格式

The first line contains a positive integer n (1≤n≤2×103)n\ (1\leq n\leq 2\times 10^3)n (1n2×103),representing the size of the multiset SSS and the multiset TTT .
The second line contains a line of nnn positive integers si (1≤si≤105)s_i \ (1\leq s_i\leq 10^5)si (1si105), representing the multiset SSS.
The third line contains a line of nnn positive integers ti (1≤ti≤105)t_i\ (1\leq t_i\leq 10^5)ti (1ti105), representing the multiset TTT.

The input sequence is not guaranteed to be ordered.

输出格式

Output a line with a integer representing the answer, modulo 998244353998244353998244353.

输入样例 复制

2
1 2
1 1

输出样例 复制

3

数据范围与提示

A={2} B={1} C(A,B)=1
A={2} B={1} C(A,B)=1
A={1 2} B={1 1} C(A,B)=1