Problem: You have got a new job, and it's very interesting, you are a ship captain. Your first task is to move your ship from one point to another point, and for sure you want to move it at the minimum cost.

And it's well known that the shortest distance between any 2 points is the length of the line segment between these 2 points. But unfortunately there is an island in the sea, so sometimes you won't be able to move your ship in the line segment between the 2 points.

You can only move to safe points. A point is called safe if it's on the line segment between the start and end points, or if it's on the island's edge.

But you are too lucky, you have got some clever and strong workers and they can help you in your trip, they can help you move the ship in the sea and they will take 1 Egyptian pound for each moving unit in the sea, and they can carry the ship (yes, they are very strong) and walk on the island and they will take 2 Egyptian pounds for each moving unit in the island. The money which you will give to them will be divided between all workers, so the number of workers does not matter here.

You can move your ship on the island edge, and it will be considered moving in the sea.

Now you have a sea map, and you have to decide what is the minimum cost for your trip.

Your starting point is (xStart, yStart), and the end point is (xEnd, yEnd), both points will be different.

The island will be a convex polygon and there will be no more than 2 polygon points on the same line, also the starting and the end points won't be inside or on the boundary of the island. The points for the polygon will be given in the anti-clockwise order.

Input

The first line contains 4 integers, xStart, yStart, xEnd and yEnd ( - 100 ≤ xStart, yStart, xEnd, yEnd ≤ 100). The second line contains an integer n, which is the number of points in the polygon (3 ≤ n ≤ 30), followed by a line containing n pairs of integers x and y, which are the coordinates of the points ( - 100 ≤ x, y ≤ 100), the polygon points will be distinct.

Output

Print one line which contains the minimum possible cost. The absolute or relative error in the answer should not exceed 10 - 6.

Examples

Input

1 7 6 7
4
4 2 4 12 3 12 3 2


Output

6.000000000


Input

-1 0 2 0
4
0 0 1 0 1 1 0 1


Output

3.000000000

Solution (in JAVA):

Solution:
import java.util.*;

public class Ship {
	public static double EPS = 1e-9;
	public static void main(String[] args){
		Scanner reader = new Scanner(System.in);
		
		Point s = new Point(reader.nextDouble(), reader.nextDouble());
		Point t = new Point(reader.nextDouble(), reader.nextDouble());
		
		int n = reader.nextInt();
		Point[] p = new Point[n];
		for(int i = 0; i < n; i++)
			p[i] = new Point(reader.nextDouble(), reader.nextDouble());
		
		//1. Find points of intersection between segment ST and each segment along the polygon,
		//   add to treeset for uniqueness
		TreeSet<Point> set = new TreeSet<Point>();
		boolean flag = false;
		for(int i = 0; i < n; i++){
			Point a = p[i];
			Point b = p[(i+1)%n];
			if(segmentIntersect(s,t,a,b)){
				Point c = intersect(s,t,a,b);
				flag |= c==null;
				//System.out.println(c);
				if(c != null)
					set.add(c);
			}
		}
		
		//2.a If set size <= 1, return 0!
		if(set.size() <= 1 || flag){
			System.out.printf("%.10f\n", s.dis(t));
		}else{
			//2.b Build graph of size n + 4
			int m = n+4;
			double[][] g = new double[m][m];
			for(double[] e:g)Arrays.fill(e,1e9);
			for(int i = 0; i < m; i++)
				g[i][i] = 0;
			
			ArrayList<Point> h = new ArrayList<Point>();
			for(Point c:set)
				h.add(c);
			
			//Add edges from start and end to polygon intersects
			for(int i = 0; i < 2; i++){
				if(h.get(i).dis(s) < h.get((i+1)%2).dis(s)){
					g[0][i+2] = h.get(i).dis(s);
					g[i+2][0] = g[0][i+2];
				}else{
					g[i+2][1] = h.get(i).dis(t);
					g[1][i+2] = g[i+2][1];
				}
			}
			
			//Add edge between intersects
			g[2][3] = 2*h.get(0).dis(h.get(1));
			g[3][2] = g[2][3];
			
			//Add edges from intersects to polygon vertices
			for(int j = 0; j < 2; j++){
				for(int i = 0; i < n; i++){
					Point a = p[i];
					Point b = p[(i+1)%n];
					
					if(pldist(a,b,h.get(j)) < EPS){
						g[j+2][i+4] = a.dis(h.get(j));
						g[i+4][j+2] = g[j+2][i+4];
						g[j+2][(i+1)%n+4] = b.dis(h.get(j));
						g[(i+1)%n+4][j+2] = g[j+2][(i+1)%n+4];
					}
					g[j+2][i+4] = Math.min(g[j+2][i+4], 2*a.dis(h.get(j)));
					g[i+4][j+2] = Math.min(g[i+4][j+2], g[j+2][i+4]);
				}
			}
			
			for(int i = 0; i < n; i++){
				//Add edges from polygon vertices to polygon vertices
				for(int j = 0; j < n; j++){
					double d = p[i].dis(p[j])*2;
					if(j == (i+1)%n || j == (i-1+n)%n)
						d /= 2;
					g[i+4][j+4] = d;
					g[j+4][i+4] = d;
				}
				
				//Add edges from start point to polygon vertices
				/*TreeSet<Point> chk = new TreeSet<Point>();
				for(int j = 0; j < n; j++){
					Point a = p[j];
					Point b = p[(j+1)%n];
					if(segmentIntersect(s,p[i],a,b)){
						Point c = intersect(s,p[i],a,b);
						if(c != null)
							chk.add(c);
					}
				}
				
				if(chk.size() == 1){
					g[0][i+4] = s.dis(p[i]);
					g[i+4][0] = g[0][i+4];
				}
				
				chk.clear();
				//Add edges from polygon vertices to end point
				chk = new TreeSet<Point>();
				for(int j = 0; j < n; j++){
					Point a = p[j];
					Point b = p[(j+1)%n];
					if(segmentIntersect(p[i],t,a,b)){
						Point c = intersect(p[i],t,a,b);
						if(c != null)
							chk.add(c);
					}
				}
				
				if(chk.size() == 1){
					g[1][i+4] = t.dis(p[i]);
					g[i+4][1] = g[1][i+4];
				}*/
			}
			
//			for(double[] e:g)
//				System.out.println(Arrays.toString(e));
			
			//3. Floyd's!
			for(int k = 0; k < m; k++){
				for(int i = 0; i < m; i++){
					for(int j = 0; j < m; j++){
						g[i][j] = Math.min(g[i][j], g[i][k] + g[k][j]);
					}
				}
			}
			
			System.out.printf("%.10f",g[0][1]);
		}
	}
	
