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>
struct point {
  int x, y;
};
enum segtype { vert, horiz };
struct segment {
  struct point p1, p2;
  double a, b, c, l;
  enum segtype type;
};
std::vector<std::vector<double> > g(1002, std::vector<double>(1002, 0));
double dest_points(struct point* p1, struct point* p2) {
  return sqrt((p1->x - p2->x) * (p1->x - p2->x) +
              (p1->y - p2->y) * (p1->y - p2->y));
}
double dest_pointseg(struct point* p, struct segment* s) {
  struct point closer;
  if (s->type == horiz) {
    if (s->p1.x <= p->x && p->x <= s->p2.x) {
      return abs(p->y - s->p1.y);
    } else {
      closer.x = (s->p2.x < p->x) ? s->p2.x : s->p1.x;
      closer.y = s->p1.y;
      return dest_points(&closer, p);
    }
  } else {
    if (s->p1.y <= p->y && p->y <= s->p2.y) {
      return abs(p->x - s->p1.x);
    } else {
      closer.y = (s->p2.y < p->y) ? s->p2.y : s->p1.y;
      closer.x = s->p1.x;
      return dest_points(&closer, p);
    }
  }
}
double dest_segseg(struct segment* s1, struct segment* s2) {
  struct segment* ps1 = s1;
  struct segment* ps2 = s2;
  struct segment* t;
  if (ps1->type != ps2->type) {
    if (ps1->type == horiz) {
      t = ps2;
      ps2 = ps1;
      ps1 = t;
    }
    if (ps1->p1.y <= ps2->p1.y && ps2->p1.y <= ps1->p2.y) {
      return std::min(abs(ps1->p1.x - ps2->p2.x), abs(ps1->p1.x - ps2->p1.x));
    } else if (ps2->p1.x <= ps1->p1.x && ps1->p1.x <= ps2->p2.x) {
      return std::min(abs(ps2->p1.y - ps1->p2.y), abs(ps2->p1.y - ps1->p1.y));
    } else {
      struct point p1, p2;
      if (ps1->p2.y < ps2->p1.y)
        p1 = ps1->p2;
      else
        p1 = ps1->p1;
      if (ps1->p2.x < ps2->p1.x)
        p2 = ps2->p1;
      else
        p2 = ps2->p2;
      return dest_points(&p1, &p2);
    }
  } else {
    if (ps1->type == horiz) {
      if (ps1->p1.x <= ps2->p1.x && ps2->p1.x <= ps1->p2.x ||
          ps1->p1.x <= ps2->p2.x && ps2->p2.x <= ps1->p2.x ||
          ps2->p1.x <= ps1->p1.x && ps1->p1.x <= ps2->p2.x ||
          ps2->p1.x <= ps1->p2.x && ps1->p2.x <= ps2->p2.x)
        return abs(ps1->p1.y - ps2->p1.y);
      else {
        struct point p1, p2;
        if (ps1->p1.x > ps2->p2.x) {
          p1 = ps2->p2;
          p2 = ps1->p1;
        } else {
          p1 = ps2->p1;
          p2 = ps1->p2;
        }
        return dest_points(&p1, &p2);
      }
    } else {
      if (ps1->p1.y <= ps2->p1.y && ps2->p1.y <= ps1->p2.y ||
          ps1->p1.y <= ps2->p2.y && ps2->p2.y <= ps1->p2.y ||
          ps2->p1.y <= ps1->p1.y && ps1->p1.y <= ps2->p2.y ||
          ps2->p1.y <= ps1->p2.y && ps1->p2.y <= ps2->p2.y)
        return abs(ps1->p1.x - ps2->p1.x);
      else {
        struct point p1, p2;
        if (ps1->p1.y > ps2->p2.y) {
          p1 = ps2->p2;
          p2 = ps1->p1;
        } else {
          p1 = ps2->p1;
          p2 = ps1->p2;
        }
        return dest_points(&p1, &p2);
      }
    }
  }
}
void fillsegment(struct segment* s) {
  s->type = (s->p1.x == s->p2.x) ? vert : horiz;
  if (s->p1.x > s->p2.x) std::swap(s->p1.x, s->p2.x);
  if (s->p1.y > s->p2.y) std::swap(s->p1.y, s->p2.y);
}
int main(int argc, char** argv) {
  int a, b;
  struct point pa, pb;
  scanf("%d %d", &a, &b);
  scanf("%d %d", &pa.x, &pa.y);
  scanf("%d %d", &pb.x, &pb.y);
  int n;
  scanf("%d", &n);
  int i, j;
  std::vector<struct segment> s(1000);
  struct segment seg;
  for (i = 0; i < n; i++) {
    scanf("%d %d %d %d", &seg.p1.x, &seg.p1.y, &seg.p2.x, &seg.p2.y);
    fillsegment(&seg);
    s[i] = seg;
  }
  double dest;
  for (i = 1; i <= n; i++) {
    dest = dest_pointseg(&pa, &s[i - 1]);
    if (dest <= a) {
      g[0][i] = dest;
      g[i][0] = dest;
    }
    dest = dest_pointseg(&pb, &s[i - 1]);
    if (dest <= a) {
      g[n + 1][i] = dest;
      g[i][n + 1] = dest;
    }
    for (j = i + 1; j <= n; j++) {
      dest = dest_segseg(&s[j - 1], &s[i - 1]);
      if (dest <= a) {
        g[j][i] = dest;
        g[i][j] = dest;
      }
    }
  }
  dest = dest_points(&pa, &pb);
  if (dest <= a) {
    g[0][n + 1] = dest;
    g[n + 1][0] = dest;
  }
  std::vector<double> d(1002, 1E+9), p(1002);
  std::vector<bool> u(1002, false);
  d[0] = 0;
  int v, minv;
  for (i = 0; i <= n + 1; i++) {
    v = -1;
    for (j = 0; j <= n + 1; j++) {
      if (!u[j] && (v == -1 || d[j] < d[v])) v = j;
    }
    if (d[v] == 1E+9) break;
    u[v] = true;
    for (j = 0; j <= n + 1; j++) {
      if (!g[v][j]) continue;
      if ((d[v] + 1 < d[j]) || (d[v] + 1 == d[j] && g[p[j]][j] > g[v][j])) {
        d[j] = d[v] + 1;
        p[j] = v;
      }
    }
  }
  if (d[n + 1] == 1E+9) {
    printf("-1\n");
  } else {
    printf("%.11f\n", (d[n + 1] - 1) * (a + b) + g[p[n + 1]][n + 1]);
  }
  return 0;
}