Codeforces Round 736 (Div. 2)
F2
Gregor and the Odd Cows (Hard)
Codeforces
未评级
原题
← F1→
翻译中…

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 $n$ 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 $3$ 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.

翻译中…

Input

翻译中…

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

翻译中…

Each of the next $n$ line contains two integers $x$ and $y$ ($0 \le x,y \le 10^7$, where $(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.

翻译中…

Note

翻译中…

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

翻译中…

image

翻译中…

In the second example, there are $4$ possible fences. Only one of them is interesting however. That fence has an area of $8$ and $5$ enclosed cows.

翻译中…

image

翻译中…

样例

Input #1
3
0 0
2 0
0 4
Output #1
1
InputCopy OutputCopy
Input #2
4
1 8
0 6
5 2
5 6
Output #2
1
InputCopy OutputCopy
Input #3
10
170 59
129 54
5 98
129 37
58 193
154 58
24 3
13 138
136 144
174 150
Output #3
29
InputCopy OutputCopy
题目信息
题号
1549F2
时间限制
6 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。