Problem: Vasya lagged behind at the University and got to the battlefield. Just joking! He's simply playing some computer game. The field is a flat platform with n trenches dug on it. The trenches are segments on a plane parallel to the coordinate axes. No two trenches intersect.

There is a huge enemy laser far away from Vasya. The laser charges for a seconds, and then shoots continuously for b seconds. Then, it charges for a seconds again. Then it shoots continuously for b seconds again and so on. Vasya knows numbers a and b. He also knows that while the laser is shooting, Vasya must be in the trench, but while the laser is charging, Vasya can safely move around the field. The main thing is to have time to hide in the trench before the shot. If Vasya reaches the trench exactly at the moment when the laser starts shooting, we believe that Vasya managed to hide. Coincidentally, the length of any trench in meters numerically does not exceed b.

Initially, Vasya is at point A. He needs to get to point B. Vasya moves at speed 1 meter per second in either direction. You can get in or out of the trench at any its point. Getting in or out of the trench takes no time. It is also possible to move in the trench, without leaving it.

What is the minimum time Vasya needs to get from point A to point B, if at the initial time the laser has just started charging? If Vasya cannot get from point A to point B, print -1. If Vasya reaches point B at the moment when the laser begins to shoot, it is believed that Vasya managed to reach point B.

Input

The first line contains two space-separated integers: a and b (1 ≤ a, b ≤ 1000), — the duration of charging and the duration of shooting, in seconds.

The second line contains four space-separated integers: Ax, Ay, Bx, By ( - 104 ≤ Ax, Ay, Bx, By ≤ 104) — the coordinates of points А and B. It is guaranteed that points A and B do not belong to any trench.

The third line contains a single integer: n (1 ≤ n ≤ 1000), — the number of trenches. 

Each of the following n lines contains four space-separated integers: x1, y1, x2, y2 ( - 104 ≤ xi, yi ≤ 104) — the coordinates of ends of the corresponding trench.

All coordinates are given in meters. It is guaranteed that for any trench either x1 = x2, or y1 = y2. No two trenches intersect. The length of any trench in meters doesn't exceed b numerically.

Output

If Vasya can get from point A to point B, print the minimum time he will need for it. Otherwise, print number -1.

The answer will be considered correct if the absolute or relative error does not exceed 10 - 4

Examples

Input

2 4
0 5 6 5
3
0 0 0 4
1 1 4 1
6 0 6 4


Output

19.0000000000


Input

5 10
0 0 10 10
1
5 0 5 9


Output

