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;
int n, t;
long long x[101000];
long long y[101000];
long long cx, cy;
long long det(long long x0, long long y0, long long x1, long long y1) {
  return x0 * y1 - x1 * y0;
}
int diff(int l, int r) {
  if (r >= l) return r - l;
  return n - (l - r);
}
long long cnt(int v) {
  int l = (v + 2) % n;
  if (det(x[l] - x[v], y[l] - y[v], cx - x[v], cy - y[v]) >= 0) return 0;
  int r = (v + n - 1) % n;
  while (diff(l, r) > 1) {
    int d = diff(l, r) / 2;
    int m = (l + d) % n;
    if (det(x[m] - x[v], y[m] - y[v], cx - x[v], cy - y[v]) < 0)
      l = m;
    else
      r = m;
  }
  if (det(x[r] - x[v], y[r] - y[v], cx - x[v], cy - y[v]) < 0) l = r;
  long long ret = diff(v, l);
  return (ret - 1) * ret / 2;
}
bool is_inside() {
  int l = 1;
  int r = n - 1;
  if (det(cx - x[0], cy - y[0], x[l] - x[0], y[l] - y[0]) <= 0) return false;
  if (det(cx - x[0], cy - y[0], x[r] - x[0], y[r] - y[0]) >= 0) return false;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    if (det(cx - x[0], cy - y[0], x[m] - x[0], y[m] - y[0]) == 0) return false;
    if (det(cx - x[0], cy - y[0], x[m] - x[0], y[m] - y[0]) < 0)
      r = m;
    else
      l = m;
  }
  if (l == r) return false;
  if (det(cx - x[l], cy - y[l], x[r] - x[l], y[r] - y[l]) < 0) return false;
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int xx, yy;
    scanf("%d %d", &xx, &yy);
    x[i] = xx;
    y[i] = yy;
  }
  scanf("%d", &t);
  for (int i = 0; i < t; ++i) {
    int xx0, yy0;
    scanf("%d %d", &xx0, &yy0);
    cx = xx0;
    cy = yy0;
    long long res = (n * (long long)(n - 1) * (long long)(n - 2)) / 6;
    if (is_inside()) {
      for (int v = 0; v < n; ++v) {
        res -= cnt(v);
      }
    } else
      res = 0;
    cout << res << "\n";
  }
  return 0;
};