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 ll = long long;
using ld = long double;
using namespace std;
int a, b, n;
pair<int, int> A, B;
map<pair<int, int>, int> P2N;
map<int, vector<int> > P;
vector<vector<pair<int, int> > > N2P;
vector<set<pair<double, int> > > G;
double dist(int node) {
  if (N2P[node].size() == 2) {
    if (N2P[node][0].first == N2P[node][1].first) {
      if ((N2P[node][0].second <= B.second &&
           B.second <= N2P[node][1].second) ||
          (N2P[node][1].second <= B.second && B.second <= N2P[node][0].second))
        return abs(N2P[node][0].first - B.first);
    }
    if (N2P[node][0].second == N2P[node][1].second) {
      if ((N2P[node][0].first <= B.first && B.first <= N2P[node][1].first) ||
          (N2P[node][1].first <= B.first && B.first <= N2P[node][0].first))
        return abs(N2P[node][0].second - B.second);
    }
  }
  double result = 100000.0;
  for (auto Y : N2P[node]) {
    result = min(result,
                 sqrt(pow(B.first - Y.first, 2) + pow(B.second - Y.second, 2)));
  }
  return result;
}
void link(pair<int, int> X, pair<int, int> Y) {
  int node1 = P2N[X];
  int node2 = P2N[Y];
  if (node1 != node2) {
    if (node1 == n + 1) {
      G[node2].insert(make_pair(dist(node2), node1));
    } else if (node2 == n + 1) {
      G[node1].insert(make_pair(dist(node1), node2));
    } else {
      G[node1].insert(make_pair(a + b, node2));
      G[node2].insert(make_pair(a + b, node1));
    }
  }
}
void link(pair<int, int> X, int p, int marge) {
  for (auto it = lower_bound(P[p].begin(), P[p].end(), X.second - marge);
       it != P[p].end() && abs(*it - X.second) <= marge; ++it) {
    link(X, make_pair(p, *it));
  }
}
void linkv(pair<int, int> X, int x, int y2) {
  for (auto it = lower_bound(P[x].begin(), P[x].end(), X.second);
       it != P[x].end() && *it <= y2; ++it) {
    link(X, make_pair(x, *it));
  }
}
int main() {
  ios::sync_with_stdio(false);
  cout.precision(20);
  cin >> a >> b;
  cin >> A.first >> A.second >> B.first >> B.second;
  cin >> n;
  N2P.resize(n + 2);
  G.resize(n + 2);
  N2P[0].push_back(A);
  N2P[n + 1].push_back(B);
  P2N[A] = 0;
  P2N[B] = n + 1;
  P[A.first].push_back(A.second);
  P[B.first].push_back(B.second);
  for (int i = 0; i < n; i++) {
    pair<int, int> X, Y;
    cin >> X.first >> X.second >> Y.first >> Y.second;
    N2P[i + 1].push_back(X);
    N2P[i + 1].push_back(Y);
    P2N[X] = i + 1;
    P2N[Y] = i + 1;
    P[X.first].push_back(X.second);
    P[Y.first].push_back(Y.second);
  }
  vector<int> previous;
  for (auto it = P.begin(); it != P.end(); ++it) {
    sort(it->second.begin(), it->second.end());
    for (int i = 1; i < it->second.size(); ++i) {
      for (int j = i - 1; j >= 0 && it->second[i] - it->second[j] <= a; --j) {
        link(make_pair(it->first, it->second[i]),
             make_pair(it->first, it->second[j]));
      }
    }
    for (int i = 0; i < it->second.size(); ++i) {
      int x0 = it->first;
      for (int j = 0; j < N2P[P2N[make_pair(it->first, it->second[i])]].size();
           ++j) {
        x0 = min(x0, N2P[P2N[make_pair(it->first, it->second[i])]][j].first);
      }
      auto it2 = previous.rbegin();
      for (; it2 != previous.rend() && *it2 >= x0; it2++) {
        link(make_pair(it->first, it->second[i]), *it2, a);
      }
      for (; it2 != previous.rend() && x0 - *it2 <= a; it2++) {
        link(make_pair(it->first, it->second[i]), *it2,
             sqrt(a * a - pow(x0 - *it2, 2)));
      }
    }
    previous.push_back(it->first);
  }
  for (int k = 0; k < previous.size(); k++) {
    int x = previous[k];
    vector<int>& L = P[x];
    for (int i = 0; i < L.size(); ++i) {
      pair<int, int> X = make_pair(x, L[i]);
      int node = P2N[X];
      int y2 = max(N2P[node][0].second, N2P[node][1].second);
      if (N2P[node].size() == 2 && N2P[node][0].first == N2P[node][1].first &&
          L[i] != max(N2P[node][0].second, N2P[node][1].second)) {
        int y2 = max(N2P[node][0].second, N2P[node][1].second);
        for (int j = k - 1; j >= 0 && x - previous[j] <= a; j--) {
          linkv(X, previous[j], y2);
        }
        for (int j = k + 1; j < previous.size() && previous[j] - x <= a; j++) {
          linkv(X, previous[j], y2);
        }
      }
    }
  }
  vector<double> L(n + 2, -1);
  set<pair<double, int> > S;
  L[0] = 0;
  for (auto s : G[0]) {
    S.insert(s);
  }
  while (!S.empty()) {
    int node = S.begin()->second;
    double cost = S.begin()->first;
    S.erase(S.begin());
    if (L[node] == -1 || L[node] > cost) {
      L[node] = cost;
      for (auto s : G[node]) {
        S.insert(make_pair(s.first + cost, s.second));
      }
    }
  }
  cout << L[n + 1] << endl;
  return 0;
}