This page is still under construction.

Parts of this page are still being built. What you see may change.

Pie Division

Time limit2sMemory limit256 MB

Summary
Count the number of straight lines that split 2N labeled points (N of each of two colors, N even) so that each open half-plane holds N/2 points of each color, treating both sides as the same split.
Level

Hard8 of 10

Topics
Geometry, Combinatorics, Sorting, Two pointers
Solved
No attempts yet

Problem

Frans is celebrating his birthday. At an exclusive bakery he bought two delicious pies of different types. He cuts each pie into several pieces and, at coffee time, invites his colleagues over for a slice. After the celebration some pieces are left over — in fact exactly 2N2N pieces remain: NN pieces of each pie, and NN happens to be even. Frans does not want to take all of them home, so he decides to share them with a colleague who is also fond of pie.

The leftover pieces are scattered across the table, and Frans wonders how to split them into two. A simple way is to stretch a cord in a straight line over the table: the pieces on one side of the cord are for Frans, and the pieces on the other side are for his colleague. There is, however, a condition — each of them must take home exactly N/2N/2 pieces of the first pie and N/2N/2 pieces of the second pie.

Is this possible with the cord trick, and if so, in how many ways? Naturally, this depends on where the 2N2N pieces lie. Two divisions are regarded as the same when they separate the pieces into the same two groups; it does not matter which group ends up being Frans's. For example, when N=2N = 2 some arrangements of the four pieces admit two valid divisions, while others admit only one.

To keep things simple, assume that no three pieces lie on one straight line (in particular, no two pieces share the same position), and treat every piece as an infinitely small point.

Input

The first line contains a single integer: the number of test cases that follow. Each test case has the following format:

  • One line with an even integer NN, where 2≤N≤10002 \le N \le 1000.
  • NN lines, each with two integers xx and yy, where −10000≤x,y≤10000-10000 \le x, y \le 10000: the coordinates of a piece of the first pie.
  • NN lines, each with two integers xx and yy, where −10000≤x,y≤10000-10000 \le x, y \le 10000: the coordinates of a piece of the second pie.

The two integers on a line are separated by a single space.

Output

For each test case, print a single line with one integer: the number of ways to split the 2N2N pieces into two groups with a single straight cord so that each side of the cord holds N/2N/2 pieces of the first pie and N/2N/2 pieces of the second pie.

Examples3

  1. Example 1

    Input
    3
    2
    2 1
    4 3
    1 2
    3 1
    2
    2 1
    3 1
    1 2
    4 3
    4
    2 9
    6 1
    12 4
    11 8
    0 2
    15 6
    8 12
    1 5
    
    Expected output
    2
    1
    3
    
  2. Example 2

    Input
    1
    2
    4 -5
    -6 5
    -2 -3
    -3 -4
    
    Expected output
    2
    
  3. Example 3

    Input
    1
    2
    -6 -6
    -5 -3
    -3 2
    3 -6
    
    Expected output
    1