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(long long x = 0, long long y = 0) : x(x), y(y) {}
  void read() { scanf("%I64d%I64d", &x, &y); }
  point operator-(point b) { return point(x - b.x, y - b.y); }
};
vector<point> ev;
int n;
long long ans = 0;
bool on_watch(point p, point q) {
  long long t = p.x * q.y - p.y * q.x;
  return t < 0;
}
bool stop(int a, int b, point c) { return !on_watch(ev[b] - ev[a], c - ev[a]); }
long long count(long long n) { return n * (n - 1) / 2; }
long long get_full() { return (n * (n - 1ll) * (n - 2ll)) / 6ll; }
long long triangle_square(point a, point b, point c) {
  return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
long long square(point c) {
  long long sq = 0;
  for (int i = 0; i < n; ++i) {
    sq += abs(triangle_square(ev[i], ev[(i + 1) % n], c));
  }
  return sq;
}
int main() {
  int test;
  scanf("%d", &n);
  long long full = get_full();
  ev.resize(n);
  for (int i = 0; i < n; ++i) ev[i].read();
  scanf("%d", &test);
  for (int t = 0; t < test; ++t) {
    long long ans = 0, next = 1;
    point q;
    q.read();
    if (square(ev[0]) != square(q)) {
      printf("0\n");
      continue;
    }
    for (int i = 0; i < n; ++i) {
      while (!stop(i, (1 + next) % n, q)) ++next;
      ans += count(next - i);
    }
    cout << full - ans << endl;
  }
  return 0;
}