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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E55 solver = new E55();
        solver.solve(1, in, out);
        out.close();
    }

    static class E55 {
        int N;
        int T;
        Point[] p;
        Point P;

        boolean legal(int x, int y) {
            Vec A = new Vec(p[x], p[y]);
            Vec B = new Vec(p[x], P);
            return !A.cross(B);
        }

        public void solve(int testNumber, FastScanner s, PrintWriter out) {

            N = s.nextInt();
            p = new Point[N];
            for (int i = 0; i < N; i++) {
                p[i] = new Point(s.nextLong(), s.nextLong());
            }

            T = s.nextInt();
            for (int t = 0; t < T; t++) {
                long ans = (1L * N * (N - 1) * (N - 2)) / 6;
                P = new Point(s.nextLong(), s.nextLong());
                int y = 0;
                for (int x = 0; x < N; x++) {
                    while (legal(x, (y + 1) % N))
                        y = (y + 1) % N;
                    long diff = (y - x + N) % N;
                    ans -= (diff * (diff - 1)) / 2;
                }
                out.println(Math.max(ans, 0L));
            }


        }

        class Point {
            long x;
            long y;

            Point(long xx, long yy) {
                x = xx;
                y = yy;
            }

        }

        class Vec {
            long dx;
            long dy;

            Vec(Point U, Point V) {
                dx = V.x - U.x;
                dy = V.y - U.y;
            }

            boolean cross(Vec A) {
                return dx * A.dy - dy * A.dx >= 0;
            }

        }

    }

    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

    }
}