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 {

	final int MOD = 1000000007;
	double INF = 1e9;
	final double eps = 1e-7;

	public A () throws IOException {
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int [] AB = sc.nextInts();
		
		int N = sc.nextInt() + 2;
		int [][] T = new int [N][];
		for (int i = 1; i < N-1; ++i)
			T[i] = sc.nextInts();
		
		start();

		T[0] = new int [] { AB[0], AB[1], AB[0], AB[1] };
		T[N-1] = new int [] { AB[2], AB[3], AB[2], AB[3] };
		for (int i = 0; i < N; ++i)
			for (int p = 0; p <= 1; ++p)
				if (T[i][p+2] < T[i][p]) { int tmp = T[i][p+2]; T[i][p+2] = T[i][p]; T[i][p] = tmp; }

		boolean [][] G = new boolean [N][N];
		for (int i = 0; i < N; ++i)
			for (int j = i+1; j < N; ++j)
				G[i][j] = G[j][i] = !more(dist(T, i, j), a);

		int start = 0, end = N-1;
		int [] Q = new int[N];
		int [] D = new int [N]; 
		Arrays.fill(D, -1);
		D[start] = 0;
		Q[0] = start;
		int fi = 0, la = 1;
		
		double res = INF;
		while (fi < la) {
			int z = Q[fi++];
			int d = D[z];
			
			for (int y = 0; y < N; ++y) 
				if (D[y] == -1 && G[z][y]) {
					if (y == end) {
						for (int x = 0; x < N; ++x)
							if (D[x] == d && G[x][end])
								res = Math.min(res, d*(a+b) + dist(T, x, end));
					}
					else {
						D[y] = d+1;
						Q[la++] = y;
					}
				}
		}
		
		if (res > INF/2) exit(-1);
		exit(res);
	}
		
	double R(double x1, double y1, double x2, double y2) {
		double xx = x2 - x1, yy = y2 - y1;
		return Math.sqrt(xx*xx + yy*yy);
	}
	
	boolean less(double x, double y) { return  x < y - eps; }
	boolean more(double x, double y) { return x > y + eps; }
	boolean eq(double x, double y) { return Math.abs(x - y) < eps; }
	
	double dist(int [][] T, int i, int j) {
		
		double d = INF;
		for (int p = 0; p <= 2; p += 2)
			for (int q = 0; q <= 2; q += 2)
				d = Math.min(d, R(T[i][p], T[i][p+1], T[j][q], T[j][q+1]));
		
		for (int p = 0; p <= 1; ++p) {
			int q = 1-2*p;
			if (T[i][p] < T[j][p+2] && T[j][p] < T[i][p+2]) { 
				double x = Math.min(Math.abs(T[i][p+q] - T[j][p+q+2]), Math.abs(T[i][p+q+2] - T[j][p+q]));
				d = Math.min(d, x);
			}
		}
		
		return d;
	}

	////////////////////////////////////////////////////////////////////////////////////
	
	static MyScanner sc;
	
	static void print (Object... a) {
		StringBuffer b = new StringBuffer();
		for (Object o : a)
			b.append(" ").append(o);
		System.out.println(b.toString().trim());
	}

	static void exit (Object... a) {
		print(a);
		System.out.flush();
		exit();
	}

	static void exit () {
		System.err.println("------------------");
		System.err.println("Time: " + (millis() - t) / 1000.0);
		System.exit(0);
	}
	
	static class MyScanner {
		String next() throws IOException {
			newLine();
			return line[index++];
		}
		
		char [] nextChars() throws IOException {
			return next().toCharArray();
		}
		
		double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		
		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		
		long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		
		String nextLine() throws IOException {
			line = null;
			return r.readLine();
		}
		
		String [] nextStrings() throws IOException {
			line = null;
			return r.readLine().split(" ");
		}
		
		int [] nextInts() throws IOException {
			String [] L = nextStrings();
			int [] res = new int [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}
		
		long [] nextLongs() throws IOException {
			String [] L = nextStrings();
			long [] res = new long [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Long.parseLong(L[i]);
			return res;
		}

		boolean eol() {
			return index == line.length;
		}

		//////////////////////////////////////////////
		
		private final BufferedReader r;

		MyScanner () throws IOException {
			this(new BufferedReader(new InputStreamReader(System.in)));
		}
		
		MyScanner(BufferedReader r) throws IOException { 
			this.r = r;
		}
		
		private String [] line;
		private int index;

		private void newLine() throws IOException {
			if (line == null || eol()) {
				line = r.readLine().split(" ");
				index = 0;
			}
		}		
	}
	
	////////////////////////////////////////////////////////////////////////////////////
	
	public static void main(String[] args) throws IOException {
		run();
		exit();
	}

	static void start() {
		t = millis();
	}

	static void run () throws IOException {
		sc = new MyScanner ();
		new A();
	}

	static long t;
	
	static long millis() {
		return System.currentTimeMillis();
	}	
}