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.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class cf55e {
  static FastIO in = new FastIO(), out = in;

  public static void main(String[] args) {
    int n = in.nextInt();
    vec2[] p = new vec2[n];
    for(int i=0; i<n; i++)
      p[i] = new vec2(in.nextInt(),in.nextInt());
    int t = in.nextInt();
    for(int i=0; i<t; i++) {
      vec2 v = new vec2(in.nextInt(),in.nextInt());
      out.println(solve(p,v));
    }
    out.close();
  }
  static long solve(vec2[] p, vec2 v) {
    vec2[] newP = new vec2[p.length];
    for(int i=0; i<p.length; i++)
      newP[i] = p[i].sub(v);
    return solve(newP);
  }
  static long solve(vec2[] p) {
    int n = p.length;
    long ans = choose3(n);
    double tmp = 0;
    for(int i=0; i<n; i++)
      tmp -= p[i].angleBtwn(p[(i+1)%n]);
 //   System.out.println(tmp);
    if(Math.abs(tmp-2*Math.PI) > 1e-6) return 0;
    int cur = 0, sz = 0;
    for(int i=0; i<n; i++) {
      if(cur == i) {
        cur = (cur+1)%n;
        sz++;
      }
      while(cur != i && p[i].cross(p[cur%n]) < 0) {
        cur = (cur+1)%n;
        sz++;
      }
      ans -= choose2(sz-1);
      sz--;
    }
    return ans;
  }
  static long choose3(long x) {
    return (x*(x-1)*(x-2))/6;
  }
  static long choose2(long x) {
    return (x*(x-1))/2;
  }
  static class vec2 implements Comparable<vec2>{
    long x,y;
    vec2(long a, long b) {x=a;y=b;}
    vec2 add(vec2 rhs) {return new vec2(x+rhs.x,y+rhs.y);}
    vec2 sub(vec2 rhs) {return new vec2(x-rhs.x,y-rhs.y);}
    long dot(vec2 rhs) {return x*rhs.x+y*rhs.y;}
    long cross(vec2 rhs) {return x*rhs.y-y*rhs.x;}//pos->left,neg->right
    double angleBtwn(vec2 rhs) {return Math.atan2(cross(rhs),dot(rhs));}
    double angle() {return Math.atan2(y,x);}
    vec2 orthoCW() {return new vec2(y,-x);}
    vec2 orthoCCW() {return new vec2(-y,x);}
    //[cos(t)  -sin(t)][x] = [x*cos(t)-y*sin(t)   x*sin(t)+y*cos(t)]
    //[sin(t)   cos(t)][y]
    public int compareTo(vec2 rhs) {
      return Double.compare(angle(), rhs.angle());
    }
    public String toString() {
      return x+":"+y;
    }
  }
  static class FastIO extends PrintWriter {
    BufferedReader br;
    StringTokenizer st;

    public FastIO() {
      this(System.in, System.out);
    }

    public FastIO(InputStream in, OutputStream out) {
      super(new BufferedWriter(new OutputStreamWriter(out)));
      br = new BufferedReader(new InputStreamReader(in));
      scanLine();
    }

    public void scanLine() {
      try {
        st = new StringTokenizer(br.readLine().trim());
      } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
      }
    }

    public int numTokens() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return numTokens();
      }
      return st.countTokens();
    }

    public String next() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return next();
      }
      return st.nextToken();
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

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

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