#include <bits/stdc++.h>   using namespace std;   struct Point {     double x;     double y;     Point(double _x = 0, double _y = 0) : x(_x), y(_y) {}     double length() const { return sqrt(x * x + y * y); }     double distance(const Point& other) const {       return Point(x - other.x, y - other.y).length();     }   };   Point operator+(const Point& first, const Point& second) {     return Point(first.x + second.x, first.y + second.y);   }   Point operator-(const Point& first, const Point& second) {     return Point(first.x - second.x, first.y - second.y);   }   double vector_product(const Point& first, const Point& second) {     return first.x * second.y - first.y * second.x;   }   double scalar_product(const Point& first, const Point& second) {     return first.x * second.x + first.y * second.y;   }   struct Segment {     Point A;     Point B;     Segment() {}     Segment(const Point& _A, const Point& _B) : A(_A), B(_B) {}     double length() const;     double distance(const Point& C) const;     double distance(const Segment& S) const;   };   double Segment::length() const {     double dx = B.x - A.x;     double dy = B.y - A.y;     return sqrt(dx * dx + dy * dy);   }   double Segment::distance(const Point& C) const {     if (scalar_product(C - A, B - A) < 0 || scalar_product(C - B, A - B) < 0) {       return min(Segment(A, C).length(), Segment(B, C).length());     } else {       return fabs(vector_product(C - A, B - A)) / length();     }   }   double Segment::distance(const Segment& S) const {     double r = distance(S.A);     r = min(r, distance(S.B));     r = min(r, S.distance(A));     r = min(r, S.distance(B));     return r;   }   struct Arc {     int head;     double weight;     Arc() : head(-1), weight(0) {}     Arc(int to, double label) : head(to), weight(label) {}   };   enum VertexColor { WHITE = 0, GRAY, BLACK };   const double INF = 1000000000;   void dijkstra_on_array(const std::vector<std::vector<Arc> >& graph, int source,                          vector<double>& distance) {     vector<int> color(graph.size(), WHITE);     color[source] = GRAY;     distance.assign(graph.size(), INF);     distance[source] = 0;     for (int step = 0; step < graph.size(); ++step) {       int min_gray_vertex = 0;       double min_distance_to_gray = INF;       for (int vertex = 0; vertex < graph.size(); ++vertex) {         if (color[vertex] == GRAY && distance[vertex] < min_distance_to_gray) {           min_gray_vertex = vertex;           min_distance_to_gray = distance[vertex];         }       }       if (min_distance_to_gray == INF) {         break;       }       color[min_gray_vertex] = BLACK;       for (int arc_index = 0; arc_index < graph[min_gray_vertex].size();            ++arc_index) {         const Arc& arc = graph[min_gray_vertex][arc_index];         if (color[arc.head] != BLACK &&             distance[arc.head] > min_distance_to_gray + arc.weight) {           color[arc.head] = GRAY;           distance[arc.head] = min_distance_to_gray + arc.weight;         }       }     }   }   int main() {     double a, b;     cin >> a >> b;     Point A, B;     cin >> A.x >> A.y >> B.x >> B.y;     int n;     cin >> n;     vector<Segment> segments(n);     for (int i = 0; i < n; ++i) {       cin >> segments[i].A.x >> segments[i].A.y >> segments[i].B.x >>           segments[i].B.y;     }     std::vector<std::vector<Arc> > g(n + 2);     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         if (segments[i].distance(segments[j]) <= a + 1e-9) {           g[i].push_back(Arc(j, a + b));           g[j].push_back(Arc(i, a + b));         }       }     }     for (int i = 0; i < n; ++i) {       double da = segments[i].distance(A);       double db = segments[i].distance(B);       if (da <= a + 1e-9) {         g[n].push_back(Arc(i, a + b));       }       if (db <= a + 1e-9) {         g[i].push_back(Arc(n + 1, db));       }     }     if (A.distance(B) <= a + 1e-9) {       cout.precision(8);       cout << fixed << A.distance(B) << endl;     } else {       vector<double> d;       dijkstra_on_array(g, n, d);       if (d[n + 1] == INF) {         cout << -1 << endl;       } else {         cout.precision(8);         cout << fixed << d[n + 1] << endl;       }     }     return 0;   }