Problem: The Onogawa Expedition is planning to conduct a survey of the Aizu nature reserve. The expedition planner wants to take the shortest possible route from the start to end point of the survey, while the expedition has to go around the coast of the Lake of Onogawa en route. The expedition walks along the coast of the lake, but can not wade across the lake.

Based on the base information including the start and end point of the survey and the area of Lake Onogawa as convex polygon data, make a program to find the shortest possible route for the expedition and calculate its distance. Note that the expedition can move along the polygonal lines passing through the nodes, but never enter within the area enclosed by the polygon.



Input

The input is given in the following format.


x_s y_s
x_g y_g
N
x_1 y_1
x_2 y_2
:
x_N y_N


The first line provides the start point of the survey x_s,y_s (0≤x_s,y_s≤104), and the second line provides the end point x_g,y_g (0 ≤ x_g,y_g ≤ 104) all in integers. The third line provides the number of apexes N (3 ≤ N ≤ 100) of the polygon that represents the lake, and each of the subsequent N lines provides the coordinate of the i-th apex x_i,y_i (0 ≤ x_i,y_i ≤ 104) in counter-clockwise order. These data satisfy the following criteria:

* Start and end points of the expedition are not within the area enclosed by the polygon nor on boundaries.
* Start and end points of the expedition are not identical, i.e., x_s ≠ x_g or y_s ≠ y_g.
* No duplicate coordinates are given, i.e., if i ≠ j then x_i ≠ x_r or y_i ≠ y_j.
* The area enclosed by the polygon has a positive value.
* Any three coordinates that define an area are not aligned on a line.

Output

Output the distance of the shortest possible expedition route. Any number of decimal places can be selected as long as the error does not exceed ± 10-3.

Examples

Input

0 0
4 0
4
1 1
2 1
3 3
1 2


Output

4.472136


Input

4 4
0 0
4
1 1
3 1
3 3
1 3


Output

6.32455

Solution (in CPP):

