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;
vector<int> v[1010];
queue<int> q;
bool check(int X1_1, int Y1_1, int X1_2, int Y1_2, int X2_1, int Y2_1, int X2_2,
           int Y2_2, int maxdist) {
  int mini = maxdist * maxdist + 1;
  int dist1 = (X1_1 - X2_1) * (X1_1 - X2_1) + (Y1_1 - Y2_1) * (Y1_1 - Y2_1);
  int dist2 = (X1_1 - X2_2) * (X1_1 - X2_2) + (Y1_1 - Y2_2) * (Y1_1 - Y2_2);
  int dist3 = (X1_2 - X2_1) * (X1_2 - X2_1) + (Y1_2 - Y2_1) * (Y1_2 - Y2_1);
  int dist4 = (X1_2 - X2_2) * (X1_2 - X2_2) + (Y1_2 - Y2_2) * (Y1_2 - Y2_2);
  mini = min(min(dist1, dist2), min(dist3, dist4));
  if (X1_1 > X1_2) {
    swap(X1_1, X1_2);
    swap(Y1_1, Y1_2);
  }
  if (X2_1 > X2_2) {
    swap(X2_1, X2_2);
    swap(Y2_1, Y2_2);
  }
  int dist5 = maxdist * maxdist + 1;
  if (X1_1 <= X2_1 && X1_2 >= X2_1 || X1_1 <= X2_2 && X1_2 >= X2_2 ||
      X2_1 <= X1_1 && X2_2 >= X1_1 || X2_1 <= X1_2 && X2_2 >= X1_2)
    dist5 =
        min(min((Y1_1 - Y2_1) * (Y1_1 - Y2_1), (Y1_1 - Y2_2) * (Y1_1 - Y2_2)),
            min((Y1_2 - Y2_1) * (Y1_2 - Y2_1), (Y1_2 - Y2_2) * (Y1_2 - Y2_2)));
  if (Y1_1 > Y1_2) {
    swap(X1_1, X1_2);
    swap(Y1_1, Y1_2);
  }
  if (Y2_1 > Y2_2) {
    swap(X2_1, X2_2);
    swap(Y2_1, Y2_2);
  }
  int dist6 = maxdist * maxdist + 1;
  if (Y1_1 <= Y2_1 && Y1_2 >= Y2_1 || Y1_1 <= Y2_2 && Y1_2 >= Y2_2 ||
      Y2_1 <= Y1_1 && Y2_2 >= Y1_1 || Y2_1 <= Y1_2 && Y2_2 >= Y1_2)
    dist6 =
        min(min((X1_1 - X2_1) * (X1_1 - X2_1), (X1_1 - X2_2) * (X1_1 - X2_2)),
            min((X1_2 - X2_1) * (X1_2 - X2_1), (X1_2 - X2_2) * (X1_2 - X2_2)));
  if (dist5 < mini) mini = dist5;
  if (dist6 < mini) mini = dist6;
  if (mini > maxdist * maxdist) return false;
  return true;
}
double getdist(int X1_1, int Y1_1, int X1_2, int Y1_2, int X2_1, int Y2_1,
               int X2_2, int Y2_2) {
  int mini = 1000000000;
  int dist1 = (X1_1 - X2_1) * (X1_1 - X2_1) + (Y1_1 - Y2_1) * (Y1_1 - Y2_1);
  int dist2 = (X1_1 - X2_2) * (X1_1 - X2_2) + (Y1_1 - Y2_2) * (Y1_1 - Y2_2);
  int dist3 = (X1_2 - X2_1) * (X1_2 - X2_1) + (Y1_2 - Y2_1) * (Y1_2 - Y2_1);
  int dist4 = (X1_2 - X2_2) * (X1_2 - X2_2) + (Y1_2 - Y2_2) * (Y1_2 - Y2_2);
  mini = min(min(dist1, dist2), min(dist3, dist4));
  if (X1_1 > X1_2) {
    swap(X1_1, X1_2);
    swap(Y1_1, Y1_2);
  }
  if (X2_1 > X2_2) {
    swap(X2_1, X2_2);
    swap(Y2_1, Y2_2);
  }
  int dist5 = 1000000000;
  if (X1_1 <= X2_1 && X1_2 >= X2_1 || X1_1 <= X2_2 && X1_2 >= X2_2 ||
      X2_1 <= X1_1 && X2_2 >= X1_1 || X2_1 <= X1_2 && X2_2 >= X1_2)
    dist5 =
        min(min((Y1_1 - Y2_1) * (Y1_1 - Y2_1), (Y1_1 - Y2_2) * (Y1_1 - Y2_2)),
            min((Y1_2 - Y2_1) * (Y1_2 - Y2_1), (Y1_2 - Y2_2) * (Y1_2 - Y2_2)));
  if (Y1_1 > Y1_2) {
    swap(X1_1, X1_2);
    swap(Y1_1, Y1_2);
  }
  if (Y2_1 > Y2_2) {
    swap(X2_1, X2_2);
    swap(Y2_1, Y2_2);
  }
  int dist6 = 1000000000;
  if (Y1_1 <= Y2_1 && Y1_2 >= Y2_1 || Y1_1 <= Y2_2 && Y1_2 >= Y2_2 ||
      Y2_1 <= Y1_1 && Y2_2 >= Y1_1 || Y2_1 <= Y1_2 && Y2_2 >= Y1_2)
    dist6 =
        min(min((X1_1 - X2_1) * (X1_1 - X2_1), (X1_1 - X2_2) * (X1_1 - X2_2)),
            min((X1_2 - X2_1) * (X1_2 - X2_1), (X1_2 - X2_2) * (X1_2 - X2_2)));
  if (dist5 < mini) mini = dist5;
  if (dist6 < mini) mini = dist6;
  return sqrt((double)mini);
}
int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  int Bx, By;
  int transh[1010][4];
  scanf("%d %d %d %d", &transh[0][0], &transh[0][1], &Bx, &By);
  transh[0][2] = transh[0][0];
  transh[0][3] = transh[0][1];
  int n;
  scanf("%d", &n);
  transh[n + 1][0] = Bx;
  transh[n + 1][1] = By;
  transh[n + 1][2] = Bx;
  transh[n + 1][3] = By;
  for (int i = 1; i <= n; i++)
    scanf("%d %d %d %d", &transh[i][0], &transh[i][1], &transh[i][2],
          &transh[i][3]);
  for (int i = 0; i <= n; i++) {
    for (int j = i + 1; j <= n + 1; j++) {
      if (check(transh[i][0], transh[i][1], transh[i][2], transh[i][3],
                transh[j][0], transh[j][1], transh[j][2], transh[j][3], a)) {
        v[i].push_back(j);
        v[j].push_back(i);
      }
    }
  }
  double answer = 1000000000.0;
  q.push(0);
  int steps = 0;
  bool visited[1010];
  for (int i = 0; i < 1010; i++) visited[i] = false;
  visited[0] = true;
  while (!q.empty() && steps <= n + 5) {
    for (int i = 0, j = q.size(); i < j; i++) {
      int x = q.front();
      q.pop();
      for (int k = 0, maxi = v[x].size(); k < maxi; k++) {
        if (v[x][k] == n + 1)
          answer = min(answer, (double)steps * (double)(a + b) +
                                   getdist(transh[x][0], transh[x][1],
                                           transh[x][2], transh[x][3],
                                           transh[n + 1][0], transh[n + 1][1],
                                           transh[n + 1][2], transh[n + 1][3]));
        if (!visited[v[x][k]]) q.push(v[x][k]);
        visited[v[x][k]] = true;
      }
    }
    if (answer < 999999999.0) break;
    steps++;
  }
  if (steps >= n + 3 || q.empty())
    printf("-1\n");
  else
    printf("%lf\n", answer);
  return 0;
}