	static boolean segmentIntersect(Point a, Point b, Point c, Point d){
		Point e = b.sub(a);
		Point f = d.sub(c);
		if(Math.abs(c.sub(a).cross(e)) < EPS && Math.abs(d.sub(a).cross(e)) < EPS)
			return (c.sub(a).dot(e) > -EPS && c.sub(b).dot(a.sub(b)) > -EPS) || (d.sub(a).dot(e) > -EPS && d.sub(b).dot(a.sub(b)) > -EPS) ||
			       (a.sub(c).dot(f) > -EPS && a.sub(d).dot(c.sub(d)) > -EPS) || (b.sub(c).dot(f) > -EPS && b.sub(d).dot(c.sub(d)) > -EPS);
		return Math.signum(b.sub(c).cross(f)) != Math.signum(a.sub(c).cross(f)) && Math.signum(c.sub(a).cross(e)) !=  Math.signum(d.sub(a).cross(e));
	}
	
	//Point-line distance
	//Input: Line from A to B, point to be tested p
	public static double pldist(Point a, Point b, Point p){
		Point c = p.sub(a);
		Point d = b.sub(a);
		if(c.dot(d) < 0)
			return p.dis(a);
		if(p.sub(b).dot(d.scale(-1)) < 0)
			return p.dis(b);
		return Math.abs(c.cross(d))/d.mag();
	}
	
	//Line-line intersection
	//Input: Line AB, Line CD
	//Returns: null if the lines are parallel, point of intersection otherwise
	//Notes: Detects coincidence, handling left for a per-problem basis
	static Point intersect(Point a, Point b, Point c, Point d){
		Point e = d.sub(c), f = a.sub(c), g = b.sub(a);
		double AB = e.cross(f);
		double CD = g.cross(f);
		double D = g.cross(e);
		
		//if AB == CD == D == 0, then the lines are coincident
		//if D == 0, the lines are parallel
		if(Math.abs(D) < EPS)
			return null;
		
		return a.add(g.scale(AB/D));
	}
	
	public static class Point implements Comparable<Point>{
		double x,y;
		public Point(double _x, double _y){
			x = _x; y = _y;
		}
		public Point sub(Point p){
			return new Point(x-p.x, y-p.y);
		}
		public Point add(Point p){
			return new Point(x+p.x, y+p.y);
		}
		public Point scale(double L){
			return new Point(x*L, y*L);
		}
		public Point rot(double t){
			double c = Math.cos(t);
			double s = Math.sin(t);	
			return new Point(x*c-y*s, x*s+y*c);
		}
		public Point norm(){
			return new Point(x/mag(), y/mag());
		}
		public Point project(Point p){
			return p.scale(dot(p)/p.dot(p));
		}
		public double dot(Point p){
			return x*p.x + y*p.y;
		}
		public double cross(Point p){
			return x*p.y-y*p.x;
		}
		public double angBetween(Point p){
			double d = Math.abs(ang()-p.ang());
			return Math.min(d, 2*Math.PI-d);
		}
		public double mag(){
			return Math.abs(Math.sqrt(x*x + y*y));
		}
		public double ang(){
			double a = Math.atan2(y,x);
			if(a<0) a+=2*Math.PI;
			return a;
		}
		public double dis(Point p){
			return sub(p).mag();
		}
		public int compareTo(Point p){
			if(Math.abs(x-p.x) < EPS){
				if(Math.abs(y-p.y) < EPS)
					return 0;
				return (int)Math.signum(y-p.y);
			}
			return (int)Math.signum(x-p.x);	
		}
		public String toString(){
			return "("+x+", "+y+")";
		}
	}
}