#include <bits/stdc++.h>
using namespace std;
struct vect {
  int x, y;
  vect() {}
  vect(int x, int y) : x(x), y(y) {}
  vect operator+(vect const &T) const { return vect(x + T.x, y + T.y); }
  vect operator-(vect const &T) const { return vect(x - T.x, y - T.y); }
  int operator%(vect const &T) const { return x * T.x + y * T.y; }
  int operator^(vect const &T) const { return x * T.y - y * T.x; }
  double len() { return sqrt((x * x + y * y) * 1.); }
  int len2() { return x * x + y * y; }
  bool operator<(vect const &T) const { return x == T.x ? y < T.y : x < T.x; }
  int get() { return scanf("%d%d", &x, &y); }
};
int ta, tb, n, t, hd, tl, q[1005], v[1005], G[1005][1005];
double ret;
vect st, ed, pa[1005], pb[1005];
int sqr(int x) { return x * x; }
int DPS(vect p, vect L1, vect L2) {
  if ((L2 - L1) % (p - L1) < 0 || (L1 - L2) % (p - L2) < 0)
    return min((p - L1).len2(), (p - L2).len2());
  if (L1.x == L2.x)
    return sqr(L1.x - p.x);
  else
    return sqr(L1.y - p.y);
}
int DSS(vect a, vect b, vect c, vect d) {
  return min(min(DPS(a, c, d), DPS(b, c, d)), min(DPS(c, a, b), DPS(d, a, b)));
}
int main() {
  scanf("%d%d", &ta, &tb);
  st.get();
  ed.get();
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) {
    pa[i].get(), pb[i].get();
    for (int j = (0); j < (i); j++)
      if (DSS(pa[i], pb[i], pa[j], pb[j]) <= ta * ta) G[i][j] = G[j][i] = 1;
  }
  if ((ed - st).len2() <= ta * ta) {
    printf("%.9f\n", (ed - st).len());
    return 0;
  }
  memset(v, -1, sizeof(v));
  hd = 0, tl = -1;
  for (int i = (0); i < (n); i++) {
    if (DPS(st, pa[i], pb[i]) <= ta * ta) v[i] = 1, q[++tl] = i;
  }
  while (tl >= hd) {
    for (int i = (0); i < (n); i++)
      if (v[i] == -1 && G[q[hd]][i]) v[q[++tl] = i] = v[q[hd]] + 1;
    ++hd;
  }
  ret = 1e20;
  for (int i = (0); i < (n); i++) {
    t = DPS(ed, pa[i], pb[i]);
    if (t <= ta * ta && v[i] != -1) {
      ret = min(ret, v[i] * (ta + tb) + sqrt(t));
    }
  }
  if (ret > 1e19)
    puts("-1");
  else
    printf("%.9f\n", ret);
  return 0;
}
