Problem: You are given a convex polygon. Count, please, the number of triangles that contain a given point in the plane and their vertices are the vertices of the polygon. It is guaranteed, that the point doesn't lie on the sides and the diagonals of the polygon.

Input

The first line contains integer n — the number of vertices of the polygon (3 ≤ n ≤ 100000). The polygon description is following: n lines containing coordinates of the vertices in clockwise order (integer x and y not greater than 109 by absolute value). It is guaranteed that the given polygon is nondegenerate and convex (no three points lie on the same line).

The next line contains integer t (1 ≤ t ≤ 20) — the number of points which you should count the answer for. It is followed by t lines with coordinates of the points (integer x and y not greater than 109 by absolute value).

Output

The output should contain t integer numbers, each on a separate line, where i-th number is the answer for the i-th point.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).

Examples

Input

4
5 0
0 0
0 5
5 5
1
1 3


Output

2


Input

3
0 0
0 5
5 0
2
1 1
10 10


Output

1
0


Input

5
7 6
6 3
4 1
1 2
2 4
4
3 3
2 3
5 5
4 2


Output

5
3
3
4

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
int n;
struct point {
  int x, y;
};
point p, v[100005];
long long total;
int semn(point p1, point p2, point p3) {
  long long s;
  s = ((long long)p2.x - p1.x) * ((long long)p3.y - p2.y) -
      ((long long)p2.y - p1.y) * ((long long)p3.x - p2.x);
  if (s < 0) return -1;
  if (s > 0) return 1;
  return 0;
}
int ok(int i, int j, int k) {
  int s1 = semn(v[i], v[j], p);
  int s2 = semn(v[j], v[k], p);
  int s3 = semn(v[k], v[i], p);
  return s1 == s2 && s2 == s3;
}
void rez() {
  int i, j;
  long long nr = 0, nr1, nr2;
  j = 2;
  for (i = 1; i <= n; i++) {
    while (!ok(i, (j - 1) % n + 1, (j + 1 - 1) % n + 1)) j++;
    nr1 = j - i;
    nr2 = n - nr1 - 1;
    nr = nr + nr1 * (nr1 - 1) / 2 + nr2 * (nr2 - 1) / 2;
  }
  total -= nr / 2;
}
int polig() {
  int s = semn(v[1], v[2], p);
  int i;
  for (i = 1; i <= n; i++)
    if (s != semn(v[i], v[(i - 1 + 1) % n + 1], p)) return 0;
  return 1;
}
int main() {
  scanf("%d", &n);
  int i, t;
  for (i = 1; i <= n; i++) scanf("%d %d", &v[i].x, &v[i].y);
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &p.x, &p.y);
    if (!polig()) {
      printf("0\n");
      continue;
    }
    total = (long long)n * (n - 1) * (n - 2) / 6;
    rez();
    printf("%I64d\n", total);
  }
  return 0;
}