This page is still under construction.

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

Casting

Time limit1sMemory limit128 MB

Summary
For a convex polygon, count the vertex pairs whose connecting line splits it into two parts that can each be pulled out by translation.
Level

Hard9 of 10

Topics
Geometry, Two pointers, Math, Implementation
Solved
No attempts yet

Problem

Casting is a manufacturing process in which liquid is poured into a cast (mold) that has a cavity shaped like the object to be produced. The liquid hardens, after which the cast is removed. To mass produce the object by reusing the same cast parts, the cast parts must be removable from the object by translation without destroying either the cast parts or the object.

Given a convex polygon PP (the object), we divide the cast into two parts along a straight line through two vertices of PP. The goal is to choose the two vertices so that both cast parts can each be removed by translation (without destroying the cast parts or the object). For instance, in the original figures, dividing along the line through one pair of vertices lets the upper part be pulled upward and the lower part downward, while dividing along the line through some other pair leaves a part that wraps around the object and cannot be removed in any direction. Thus, not every pair of vertices admits such a division. (Each part may be removed in its own translation direction; removal is not required to be perpendicular to the dividing line.)

Given a convex polygon PP with nn vertices, write a program that finds all pairs of vertices (vi,vj)(v_i, v_j) such that both cast parts of PP, divided by the straight line through viv_i and vjv_j, can be removed by translation.

Input

Your program reads from standard input. The first line contains the number of test cases TT. Each test case begins with an integer nn, the number of vertices of a convex polygon PP, where 3≤n≤100,0003 \le n \le 100{,}000. The next line contains 2n2n integers x1 y1 x2 y2 … xn ynx_1\ y_1\ x_2\ y_2\ \dots\ x_n\ y_n, where xix_i and yiy_i are the xx- and yy-coordinates of vertex viv_i of PP. All coordinates are integers with −1,000,000,000≤xi,yi≤1,000,000,000-1{,}000{,}000{,}000 \le x_i, y_i \le 1{,}000{,}000{,}000. The vertices v1,v2,…,vnv_1, v_2, \dots, v_n are given in clockwise order along the boundary of PP.

Output

Your program writes to standard output. For each test case, print a single line containing the number of pairs (vi,vj)(v_i, v_j) of vertices with i<ji < j such that both cast parts of PP, divided by the straight line through viv_i and vjv_j, can be removed by translation without destroying either the cast parts or the object.

Examples2

  1. Example 1

    Input
    3
    3
    0 0 3 3 6 0
    4
    0 0 0 2 5 2 5 0
    5
    0 0 3 3 3 2 3 1 3 0
    
    Expected output
    3
    6
    10
    
  2. Example 2

    Input
    1
    3
    0 0 3 3 6 0
    
    Expected output
    3