#include <bits/stdc++.h>
int abs_(int a) { return a > 0 ? a : -a; }
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
long long cross(int x1, int y1, int x2, int y2) {
  return (long long)x1 * y2 - (long long)x2 * y1;
}
int xx[6000], yy[6000];
long long solve1(int *ii, int k) {
  static int kk[2][2];
  int h, x1, y1, x2, y2;
  long long ans;
  memset(kk, 0, sizeof kk);
  for (h = 0; h < k; h++) kk[xx[ii[h]] / 2 % 2][yy[ii[h]] / 2 % 2]++;
  ans = 0;
  for (x1 = 0; x1 < 2; x1++)
    for (y1 = 0; y1 < 2; y1++) {
      ans += (long long)kk[x1][y1] * (kk[x1][y1] - 1) * (kk[x1][y1] - 2) / 6;
      for (x2 = 0; x2 < 2; x2++)
        for (y2 = 0; y2 < 2; y2++)
          if (x2 != x1 || y2 != y1)
            ans += (long long)kk[x1][y1] * (kk[x1][y1] - 1) / 2 * kk[x2][y2];
    }
  return ans;
}
long long solve2(int *ii1, int k1, int *ii2, int k2, int x, int y) {
  static int kk[2][2][4], kk_[4];
  int h1, h2;
  long long ans;
  ans = 0;
  for (h2 = 0; h2 < k2; h2++) {
    int x2 = xx[ii2[h2]], y2 = yy[ii2[h2]];
    memset(kk, 0, sizeof kk), memset(kk_, 0, sizeof kk_);
    for (h1 = 0; h1 < k1; h1++) {
      int x1 = xx[ii1[h1]], y1 = yy[ii1[h1]];
      int c = (cross(x1 - x, y1 - y, x2 - x, y2 - y) % 4 + 4) % 4;
      int b = gcd(abs_(x2 - x1), abs_(y2 - y1)) % 4;
      int d = (c - b + 4) % 4, e = (-c - b + 8) % 4;
      int x = x1 / 2 % 2, y = y1 / 2 % 2;
      ans += kk_[(6 - e) % 4] - kk[x][y][(6 - e) % 4] + kk[x][y][(4 - e) % 4];
      kk[x][y][d]++, kk_[d]++;
    }
  }
  return ans;
}
int main() {
  static int ii[2][2][6000], kk[2][2];
  int n, i, x, y, x_, y_;
  long long ans;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d%d", &x, &y);
    xx[i] = x, yy[i] = y, x %= 2, y %= 2;
    ii[x][y][kk[x][y]++] = i;
  }
  ans = 0;
  for (x = 0; x < 2; x++)
    for (y = 0; y < 2; y++) {
      ans += solve1(ii[x][y], kk[x][y]);
      for (x_ = 0; x_ < 2; x_++)
        for (y_ = 0; y_ < 2; y_++)
          if (x_ != x || y_ != y)
            ans += solve2(ii[x][y], kk[x][y], ii[x_][y_], kk[x_][y_], x, y);
    }
  printf("%lld\n", ans);
  return 0;
}
