#P14805. [CCPC 2024 哈尔滨站] 弹珠赛跑

[CCPC 2024 哈尔滨站] 弹珠赛跑

Description

Marble race is a fun way to play with marbles, and today you want to give it a try.

There are nn starting points on the negative half of the xx-axis, with the ii-th point located at xix_i. There are mm marbles in total, where mm is an odd number, and the ii-th marble has a speed of viv_i. In a race, each marble randomly chooses a starting point with equal probability, and different marbles can choose the same starting point. Then, all the marbles start moving simultaneously towards the positive direction of the xx-axis. Let cic_i be the starting point chosen by the ii-th marble. At time tt, the coordinate of the ii-th marble is given by xci+vitx_{c_i} + v_i \cdot t.

You are a unique marble race enthusiast and do not care which marble is the fastest. Instead, you want to find out the exact time when the \textbf{median} of all the mm marble coordinates reaches the origin (i.e., x=0x = 0). The median of a sequence of length mm (where mm is odd) is defined as the element at the position m+12\frac{m+1}{2} when sorted in ascending order (indexing starts from 11). Since the race has not yet started and the starting points are not yet determined, you are interested in the expected value of this time. To avoid floating-point errors, you only need to output the result modulo 109+710^9+7 (see the output format for details).

Input Format

The first line contains two positive integers nn and mm (1n,m5001 \le n, m \le 500, and mm is odd), representing the number of starting points and the number of marbles.

The second line contains nn integers x1,x2,,xnx_1, x_2, \ldots, x_n (109xi<0-10^9 \le x_i < 0), representing the coordinates of each starting point. It is guaranteed that all xix_i are distinct.

The third line contains mm integers v1,v2,,vmv_1, v_2, \ldots, v_m (1vi1091 \le v_i \le 10^9), representing the speed of each marble.

Output Format

Output a single integer, representing the expected time modulo 109+710^9+7.

Formally, let M=109+7M=10^9+7. It can be shown that the answer can be expressed as an irreducible fraction pq\frac p q, where pp and qq are integers and q≢0(modM)q \not\equiv 0\pmod M. Output the integer equal to pq1(modM)p\cdot q^{-1}\pmod M, where q1q^{-1} denotes the modular multiplicative inverse of qq modulo MM. In other words, output such an integer xx that 0x<M0\le x < M and xqp(modM)x\cdot q\equiv p\pmod M. It can be proved that there is exactly one xx which meets the condition.

2 3
-4 -5
1 2 3
250000004
3 3
-4 -5 -6
1 2 3
500000006
5 5
-4 -5 -6 -10 -2
1 2 3 2 4
434986672

Hint

For the first example, the speeds of the three marbles are 1,2,31, 2, 3, respectively. Consider the initial positions of the three marbles:

  • 4,4,4-4, -4, -4: At t=2t=2, the coordinates of the three marbles are 2,0,2-2, 0, 2, and the median is at the origin.
  • 4,4,5-4, -4, -5: At t=2t=2, the coordinates are 2,0,1-2, 0, 1, and the median is at the origin.
  • 4,5,4-4, -5, -4: At t=2.5t=2.5, the coordinates are 1.5,0,3.5-1.5, 0, 3.5, and the median is at the origin.
  • For (4,5,5)(-4, -5, -5), (5,4,4)(-5, -4, -4), (5,4,5)(-5, -4, -5), (5,5,4)(-5, -5, -4), (5,5,5)(-5, -5, -5), the median is at the origin at times t=2.5t=2.5, t=2t=2, t=2t=2, t=2.5t=2.5, t=2.5t=2.5, respectively.

In summary, the expected time is $\frac{2 + 2 + 2.5 + 2.5 + 2 + 2 + 2.5 + 2.5}{8} = \frac{9}{4}$, so you need to output 941mod(109+7)=2500000049 \cdot 4^{-1} \bmod (10^9+7) = 250000004.