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.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start(); 
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");
	
	int N;
	Point[] poly;
	Point bad;
	long area = 0L;
	
	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		
		N = nextInt();
		poly = new Point [N];
		for (int i = 0; i < N; i++)
			poly[i] = new Point(nextLong(), nextLong());
		for (int i = 0; i < N; i++)
			area += cross(poly[i], poly[next(i)]);
		area = abs(area);
		for (int T = nextInt(); T --> 0; ) {
			bad = new Point(nextLong(), nextLong());
			out.println(solve());
		}
		
		out.close();
	}
	
	long solve() {
		long n = N - 1L;
		long sub = 0L;
		long add = 0L;
		
		long sum = 0L;
		for (int i = 0; i < N; i++)
			sum += abs(cross(poly[i].sub(bad), poly[next(i)].sub(bad)));
		if (area != sum)
			return 0L;
		for (int i = 0, j = next(i), k = 1; i < N; ) {
			Point v = bad.sub(poly[i]);
			while (next(j) != i && Long.signum(cross(v, poly[next(j)].sub(poly[i]))) > 0L) {
				j = next(j);
				k++;
			}
//			System.out.printf("%d: j = %d, k = %d, add = %d, sub = %d%n", i, j, k, n * (n - 1L) / 2L, k * (k - 1L) / 2L);
			add += n * (n - 1L) / 2L;
			sub += k * (k - 1L) / 2L;
			if (++i == j)
				j = next(j);
			else
				k--;
		}
//		System.out.println(add + " " + sub);
		return add / 3 - sub;
	}

	long cross(Point p1, Point p2) {
		return p1.x * p2.y - p2.x * p1.y;
	}

	int next(int i) {
		return (i + 1) % N;
	}

	class Point {
		long x;
		long y;
		
		Point(long x, long y) {
			this.x = x;
			this.y = y;
		}
		
		Point sub(Point v) {
			return new Point(x - v.x, y - v.y);
		}
		
		@Override
		public String toString() {
			return String.format("(%d, %d)", x, y);
		}
	}
	
	String nextToken() throws IOException {
		while (!st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		
		return st.nextToken();
	}
	
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			
			if (s == null) {
				return true;
			}
			
			st = new StringTokenizer(s);
		}
		
		return false;
	}
}