#include <bits/stdc++.h>
using namespace std;
const int MX = 6000;
int double_area(int x1, int y1, int x2, int y2, int x3, int y3) {
  int tmp = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1);
  tmp = abs(tmp);
  return tmp % 4;
}
int gcd(int a, int b) {
  while (b) {
    int c = a % b;
    a = b;
    b = c;
  }
  return a;
}
pair<int, int> pts[MX];
int g[MX][MX];
int cnt[4][4][4];
int main() {
  int n;
  ignore = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x, y;
    ignore = scanf("%d %d", &x, &y);
    pts[i] = {x, y};
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      g[i][j] = g[j][i] = gcd(abs(pts[i].first - pts[j].first),
                              abs(pts[i].second - pts[j].second)) %
                          4;
    }
  }
  long long ans_2 = 0, ans_6 = 0;
  for (int pivot = 0; pivot < n; pivot++) {
    memset(cnt, 0, sizeof cnt);
    for (int i = 0; i < n; i++) {
      if (i == pivot) continue;
      cnt[pts[i].first % 4][pts[i].second % 4][g[i][pivot]]++;
    }
    for (int x1 = 0; x1 < 4; x1++)
      for (int y1 = 0; y1 < 4; y1++)
        for (int g1 = 0; g1 < 4; g1++)
          for (int x2 = 0; x2 < 4; x2++)
            for (int y2 = 0; y2 < 4; y2++)
              for (int g2 = 0; g2 < 4; g2++) {
                int g3 = gcd(abs(x1 - x2), abs(y1 - y2));
                if (g3 != 0 && g3 != 2) continue;
                int B = (g1 + g2 + g3) % 4;
                int S = double_area(x1, y1, x2, y2, pts[pivot].first,
                                    pts[pivot].second);
                if (S % 2 != 0) continue;
                if (S % 4 != B) continue;
                long long tmp;
                if (x1 == x2 && y1 == y2 && g1 == g2) {
                  tmp = cnt[x1][y1][g1] * (cnt[x1][y1][g1] - 1);
                } else {
                  tmp = cnt[x1][y1][g1] * cnt[x2][y2][g2];
                }
                if (g1 % 2 == 1) {
                  ans_2 += tmp;
                } else {
                  ans_6 += tmp;
                }
              }
  }
  ans_2 /= 2;
  ans_6 /= 6;
  printf("%lld\n", ans_2 + ans_6);
}

### Prompt

Generate a cpp solution to the following problem:

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 ≤ n ≤ 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 ≤ x,y ≤ 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.

Examples

Input


3
0 0
2 0
0 4


Output


1


Input


4
1 8
0 6
5 2
5 6


Output


1


Input


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


Output


29

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>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MX = 6000;
int double_area(int x1, int y1, int x2, int y2, int x3, int y3) {
  int tmp = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1);
  tmp = abs(tmp);
  return tmp % 4;
}
int gcd(int a, int b) {
  while (b) {
    int c = a % b;
    a = b;
    b = c;
  }
  return a;
}
pair<int, int> pts[MX];
int g[MX][MX];
int cnt[4][4][4];
int main() {
  int n;
  ignore = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x, y;
    ignore = scanf("%d %d", &x, &y);
    pts[i] = {x, y};
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      g[i][j] = g[j][i] = gcd(abs(pts[i].first - pts[j].first),
                              abs(pts[i].second - pts[j].second)) %
                          4;
    }
  }
  long long ans_2 = 0, ans_6 = 0;
  for (int pivot = 0; pivot < n; pivot++) {
    memset(cnt, 0, sizeof cnt);
    for (int i = 0; i < n; i++) {
      if (i == pivot) continue;
      cnt[pts[i].first % 4][pts[i].second % 4][g[i][pivot]]++;
    }
    for (int x1 = 0; x1 < 4; x1++)
      for (int y1 = 0; y1 < 4; y1++)
        for (int g1 = 0; g1 < 4; g1++)
          for (int x2 = 0; x2 < 4; x2++)
            for (int y2 = 0; y2 < 4; y2++)
              for (int g2 = 0; g2 < 4; g2++) {
                int g3 = gcd(abs(x1 - x2), abs(y1 - y2));
                if (g3 != 0 && g3 != 2) continue;
                int B = (g1 + g2 + g3) % 4;
                int S = double_area(x1, y1, x2, y2, pts[pivot].first,
                                    pts[pivot].second);
                if (S % 2 != 0) continue;
                if (S % 4 != B) continue;
                long long tmp;
                if (x1 == x2 && y1 == y2 && g1 == g2) {
                  tmp = cnt[x1][y1][g1] * (cnt[x1][y1][g1] - 1);
                } else {
                  tmp = cnt[x1][y1][g1] * cnt[x2][y2][g2];
                }
                if (g1 % 2 == 1) {
                  ans_2 += tmp;
                } else {
                  ans_6 += tmp;
                }
              }
  }
  ans_2 /= 2;
  ans_6 /= 6;
  printf("%lld\n", ans_2 + ans_6);
}

```