Under construction

Still being built. Things may change

Game with triangles

Time limit2sMemory limit2048 MB

Summary
Points lie on the lines y=0 and y=2. For each k, find the maximum total area of k disjoint triangles, plus the largest possible k.
Level

Medium7 of 10

Topics
Sorting, Prefix sum, Greedy, Math
Solved
No attempts yet

Statement

Even Little John needs money to buy a house. But he recently lost his job, so how will he earn money now? By playing a game that pays him as a reward, of course. Oh well, it is probably not the kind of game you are thinking of.

There are n+mn+m distinct points (a_1,0),(a_2,0),…,(a_n,0),(b_1,2),(b_2,2),…,(b_m,2)(a\_1,0), (a\_2,0), \ldots, (a\_{n},0), (b\_1,2), (b\_2,2), \ldots, (b\_{m},2) on the plane. Initially, your score is 00. To increase your score, you can perform the following operation:

  • Choose three distinct points that are not collinear.
  • Increase your score by the area of the triangle formed by these three points.
  • Erase the three points from the plane.

An instance of the game, where the operation is performed twice.

Let k_max⁡k\_{\max} be the maximum number of operations that can be performed. For example, if no operation is possible, k_max⁡k\_{\max} is 00. Define f(k)f(k) as the maximum score achievable by performing the operation exactly kk times. f(k)f(k) is defined for every integer kk with 0≤k≤k_max⁡0 \le k \le k\_{\max}.

Find the value of k_max⁡k\_{\max}, and find the value of f(x)f(x) for each integer x=1,2,…,k_max⁡x=1,2,\ldots,k\_{\max}.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤3⋅1041 \le t \le 3 \cdot 10^4). The test cases follow.

The first line of each test case contains two integers nn and mm (1≤n,m≤2⋅1051 \le n,m \le 2 \cdot 10^5).

The second line contains nn pairwise distinct integers a_1,a_2,…,a_na\_1,a\_2,\ldots,a\_{n}, the points on y=0y=0 (−109≤a_i≤109-10^9 \le a\_i \le 10^9).

The third line contains mm pairwise distinct integers b_1,b_2,…,b_mb\_1,b\_2,\ldots,b\_{m}, the points on y=2y=2 (−109≤b_i≤109-10^9 \le b\_i \le 10^9).

The sum of nn and the sum of mm over all test cases each do not exceed 2⋅1052 \cdot 10^5.

Output

For each test case, output at most two lines.

The first line contains the value of k_max⁡k\_{\max}.

The second line contains k_max⁡k\_{\max} integers f(1),f(2),…,f(k_max⁡)f(1),f(2),\ldots,f(k\_{\max}). You may omit this line if k_max⁡k\_{\max} is 00.

Under the constraints of this problem, every value of f(x)f(x) is an integer no greater than 101610^{16}.

Hint

In the first test case, there are 1+3=41+3=4 points (0,0),(0,2),(1,2),(−1,2)(0,0),(0,2),(1,2),(-1,2). It can be shown that you cannot perform two or more operations. So k_max⁡k\_{\max} is 11, and only f(1)f(1) is asked.

You can choose (0,0)(0,0), (−1,2)(-1,2), and (1,2)(1,2) as the three vertices. The triangle has area 22, so your score increases by 22 and the three points are erased. It can be shown that the maximum score after one operation is 22. Therefore f(1)=2f(1)=2.

In the fifth test case, there are 8+2=108+2=10 points. It can be shown that you cannot perform three or more operations. So k_max⁡k\_{\max} is 22, and f(1)f(1) and f(2)f(2) are asked.

To maximize the score with one operation, choose (198 872 582,0)(198\,872\,582,0), (−1 000 000 000,2)(-1\,000\,000\,000,2), and (1 000 000 000,2)(1\,000\,000\,000,2). The score becomes 2 000 000 0002\,000\,000\,000, so f(1)=2 000 000 000f(1)=2\,000\,000\,000.

To maximize the score with exactly two operations, first choose (−509 489 796,0)(-509\,489\,796,0), (553 177 666,0)(553\,177\,666,0), and (−1 000 000 000,2)(-1\,000\,000\,000,2). Then choose (−400 714 529,0)(-400\,714\,529,0), (564 040 265,0)(564\,040\,265,0), and (1 000 000 000,2)(1\,000\,000\,000,2). The score becomes 2 027 422 2562\,027\,422\,256, so f(2)=2 027 422 256f(2)=2\,027\,422\,256.

Examples1

  1. Example 1

    Input
    5
    1 3
    0
    0 1 -1
    2 4
    0 100
    -100 -50 0 50
    2 4
    0 1000
    -100 -50 0 50
    6 6
    20 1 27 100 43 42
    100 84 1 24 22 77
    8 2
    564040265 -509489796 469913620 198872582 -400714529 553177666 131159391 -20796763
    -1000000000 1000000000
    
    Expected output
    1
    2
    2
    150 200
    2
    1000 200
    4
    99 198 260 283
    2
    2000000000 2027422256