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.io.*;
import java.util.*;

public class A implements Runnable {
    private MyScanner in;
    private PrintWriter out;

    public static int dist2(int x1, int y1, int x2, int y2) {
        return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    }

    private void solve() {
        int a = in.nextInt();
        int b = in.nextInt();
        int fromX = in.nextInt();
        int fromY = in.nextInt();
        int toX = in.nextInt();
        int toY = in.nextInt();
        int n = in.nextInt();
        Segment[] seg = new Segment[n];
        for (int i = 0; i < n; ++i) {
            int x1 = in.nextInt();
            int y1 = in.nextInt();
            int x2 = in.nextInt();
            int y2 = in.nextInt();
            seg[i] = new Segment(x1, y1, x2, y2);
        }
        boolean[][] can = new boolean[n][n];
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                int d2 = seg[i].getDist2(seg[j]);
                can[i][j] = can[j][i] = d2 <= a * a;
            }
        }
        int startFinish = dist2(fromX, fromY, toX, toY);
        if (startFinish <= a * a) {
            out.println(Math.sqrt(startFinish));
            return;
        }
        boolean[] fromStart = new boolean[n], toFinish = new boolean[n];
        boolean[] seen = new boolean[n];
        Deque<Integer> queue = new ArrayDeque<Integer>();
        for (int i = 0; i < n; ++i) {
            fromStart[i] = seg[i].dist2ToPoint(fromX, fromY) <= a * a;
            if (fromStart[i]) {
                queue.addLast(i);
                seen[i] = true;
            }
            toFinish[i] = seg[i].dist2ToPoint(toX, toY) <= a * a;
        }
        int time = a + b;
        double ans = Long.MAX_VALUE;
        while (!queue.isEmpty()) {
            int sz = queue.size();
            for (int i = 0; i < sz; ++i) {
                int cur = queue.removeFirst();
                if (toFinish[cur]) {
                    ans = Math.min(ans, time
                            + Math.sqrt(seg[cur].dist2ToPoint(toX, toY)));
                } else {
                    for (int j = 0; j < n; ++j) {
                        if (!seen[j] && can[cur][j]) {
                            queue.addLast(j);
                            seen[j] = true;
                        }
                    }
                }
            }
            if (ans < Long.MAX_VALUE / 2) {
                break;
            }
            time += a + b;
        }
        if (ans > Long.MAX_VALUE / 2) {
            out.println(-1);
        } else {
            out.println(ans);
        }       
    }

    @Override
    public void run() {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    public static void main(String[] args) {
        new A().run();
    }

    class Segment {
        public int x1, y1, x2, y2;

        public Segment(int x1, int y1, int x2, int y2) {
            this.x1 = x1;
            this.y1 = y1;
            this.x2 = x2;
            this.y2 = y2;
            if (x1 > x2 || y1 > y2) {
                int temp = this.x1;
                this.x1 = this.x2;
                this.x2 = temp;
                temp = this.y1;
                this.y1 = this.y2;
                this.y2 = temp;
            }
        }

        public int getDist2(Segment s) {
            if (x1 == x2) {
                if (s.x1 == s.x2) {
                    if (y2 < s.y1) {
                        return dist2(x2, y2, s.x1, s.y1);
                    } else if (y1 > s.y2) {
                        return dist2(x1, y1, s.x2, s.y2);
                    } else {
                        return (s.x1 - x1) * (s.x1 - x1);
                    }
                } else {
                    if (x1 >= s.x1 && x1 <= s.x2) {
                        return Math.min(dist2(x1, y1, x1, s.y1), dist2(x2, y2,
                                x1, s.y1));
                    } else if (y1 <= s.y1 && y2 >= s.y1) {
                        return Math.min(dist2(x1, s.y1, s.x1, s.y1), dist2(x1,
                                s.y1, s.x2, s.y2));
                    } else {
                        return Math.min(Math.min(dist2(x1, y1, s.x1, s.y1),
                                dist2(x1, y1, s.x2, s.y2)), Math.min(dist2(x2,
                                y2, s.x1, s.y1), dist2(x2, y2, s.x2, s.y2)));
                    }
                }
            } else {
                if (s.y1 == s.y2) {
                    if (x2 < s.x1) {
                        return dist2(x2, y2, s.x1, s.y1);
                    } else if (x1 > s.x2) {
                        return dist2(x1, y1, s.x2, s.y2);
                    } else {
                        return (s.y1 - y1) * (s.y1 - y1);
                    }
                } else {
                    return s.getDist2(this);
                }
            }

        }

        public int dist2ToPoint(int x, int y) {
            if (y1 == y2) {
                if (x <= x1) {
                    return dist2(x1, y1, x, y);
                }
                if (x >= x2) {
                    return dist2(x2, y2, x, y);
                }
                return dist2(x, y1, x, y);
            } else {
                if (y <= y1) {
                    return dist2(x1, y1, x, y);
                }
                if (y >= y2) {
                    return dist2(x2, y2, x, y);
                }
                return dist2(x1, y, x, y);
            }
        }
    }

    class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public boolean hasNext() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String s = br.readLine();
                    if (s == null) {
                        return false;
                    }
                    st = new StringTokenizer(s);
                } catch (IOException e) {
                    e.printStackTrace();
                    return false;
                }
            }
            return st != null && st.hasMoreTokens();
        }

        private String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String s = br.readLine();
                    if (s == null) {
                        return null;
                    }
                    st = new StringTokenizer(s);
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                }
            }
            return st.nextToken();
        }

        public String nextLine() {
            try {
                st = null;
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}