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 JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;

/**
 * User: adamax
 * Date: 14.01.11
 * Time: 15:33
 */
public class Problem {

    static int n;
    static long[] x, y;
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(in.readLine());
        x = new long[n];
        y = new long[n];
        for (int i = 0; i < n; ++i) {
            String[] s = in.readLine().split(" ");
            x[i] = Long.parseLong(s[0]);
            y[i] = Long.parseLong(s[1]);
        }
        int t = Integer.parseInt(in.readLine());
        while (t --> 0) {
            String[] s = in.readLine().split(" ");
            long x0 = Long.parseLong(s[0]), y0 = Long.parseLong(s[1]);
            long res = solve(x0, y0);
            System.out.println(res);
        }
    }

    private static long solve(long x0, long y0) {
        long S = 0, T = 0;
        for (int i = 0; i < n; ++i) {
            int l = (i + 1) % n;
            int r = (i + n-1) % n;
            int s1 = sgn(x[i], y[i], x0, y0, x[l], y[l]);
            int s2 = sgn(x[i], y[i], x0, y0, x[r], y[r]);
            if (s1 == s2 || s1 == 0 || s2 == 0) {
                return 0;
            }
            int sz = n-2;
            long left = 1;
            while (sz > 1) {
                int m = (l + sz/2) % n;
                if (sgn(x[i], y[i], x0, y0, x[l], y[l]) ==
                    sgn(x[i], y[i], x0, y0, x[m], y[m])) {
                    l = m;
                    left += sz/2;
                    sz -= sz/2;
                } else {
                    sz = sz/2;
                }
            }
            T += left * (n-1-left);
            S += left * (left-1) + (n-1-left) * (n-1-left-1);
        }

        return (T - S/4) / 3;
    }

    private static int sgn(long x1, long y1, long x2, long y2, long x3, long y3) {
        long d = (y2-y1) * (x3-x1) - (y3-y1) * (x2-x1);
        if (d > 0) return 1;
        else if (d < 0) return -1;
        else return 0;
    }
}