atcoder#ARC129F. [ARC129F] Let's Play Tag

[ARC129F] Let's Play Tag

Score : 10001000 points

Problem Statement

Snuke and N+MN+M children are standing on a number line.

At time 00, they are at the following positions.

  • Snuke is at coordinate 00.
  • NN children are at negative coordinates. The ii-th of them is at coordinate Li-L_i.
  • MM children are at positive coordinates. The ii-th of them is at coordinate RiR_i.

They will now play a game of tag. Specifically, they will do the following actions.

  • Snuke first chooses a string ss consisting of NN Ls and MM Rs. Then, for each i=1,2,,N+Mi=1,2,\cdots,N+M, he does the following.- If the ii-th character of ss is L, start moving at a speed of 22 in the negative direction.
    • If the ii-th character of ss is R, start moving at a speed of 22 in the positive direction.
    • When having caught a child (by occupying the same coordinate), go to the next ii, or end the game if i=N+Mi=N+M.
  • If the ii-th character of ss is L, start moving at a speed of 22 in the negative direction.
  • If the ii-th character of ss is R, start moving at a speed of 22 in the positive direction.
  • When having caught a child (by occupying the same coordinate), go to the next ii, or end the game if i=N+Mi=N+M.
  • Every child keeps moving at a speed of 11 in the direction away from Snuke.

Assume that we have found the time when the game ends for every ss that Snuke can choose in the beginning. Find the sum of all those values, modulo 998244353998244353.

Constraints

  • 3N,M2500003 \leq N,M \leq 250000
  • 1L1<L2<<LN<9982443531 \leq L_1 < L_2 < \cdots < L_N < 998244353
  • 1R1<R2<<RM<9982443531 \leq R_1 < R_2 < \cdots < R_M < 998244353
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

L1L_1 L2L_2 \cdots LNL_N

R1R_1 R2R_2 \cdots RMR_M

Output

Print the answer.

3 3
1 2 3
1 2 3
2748

For example, if s=s=LRRLLR, the game goes as follows.

  • At time 00: Snuke starts moving in the negative direction.
  • At time 11: Snuke catches a child at coordinate 2-2 and starts moving in the positive direction.
  • At time 55: Snuke catches a child at coordinate 66 and starts moving in the positive direction.
  • At time 66: Snuke catches a child at coordinate 88 and starts moving in the negative direction.
  • At time 2222: Snuke catches a child at coordinate 24-24 and starts moving in the negative direction.
  • At time 2323: Snuke catches a child at coordinate 26-26 and starts moving in the positive direction.
  • At time 7575: Snuke catches a child at coordinate 7878 and ends the game.
7 5
89789743 196247866 205535557 542612813 782887985 889864096 899373580
539329402 618885430 714090971 717251433 860233092
937403116