-1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using DBL = long double;
const DBL PI = acosl(DBL(-1));
const DBL INF = 1e20;
const DBL EPS = 1e-8;
inline DBL sqr(DBL x) { return x * x; }
inline int sgn(DBL x) { return (x > EPS) - (x < (-EPS)); }
inline int cmp(DBL x, DBL y) { return sgn((x - y) / max(DBL(1), fabsl(x))); }
struct point {
  DBL x, y;
  point() {}
  point(DBL x, DBL y) : x(x), y(y) {}
  void input() {
    int _x, _y;
    scanf("%d%d", &_x, &_y);
    x = _x, y = _y;
  }
  bool operator<(const point &p) const {
    if (fabsl(x - p.x) > EPS) return x < p.x;
    return y + EPS < p.y;
  }
  bool operator==(const point &p) const {
    return fabsl(x - p.x) < EPS && fabsl(y - p.y) < EPS;
  }
};
point operator+(point p1, point p2) { return point(p1.x + p2.x, p1.y + p2.y); }
point operator-(point p1, point p2) { return point(p1.x - p2.x, p1.y - p2.y); }
point operator*(point p, DBL c) { return point(p.x * c, p.y * c); }
point operator/(point p, DBL c) { return point(p.x / c, p.y / c); }
DBL dis(point p) { return sqrtl(sqr(p.x) + sqr(p.y)); }
DBL dis(point p1, point p2) { return dis(p1 - p2); }
DBL dis2(point p) { return sqr(p.x) + sqr(p.y); }
DBL dis2(point p1, point p2) { return dis2(p1 - p2); }
DBL vect(point p1, point p2) { return p1.x * p2.y - p2.x * p1.y; }
DBL vect(point p, point p1, point p2) { return vect(p1 - p, p2 - p); }
DBL scal(point p1, point p2) { return p1.x * p2.x + p1.y * p2.y; }
DBL scal(point p, point p1, point p2) { return scal(p1 - p, p2 - p); }
DBL getAngle(point p) { return atan2l(p.y, p.x); }
DBL getAngle(point p, point p1, point p2) {
  return acosl(scal(p, p1, p2) / dis(p - p1) / dis(p - p2));
}
point normalize(point p) { return p / dis(p); }
point virt(point p) { return point(-p.y, p.x); }
point rot(point p, DBL t) {
  return point(p.x * cos(t) - p.y * sin(t), p.x * sin(t) + p.y * cos(t));
}
point polar(point p, DBL r, DBL t) {
  return point(p.x + r * cos(t), p.y + r * sin(t));
}
point projection(point a, point b, point p) {
  return a + (a - b) * (scal(p - a, a - b) / dis2(a - b));
}
DBL disToLine(point p, point p1, point p2) {
  return fabsl(vect(p, p1, p2)) / dis(p1, p2);
}
DBL disToSeg(point p, point p1, point p2) {
  if (scal(p1, p, p2) < 0) return dis(p, p1);
  if (scal(p2, p, p1) < 0) return dis(p, p2);
  return disToLine(p, p1, p2);
}
bool onLine(point p, point p1, point p2) {
  return fabsl(vect(p1 - p, p2 - p)) < EPS;
}
bool onSeg(point p, point p1, point p2) {
  if (!onLine(p, p1, p2)) return 0;
  return (p1.x - p.x) * (p2.x - p.x) < EPS && (p1.y - p.y) * (p2.y - p.y) < EPS;
}
bool cross(point p1, point p2, point p3, point p4) {
  return vect(p1, p2, p3) * vect(p1, p2, p4) < -EPS &&
         vect(p3, p4, p1) * vect(p3, p4, p2) < -EPS;
}
bool common(point p1, point p2, point p3, point p4) {
  if (max(p1.x, p2.x) + EPS < min(p3.x, p4.x) ||
      max(p3.x, p4.x) + EPS < min(p1.x, p2.x))
    return 0;
  if (max(p1.y, p2.y) + EPS < min(p3.y, p4.y) ||
      max(p3.y, p4.y) + EPS < min(p1.y, p2.y))
    return 0;
  return vect(p1, p2, p3) * vect(p1, p2, p4) < EPS &&
         vect(p3, p4, p1) * vect(p3, p4, p2) < EPS;
}
int posLineLine(point p1, point p2, point p3, point p4, point &p) {
  DBL s1 = vect(p1, p2, p3), s2 = vect(p1, p2, p4);
  if (fabsl(s1 - s2) < EPS) {
    if (fabsl(s1) < EPS) return 2;
    return 0;
  }
  p = p3 + (p4 - p3) * (s1 / (s1 - s2));
  return 1;
}
int posCirLine(point p, DBL r, point p1, point p2, point *q) {
  DBL a = dis2(p1 - p2);
  DBL b = scal(p1, p, p2);
  DBL c = dis2(p - p1) - sqr(r);
  DBL d2 = sqr(b) - a * c;
  if (d2 < -EPS) return 0;
  DBL d = sqrtl(fabsl(d2));
  q[0] = p1 + (p2 - p1) * ((b + d) / a);
  q[1] = p1 + (p2 - p1) * ((b - d) / a);
  if (d2 < EPS) return 1;
  return 2;
}
int posCirCir(point p1, DBL r1, point p2, DBL r2, point *q) {
  if (p1 == p2) return 0;
  DBL dx = p2.x - p1.x, dy = p2.y - p1.y;
  DBL d = dis(p1 - p2);
  DBL e = (sqr(r1) - sqr(r2) + sqr(d)) / 2 / d;
  DBL f2 = sqr(r1) - sqr(e);
  if (f2 < -EPS) return 0;
  DBL f = sqrtl(fabsl(f2));
  q[0] = point(p1.x + (e * dx - f * dy) / d, p1.y + (e * dy + f * dx) / d);
  q[1] = point(p1.x + (e * dx + f * dy) / d, p1.y + (e * dy - f * dx) / d);
  if (f2 < EPS) return 1;
  return 2;
}
vector<point> convex_hull(vector<point> ps) {
  if ((int)ps.size() <= 1) return ps;
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  vector<point> ch(2 * n);
  for (int i = 0; i < n; ch[k++] = ps[i++])
    while (k >= 2 && vect(ch[k - 2], ch[k - 1], ps[i]) < EPS) --k;
  for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
    while (k >= t && vect(ch[k - 2], ch[k - 1], ps[i]) < EPS) --k;
  ch.resize(k - 1);
  return ch;
}
const int maxn = 1010;
struct segment {
  point A, B;
  segment() {}
  segment(point A, point B) : A(A), B(B) {}
  void input() {
    A.input();
    B.input();
  }
} seg[maxn];
DBL segToseg(segment A, segment B) {
  DBL v1 = min(disToSeg(A.A, B.A, B.B), disToSeg(A.B, B.A, B.B));
  DBL v2 = min(disToSeg(B.A, A.A, A.B), disToSeg(B.B, A.A, A.B));
  return min(v1, v2);
}
int n, a, b;
point st, en;
int q[maxn], qh, qt;
int vis[maxn];
int di[maxn];
int main() {
  scanf("%d%d", &a, &b);
  st.input();
  en.input();
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    seg[i].input();
    di[i] = 0x3f3f3f3f;
  }
  qh = qt = 0;
  DBL d = dis(st, en);
  DBL ans = 1e20;
  if (sgn(d - (DBL)a) <= 0) {
    printf("%.20Lf\n", d);
  } else {
    for (int i = 0; i < n; i++) {
      DBL d = disToSeg(st, seg[i].A, seg[i].B);
      if (sgn(d - (DBL)a) <= 0) {
        q[qt++] = i;
        di[i] = 1;
        vis[i] = 1;
      }
    }
    bool reach = false;
    while (qh < qt) {
      int f = q[qh++];
      for (int i = 0; i < n; i++) {
        if (vis[i]) continue;
        DBL d = segToseg(seg[f], seg[i]);
        if (sgn(d - (DBL)a) <= 0) {
          q[qt++] = i;
          di[i] = di[f] + 1;
          vis[i] = 1;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (!vis[i]) continue;
      DBL d = disToSeg(en, seg[i].A, seg[i].B);
      if (sgn(d - (DBL)a) <= 0) {
        reach = true;
        if (ans > (DBL)di[i] * (a + b) + d) ans = (DBL)di[i] * (a + b) + d;
      }
    }
    if (reach)
      printf("%.20Lf\n", ans);
    else
      puts("-1");
  }
}