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;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m;
int x[300000], y[300000], a[300000], b[300000], c[300000];
long long d[300000], w[300000];
long long vect(int x1, int y8687969, int x2, int y2) {
  return (long long)x1 * y2 - (long long)x2 * y8687969;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &x[i], &y[i]);
    x[2 * n + i] = x[n + i] = x[i];
    y[2 * n + i] = y[n + i] = y[i];
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int cx, cy;
    scanf("%d%d", &cx, &cy);
    int pc = 0, nc = 0;
    for (int j = 0; j < n; j++) {
      long long tmp = vect(x[j] - cx, y[j] - cy, x[j + 1] - cx, y[j + 1] - cy);
      pc += int(tmp > 0);
      nc += int(tmp < 0);
    }
    if (pc && nc)
      printf("0\n");
    else {
      a[0] = 0;
      while (vect(x[a[0] + 1] - x[0], y[a[0] + 1] - y[0], cx - x[0],
                  cy - y[0]) < 0)
        a[0]++;
      b[0] = a[0];
      while (vect(x[b[0]] - x[0], y[b[0]] - y[0], cx - x[0], cy - y[0]) < 0)
        b[0]++;
      for (int i = 1; i < 2 * n; i++) {
        a[i] = a[i - 1];
        b[i] = b[i - 1];
        while (vect(x[a[i] + 1] - x[i], y[a[i] + 1] - y[i], cx - x[i],
                    cy - y[i]) < 0)
          a[i]++;
        while (vect(x[b[i]] - x[i], y[b[i]] - y[i], cx - x[i], cy - y[i]) < 0)
          b[i]++;
      }
      c[0] = b[0];
      while (a[0] + n >= b[c[0]]) c[0]++;
      for (int i = 1; i < n; i++) {
        c[i] = c[i - 1];
        while (a[i] + n >= b[c[i]]) c[i]++;
      }
      d[2 * n - 1] = 0;
      for (int i = 2 * n - 2; i >= 0; i--) {
        d[i] = d[i + 1] + (a[i + 1] - a[i]);
        w[i] = w[i + 1] + (long long)(a[i + 1] - a[i]) * (2 * n - i);
      }
      long long ans = 0;
      for (int i = 0; i < n; i++) {
        int j = b[i];
        int k = a[j];
        int s = a[i] + n - k;
        if (s <= 0) continue;
        long long tmp;
        if (b[i] + 1 == c[i])
          tmp = 0;
        else
          tmp = w[b[i]] - w[c[i] - 1] -
                (d[b[i]] - d[c[i] - 1]) * (2 * n - c[i] + 1);
        ans += (long long)s * (c[i] - b[i]) - tmp;
      }
      cout << ans / 3 << endl;
    }
  }
  return 0;
}