This page is still under construction.

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

Regetni

Time limit1sMemory limit128 MB

Summary
Count triples of given integer points whose triangle area is an integer, including collinear triples with area 0.
Level

Medium7 of 10

Topics
Math, Combinatorics, Number theory, Geometry
Solved
No attempts yet

Problem

Hello, Earthling. We come from the planet Regetni, and we need your help to make a great deal of money — perhaps we will even share some of it with you.

The trouble is that in our world everything must be an integer. It is even enforced by law: no other kind of number is allowed for anything. So it should not surprise you that we plan our cities using integer coordinate systems. Until now only axis-aligned rectangular plots of land have been sold, but our professor Elgnairt recently had the revolutionary idea to sell triangular plots too. We believe high society will love the concept and that it will make us rich.

Unfortunately the professor patented his idea, so we cannot simply use it. We need his permission, and being a true scientist he will not grant it until we solve one of his riddles. That is where you come in, because we hear you are a genius.

The professor's riddle goes like this: given some candidate corner points, determine how many triangles of integer area can be built from them. Degenerate triangles with empty area (that is, straight lines) must be counted too, since 0 is an integer. To be precise, count the number of triangles whose three corners are three distinct points from the given set of points. All points in a scenario are distinct — there are no duplicates. Here are some examples:

Example a) shows a triangle with integer area (namely 3); b) shows one with non-integer area; c) shows a degenerate triangle with empty area (that is, zero, so count it!); d) shows four points, any three of which build a triangle of integer area; and e) shows four points from which no integer-area triangle can be built at all.

Hint: the area AA of a triangle with corners (x1,y1)(x_1, y_1), (x2,y2)(x_2, y_2) and (x3,y3)(x_3, y_3) can be computed as

A=∣x1y2−y1x2+x2y3−y2x3+x3y1−y3x1∣2A = \frac{|x_1 y_2 - y_1 x_2 + x_2 y_3 - y_2 x_3 + x_3 y_1 - y_3 x_1|}{2}

Try to make clever use of this formula.

Input

The first line contains the number of scenarios. Each scenario is given on one line: first the number NN of distinct points in that scenario (0≤N≤100000 \le N \le 10000), followed by NN pairs of integers, each pair describing one point (xi,yi)(x_i, y_i) with −100000≤xi,yi≤100000-100000 \le x_i, y_i \le 100000. All of these numbers are separated by single spaces.

Output

For each scenario, first print a line "Scenario #i:", where ii is the scenario number starting at 1. Then print a single line containing the number of triangles of integer area whose three distinct corners are among the given points. Print a blank line after each scenario.

Examples1

  1. Example 1

    Input
    6
    3 0 0 2 0 1 -3
    3 0 0 2 1 1 -3
    3 0 0 2 2 3 3
    4 0 0 2 0 0 2 2 2
    4 0 0 1 0 0 1 1 1
    9 0 0 0 1 0 2 1 0 1 1 1 2 2 0 2 1 2 2
    
    Expected output
    Scenario #1:
    1
    
    Scenario #2:
    0
    
    Scenario #3:
    1
    
    Scenario #4:
    4
    
    Scenario #5:
    0
    
    Scenario #6:
    48