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.*;
import java.util.*;

public class e {
public static void main(String[] args) throws IOException {
	input.init(System.in);
	PrintWriter out = new PrintWriter(System.out);
	int n = input.nextInt();
	long[] xs = new long[n], ys = new long[n];
	Point[] p = new Point[n];
	for(int i = 0; i<n; i++)
	{
		xs[i] = input.nextLong();
		ys[i] = input.nextLong();
		p[i] = new Point(xs[i], ys[i]);
	}
	Piplup pip = new Piplup(p);
	int T = input.nextInt();
	for(int t = 0; t<T; t++)
	{
		long x = input.nextLong(), y = input.nextLong();
		Point pp = new Point(x, y);
		if(!pip.query(pp))
		{
			out.println(0);
			continue;
		}
		int j = 0;
		long res = (long)n*(n-1)*(n-2)/6;
		long bad = 0;
		for(int i = 0; i<n; i++)
		{
			while(j == i || (xs[j] - xs[i]) * (y - ys[i]) - (x - xs[i]) * (ys[j] - ys[i]) < 0) j = (j+1)%n;
			int diff = j - i;
			if(diff < 0) diff += n;
			//out.println(i+" "+diff);
			bad += (long)(diff - 1) * (diff - 2) / 2;
		}
		out.println(res - bad);
	}
	out.close();
}
static class Piplup
{
	Point[] upper, lower;
	Piplup(Point[] p)
	{
		findHull(p);
		for(int i = 0; i<(upper.length+1)/2; i++)
		{
			Point temp = upper[i];
			upper[i] = upper[upper.length-1-i];
			upper[upper.length-1-i] = temp;
		}
	}
	/*
	 * Returns true if p is strictly inside the polygon and false otherwise.
	 */
	boolean query(Point p)
	{
		if(p.x <= upper[0].x || p.x >= upper[upper.length-1].x) return false;
		return above(lower, p) == 1 && above(upper, p) == -1;
	}
	int above(Point[] hull, Point p)
	{
		int lo = 0, hi = hull.length-1;
		while(true)
		{
			int mid = (lo+hi)/2;
			if(p.x >= hull[mid].x && p.x <= hull[mid+1].x) 
				return (int)Math.signum(hull[mid+1].minus(hull[mid]).cross(p.minus(hull[mid])));
			else if(p.x >= hull[mid].x) lo = mid;
			else hi = mid;
		}
	}
	void findHull( Point[] points)
	{
		int n = points.length;
		Arrays.sort( points);
		lower = new Point[2 * n];
		upper = new Point[2*n];
		int k = 0, start = 0;
		for(int i = 0; i < n; i ++)
		{
			Point p = points[i];
			while(k-start >= 2 && p.minus(lower[k-1]).cross(p.minus(lower[k-2])) >= 0)
				k--;
			lower[k++] = p; 
		}
		lower = Arrays.copyOf(lower, k);
		start = 0;
		k = 0;
		for(int i = n-1 ; i >= 0 ; i --)
		{
			Point p = points[i];
			while(k - start >= 2 && p.minus(upper[k-1]).cross(p.minus(upper[k-2])) >= 0)
				k--;
			upper[k++] = p; 
		}
		upper = Arrays.copyOf(upper, k);
	}
}
static class Point implements Comparable<Point>
{
	long x, y;
	public Point(long xx, long yy)
	{
		x = xx; y = yy;
	}
	long cross(Point p)
	{
		return x * p.y - y*p.x;
	}
	Point minus(Point p)
	{
		return new Point(x-p.x, y-p.y);
	}
	public int compareTo(Point o) {
		if(x != o.x) return Double.compare(x, o.x);
		return Double.compare(y, o.y);
	}
}
public static class input {
	static BufferedReader reader;
	static StringTokenizer tokenizer;

	static void init(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

	static String next() throws IOException {
		while (!tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(reader.readLine());
		return tokenizer.nextToken();
	}

	static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
}
}