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 JAVA):

Solution:
import java.util.*;
import java.io.*;

public class Main {

    static final int MAXN = 1024;
    double a, b, Ax, Ay, Bx, By;
    Point A, B;
    Point[] p1 = new Point[MAXN];
    Point[] p2 = new Point[MAXN];
    boolean[] vist = new boolean[MAXN];
    int[] step = new int[MAXN];

    public void run() {
        a = cin.nextInt();
        b = cin.nextInt();
        Ax = cin.nextInt();
        Ay = cin.nextInt();
        
        Bx = cin.nextInt();
        By = cin.nextInt();
        
        A = new Point(Ax, Ay);
        B = new Point(Bx, By);
        int n = cin.nextInt();
        for (int i = 0; i < n; ++i) {
            int x1 = cin.nextInt();
            int y1 = cin.nextInt();
            int x2 = cin.nextInt();
            int y2 = cin.nextInt();
            p1[i] = new Point(x1, y1);
            p2[i] = new Point(x2, y2);
        }
        //a += Point.EPS;
        if (Point.distance(A, B) <= a + Point.EPS) {
            out.println(Point.distance(A, B));
            return;
        }
        Queue<Integer> Q = new LinkedList<Integer>();
        for (int i = 0; i < n; ++i) {
            //out.println(Point.disptoseg(A, p1[i], p2[i]));
            //out.println(A.x + " " + A.y + " " + p1[i].x + " " + p1[i].y + " " + p2[i].x + " " + p2[i].y);
            if (Point.disptoseg(A, p1[i], p2[i]) <= a + Point.EPS) {
                Q.add(i);
                vist[i] = true;
                step[i] = 1;
            }
        }
        double ans = -1;
        while (!Q.isEmpty()) {
            int id = Q.poll();
            if (Point.disptoseg(B, p1[id], p2[id]) <= a + Point.EPS) {
                if (ans == -1) {
                    ans = step[id] * (a + b) + Point.disptoseg(B, p1[id], p2[id]);
                } else {
                    ans = Math.min(ans, step[id] * (a + b) + Point.disptoseg(B, p1[id], p2[id]));
                }
            }
            for (int i = 0; i < n; ++i) {
                if (vist[i]) continue;
                boolean flag = false;
                if (Point.disptoseg(p1[i], p2[id], p1[id]) <= a + Point.EPS) {
                    flag = true;
                } else if (Point.disptoseg(p2[i], p2[id], p1[id]) <= a + Point.EPS) {
                    flag = true;
                } else if (Point.disptoseg(p1[id], p1[i], p2[i]) <= a + Point.EPS) {
                    flag = true;
                } else if (Point.disptoseg(p2[id], p1[i], p2[i]) <= a + Point.EPS) {
                    flag = true;
                }
                if (flag) {
                    Q.add(i);
                    vist[i] = true;
                    step[i] = step[id] + 1;
                }
            }
        }
        out.println(ans);
    }

    double distance(int x1, int y1, int x2, int y2) {
        return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    }

    public static void main(String[] args) throws IOException {
        Main sloved = new Main();
        sloved.run();
        sloved.out.close();
    }

    Scanner cin = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
}

class Point {
    static final double EPS = 1e-6;
    double x, y;

    Point() {
    }

    Point(double x, double y) {
        this.x = x;
        this.y = y;
    }

    Point(Point u) {
        this.x = u.x;
        this.y = u.y;
    }

    public static boolean parallel(Point u1, Point u2, Point v1, Point v2) {
        return zero((u1.x - u2.x) * (v1.y - v2.y) - (v1.x - v2.x)
                * (u1.y - u2.y));
    }

    public static boolean intersect_ex(Point u1, Point u2, Point v1, Point v2) {
        return opposite_side(u1, u2, v1, v2) && opposite_side(v1, v2, u1, u2);
    }

    public static boolean dot_online_in(Point p, Point l1, Point l2) {
        return zero(xmult(p, l1, l2)) && (l1.x - p.x) * (l2.x - p.x) < EPS
                && (l1.y - p.y) * (l2.y - p.y) < EPS;
    }

    public static boolean same_side(Point p1, Point p2, Point l1, Point l2) {
        return xmult(l1, p1, l2) * xmult(l1, p2, l2) > EPS;
    }

    public static boolean intersect_in(Point u1, Point u2, Point v1, Point v2) {
        if (!dots_inline(u1, u2, v1) || !dots_inline(u1, u2, v2))
            return !same_side(u1, u2, v1, v2) && !same_side(v1, v2, u1, u2);
        return dot_online_in(u1, v1, v2) || dot_online_in(u2, v1, v2)
                || dot_online_in(v1, u1, u2) || dot_online_in(v2, u1, u2);
    }

    public static boolean dots_inline(Point p1, Point p2, Point p3) {
        return zero(xmult(p1, p2, p3));
    }

    public static boolean dot_online_ex(Point p, Point l1, Point l2) {
        return dot_online_in(p, l1, l2)
                && (!zero(p.x - l1.x) || !zero(p.y - l1.y))
                && (!zero(p.x - l2.x) || !zero(p.y - l2.y));
    }

    public static boolean opposite_side(Point p1, Point p2, Point l1, Point l2) {
        return xmult(l1, p1, l2) * xmult(l1, p2, l2) < -EPS;
    }

    public static double distance(Point p1, Point p2) {
        return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y)
                * (p1.y - p2.y));
    }

    public static double xmult(Point p1, Point p2, Point p0) {
        return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
    }

    public static boolean zero(double x) {
        return (((x) > 0 ? (x) : -(x)) < EPS);
    }

    public static Point intersection(Point u1, Point u2, Point v1, Point v2) {
        Point ret = new Point(u1);
        double t = ((u1.x - v1.x) * (v1.y - v2.y) - (u1.y - v1.y)
                * (v1.x - v2.x))
                / ((u1.x - u2.x) * (v1.y - v2.y) - (u1.y - u2.y)
                        * (v1.x - v2.x));
        ret.x += (u2.x - u1.x) * t;
        ret.y += (u2.y - u1.y) * t;
        return ret;
    }

    public static Point circumcenter(Point a, Point b, Point c) {
        Point ua = new Point();
        Point ub = new Point();
        Point va = new Point();
        Point vb = new Point();
        ua.x = (a.x + b.x) / 2;
        ua.y = (a.y + b.y) / 2;
        ub.x = ua.x - a.y + b.y;
        ub.y = ua.y + a.x - b.x;
        va.x = (a.x + c.x) / 2;
        va.y = (a.y + c.y) / 2;
        vb.x = va.x - a.y + c.y;
        vb.y = va.y + a.x - c.x;
        return intersection(ua, ub, va, vb);
    }

    public static double disptoseg(Point p, Point l1, Point l2) {
        Point t = new Point(p);
        t.x += l1.y - l2.y;
        t.y += l2.x - l1.x;
        if (xmult(l1, t, p) * xmult(l2, t, p) > EPS)
            return distance(p, l1) < distance(p, l2) ? distance(p, l1)
                    : distance(p, l2);
        return Math.abs(xmult(p, l1, l2)) / distance(l1, l2);
    }

}