#P1548D2. Gregor and the Odd Cows (Hard)

    ID: 521 Type: RemoteJudge 6000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>brute forcegeometrymathnumber theory*3300

Gregor and the Odd Cows (Hard)

No submission language available for this problem.

Description

This is the hard version of the problem. The only difference from the easy version is that in this version the coordinates can be both odd and even.

There are nn fence-posts at distinct coordinates on a plane. It is guaranteed that no three fence posts lie on the same line.

There are an infinite number of cows on the plane, one at every point with integer coordinates.

Gregor is a member of the Illuminati, and wants to build a triangular fence, connecting 33 distinct existing fence posts. A cow strictly inside the fence is said to be enclosed. If there are an odd number of enclosed cows and the area of the fence is an integer, the fence is said to be interesting.

Find the number of interesting fences.

The first line contains the integer nn (3n60003 \le n \le 6000), the number of fence posts which Gregor can choose to form the vertices of a fence.

Each of the next nn line contains two integers xx and yy (0x,y1070 \le x,y \le 10^7, where (x,y)(x,y) is the coordinate of a fence post. All fence posts lie at distinct coordinates. No three fence posts are on the same line.

Print a single integer, the number of interesting fences. Two fences are considered different if they are constructed with a different set of three fence posts.

Input

The first line contains the integer nn (3n60003 \le n \le 6000), the number of fence posts which Gregor can choose to form the vertices of a fence.

Each of the next nn line contains two integers xx and yy (0x,y1070 \le x,y \le 10^7, where (x,y)(x,y) is the coordinate of a fence post. All fence posts lie at distinct coordinates. No three fence posts are on the same line.

Output

Print a single integer, the number of interesting fences. Two fences are considered different if they are constructed with a different set of three fence posts.

Samples

Sample Input 1

3
0 0
2 0
0 4

Sample Output 1

1

Sample Input 2

4
1 8
0 6
5 2
5 6

Sample Output 2

1

Sample Input 3

10
170 59
129 54
5 98
129 37
58 193
154 58
24 3
13 138
136 144
174 150

Sample Output 3

29

Note

In the first example, there is only 11 fence. That fence is interesting since its area is 44 and there is 11 enclosed cow, marked in red.

In the second example, there are 44 possible fences. Only one of them is interesting however. That fence has an area of 88 and 55 enclosed cows.