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>
using namespace std;
struct Point {
  long long x, y;
};
Point a[100005];
int n;
long long lf[100005], lr[100005], sum[100005];
int op(Point a, Point o, Point b) {
  long long x1 = o.x - a.x, y1 = o.y - a.y;
  long long x2 = b.x - o.x, y2 = b.y - o.y;
  if (x1 * y2 - x2 * y1 < 0)
    return 1;
  else
    return -1;
}
void deal(Point in) {
  long long ans = 0;
  sum[0] = 0;
  for (int i = 1; i <= n - 1; i++) {
    int l = i, h = n;
    while (l != h) {
      int mid = (l + h) / 2 + 1;
      if (op(a[i], in, a[mid]) < 0)
        l = mid;
      else
        h = mid - 1;
    }
    lf[i] = l - i;
    sum[i] = sum[i - 1] + lf[i];
  }
  sum[n] = sum[n - 1];
  lf[n] = 0;
  for (int i = 1; i <= n - 2; i++) {
    long long tmp = sum[i + lf[i]] - sum[i] - (lf[i] - 1) * lf[i] / 2;
    ans = ans + tmp;
  }
  printf("%I64d\n", ans);
}
bool dl(Point in) {
  long long x1 = in.x - a[n].x, y1 = in.y - a[n].y;
  long long x2 = in.x - a[1].x, y2 = in.y - a[1].y;
  long long dr = x1 * y2 - x2 * y1;
  for (int i = 1; i < n; i++) {
    long long tx1 = in.x - a[i].x, ty1 = in.y - a[i].y;
    long long tx2 = in.x - a[i + 1].x, ty2 = in.y - a[i + 1].y;
    long long tdr = tx1 * ty2 - tx2 * ty1;
    if ((tdr < 0 && dr > 0) || (tdr > 0 && dr < 0)) return true;
  }
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d%I64d", &a[i].x, &a[i].y);
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    Point in;
    scanf("%I64d%I64d", &in.x, &in.y);
    if (dl(in)) {
      printf("0\n");
      continue;
    }
    deal(in);
  }
}