Solution:
#include <cmath>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
class point2d {
public:
	double x, y;
	point2d() : x(0), y(0) {};
	point2d(double x_, double y_) : x(x_), y(y_) {};
	bool operator==(const point2d& p) const { return x == p.x && y == p.y; }
	bool operator!=(const point2d& p) const { return x != p.x || y != p.y; }
	point2d& operator+=(const point2d& p) { x += p.x; y += p.y; return *this; }
	point2d& operator-=(const point2d& p) { x -= p.x; y -= p.y; return *this; }
	point2d& operator*=(const double v) { x *= v; y *= v; return *this; }
	point2d operator+(const point2d& p) const { return point2d(*this) += p; }
	point2d operator-(const point2d& p) const { return point2d(*this) -= p; }
	point2d operator*(const double v) const { return point2d(*this) *= v; }
	double norm() const { return x * x + y * y; }
	double abs() const { return std::sqrt(x * x + y * y); }
	double dot(const point2d& p) const { return x * p.x + y * p.y; }
	double cross(const point2d& p) const { return x * p.y - y * p.x; }
	int ccw(const point2d& p1, const point2d& p2) const {
		point2d pr1 = p1 - point2d(*this);
		point2d pr2 = p2 - point2d(*this);
		if (pr1.cross(pr2) != 0) return pr1.cross(pr2) > 0 ? 1 : -1;
		if (pr1.dot(pr2) < 0) return 2;
		return pr1.norm() < pr2.norm() ? -2 : 0;
	}
};
class segment2d {
public:
	point2d p1, p2;
	segment2d() : p1(), p2() {};
	segment2d(const point2d& p1_, const point2d& p2_) : p1(p1_), p2(p2_) {};
	double norm() const { return (p1 - p2).norm(); }
	double abs() const { return (p1 - p2).abs(); }
};
bool intersect(const segment2d& s1, const segment2d& s2) {
	if (s1.p1 == s2.p1 || s1.p1 == s2.p2 || s1.p2 == s2.p1 || s1.p2 == s2.p2) return false; // EXCEPTION !!!
	return s1.p1.ccw(s1.p2, s2.p1) * s1.p1.ccw(s1.p2, s2.p2) <= 0 && s2.p1.ccw(s2.p2, s1.p1) * s2.p1.ccw(s2.p2, s1.p2) <= 0;
}
point2d intersect_point(const segment2d &s1, const segment2d &s2) {
	point2d base = s2.p2 - s2.p1;
	double d1 = std::abs(base.cross(s1.p1 - s2.p1));
	double d2 = std::abs(base.cross(s1.p2 - s2.p1));
	return s1.p1 + (s1.p2 - s1.p1) * (d1 / (d1 + d2));
}
bool contain(const std::vector<point2d>& v, const point2d& p) {
	int ans = -1;
	for (int i = 0; i < v.size(); ++i) {
		point2d p1 = v[i] - p;
		point2d p2 = v[(i + 1) % v.size()] - p;
		if (p1.x > p2.x) std::swap(p1, p2);
		if (p1.x <= 0 && 0 < p2.x && p1.cross(p2) < 0) ans *= -1;
	}
	return (ans == 1);
}
int main() {
	int n;
	vector<point2d> v(2);
	cin >> v[0].x >> v[0].y >> v[1].x >> v[1].y;
	cin >> n;
	v.resize(n + 2);
	for (int i = 2; i < n + 2; ++i) {
		cin >> v[i].x >> v[i].y;
	}
	// Shortest Path (Warshall-Floyd Algorithm)
	vector<vector<double> > d(n + 2, vector<double>(n + 2, 1.0e+99));
	for (int i = 0; i < n + 2; ++i) {
		d[i][i] = 0;
	}
	for (int i = 0; i < n + 2; ++i) {
		for (int j = 0; j < i; ++j) {
			// Going to vertex j from vertex i
			bool ok = true;
			for (int k = 0; k < v.size() - 2; ++k) {
				segment2d s(v[k + 2], v[(k + 1) % (v.size() - 2) + 2]);
				if (intersect(s, segment2d(v[i], v[j]))) {
					//cout << i << ' ' << j << ' ' << k << "-" << k + 1 << endl;
					ok = false;
				}
			}
			if (contain(vector<point2d>(v.begin() + 2, v.end()), (v[i] + v[j]) * 0.5)) {
				ok = false;
			}
			if (ok || (j >= 2 && i - j == 1) || (j == 2 && i == n + 1)) {
				//cout << i << ' ' << j << endl;
				d[i][j] = (v[i] - v[j]).abs();
				d[j][i] = (v[i] - v[j]).abs();
			}
		}
	}
	d[0][1] = 1.0e+99;
	d[1][0] = 1.0e+99;
	for (int i = 0; i < n + 2; ++i) {
		for (int j = 0; j < n + 2; ++j) {
			for (int k = 0; k < n + 2; ++k) {
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
	double ans = d[0][1];
	for (int i = 0; i < n; ++i) {
		point2d p1 = v[i + 2], p2 = v[(i + 1) % (v.size() - 2) + 2];
		point2d bs = p1 + (p2 - p1) * (v[1] - p1).dot(p2 - p1) * (1.0 / (p2 - p1).norm());
		point2d rfl = bs * 2 - v[1];
		point2d crp = intersect_point(segment2d(p1, p2), segment2d(v[0], rfl));
		if (min(p1.x, p2.x) <= crp.x && crp.x <= max(p1.x, p2.x) && min(p1.y, p2.y) <= crp.y && crp.y <= max(p1.y, p2.y)) {
			bool ok = true;
			for (int j = 0; j < n; ++j) {
				point2d pp1 = v[j + 2], pp2 = v[(j + 1) % (v.size() - 2) + 2];
				if (intersect(segment2d(pp1, pp2), segment2d(v[0], v[1]))) {
					ok = false;
				}
			}
			if (ok) {
				double d0 = (crp - v[0]).abs();
				double d1 = (crp - v[1]).abs();
				ans = min(ans, d0 + d1);
			}
		}
	}
	cout << fixed << setprecision(15) << ans << endl;
	return 0;
}