Problem: Given simple (without self-intersections) n-gon. It is not necessary convex. Also you are given m lines. For each line find the length of common part of the line and the n-gon.

The boundary of n-gon belongs to polygon. It is possible that n-gon contains 180-degree angles.

Input

The first line contains integers n and m (3 ≤ n ≤ 1000;1 ≤ m ≤ 100). The following n lines contain coordinates of polygon vertices (in clockwise or counterclockwise direction). All vertices are distinct.

The following m lines contain line descriptions. Each of them contains two distict points of a line by their coordinates.

All given in the input coordinates are real numbers, given with at most two digits after decimal point. They do not exceed 105 by absolute values.

Output

Print m lines, the i-th line should contain the length of common part of the given n-gon and the i-th line. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

Examples

Input

4 3
0 0
1 0
1 1
0 1
0 0 1 1
0 0 0 1
0 0 1 -1


Output

1.41421356237309514547
1.00000000000000000000
0.00000000000000000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct point {
  long long int x, y;
  point() {}
  point(long long int inx, long long int iny) {
    x = inx;
    y = iny;
  }
};
point operator-(point p1, point p2) {
  p1.x -= p2.x;
  p1.y -= p2.y;
  return p1;
}
long long int prodvec(point p1, point p2) { return p1.x * p2.y - p1.y * p2.x; }
long long int prodesc(point p1, point p2) { return p1.x * p2.x + p1.y * p2.y; }
point rotar(point a, point p) { return point(prodesc(a, p), prodvec(a, p)); }
long double abs(point p) {
  long double x = p.x;
  long double y = p.y;
  return sqrt(x * x + y * y);
}
long long int leer() {
  long double x;
  cin >> x;
  return round(x * 100);
}
point leerpunto() {
  long long int x = leer();
  long long int y = leer();
  return point(x, y);
}
int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  int n, casos;
  cin >> n >> casos;
  vector<point> v(n);
  for (int i = 0; i < n; i++) v[i] = leerpunto();
  for (int caso = 0; caso < casos; caso++) {
    point p = leerpunto();
    point q = leerpunto();
    point d = q - p;
    long double modulod = abs(d);
    vector<point> w(n);
    vector<long double> xx(n), yy(n);
    for (int i = 0; i < n; i++) {
      w[i] = rotar(d, v[i] - p);
      if (w[i].x != 0 or w[i].y != 0) {
        xx[i] = w[i].x;
        yy[i] = w[i].y;
      } else {
        xx[i] = yy[i] = 0;
      }
    }
    vector<pair<long double, int> > lista;
    for (int i = 0; i < n; i++) {
      int nexti = (i + 1) % n;
      int anti = (i - 1 + n) % n;
      point p = w[i];
      point antp = w[anti];
      point nextp = w[nexti];
      if ((p.y < 0 and 0 < nextp.y) or (nextp.y < 0 and 0 < p.y)) {
        long double x = xx[i];
        long double y = yy[i];
        long double nextx = xx[nexti];
        long double nexty = yy[nexti];
        lista.push_back(pair<long double, int>(
            x + (nextx - x) * abs(y) / abs(y - nexty), 0));
      } else if (p.y == 0) {
        long double x = xx[i];
        if (antp.y < 0) {
          if (nextp.y > 0) {
            lista.push_back(pair<long double, int>(x, 0));
          } else if (nextp.y == 0) {
            lista.push_back(pair<long double, int>(x, -1));
          }
        } else if (antp.y > 0) {
          if (nextp.y < 0) {
            lista.push_back(pair<long double, int>(x, 0));
          } else if (nextp.y == 0) {
            lista.push_back(pair<long double, int>(x, 1));
          }
        } else if (nextp.y < 0) {
          lista.push_back(pair<long double, int>(x, -1));
        } else if (nextp.y > 0) {
          lista.push_back(pair<long double, int>(x, 1));
        }
      }
    }
    sort(lista.begin(), lista.end());
    bool dentro = false;
    long double antx;
    long double sol = 0;
    for (int i = 0; i < int(lista.size()); i++) {
      long double x = lista[i].first;
      int s = lista[i].second;
      if (dentro) sol += x - antx;
      if (s == 0) {
        dentro = not dentro;
      } else {
        sol += lista[i + 1].first - x;
        dentro = dentro xor (lista[i + 1].second != s);
        i++;
      }
      antx = lista[i].first;
    }
    cout << sol / (100.0 * modulod) << endl;
  }
}