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

Solution:
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int n, tx1, ty1, tx2, ty2;
int X[31], Y[31];
vector<pair<double, double> > P;
vector<int> R;
bool pointOnLine(int x, int y, int x1, int y1, int x2, int y2) {
  int a, b, c;
  a = (y1 - y2);
  b = (x2 - x1);
  c = -(a * x1 + b * y1);
  return (a * x + b * y + c == 0);
}
bool pointOnSegm(int x, int y, int x1, int y1, int x2, int y2) {
  return (pointOnLine(x, y, x1, y1, x2, y2) && x >= min(x1, x2) &&
          x <= max(x1, x2) && y >= min(y1, y2) && y <= max(y1, y2));
}
double dist(int x1, int y1, int x2, int y2) {
  return sqrt((double)(x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
double dist2(double x1, double y1, double x2, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int g(int x, int y, int x1, int y1, int x2, int y2) {
  int d = (x - x1) * (y2 - y1) - (x2 - x1) * (y - y1);
  if (d < 0) return -1;
  if (d > 0) return 1;
  return 0;
}
bool isF(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
  if (pointOnSegm(x1, y1, x3, y3, x4, y4) ||
      pointOnSegm(x2, y2, x3, y3, x4, y4) ||
      pointOnSegm(x3, y3, x1, y1, x2, y2) ||
      pointOnSegm(x4, y4, x1, y1, x2, y2))
    return true;
  return (((g(x1, y1, x3, y3, x4, y4) + g(x2, y2, x3, y3, x4, y4) == 0) &&
           (g(x1, y1, x3, y3, x4, y4) != 0)) &&
          ((g(x3, y3, x1, y1, x2, y2) + g(x4, y4, x1, y1, x2, y2) == 0) &&
           (g(x3, y3, x1, y1, x2, y2) != 0)));
}
pair<double, double> F(int x1, int y1, int x2, int y2, int x3, int y3, int x4,
                       int y4) {
  pair<double, double> r;
  int a1, a2, b1, b2, c1, c2;
  a1 = (y1 - y2);
  a2 = (y3 - y4);
  b1 = (x2 - x1);
  b2 = (x4 - x3);
  c1 = -(a1 * x1 + b1 * y1);
  c2 = -(a2 * x3 + b2 * y3);
  int d = (a1 * b2 - a2 * b1);
  int d1 = (c1 * b2 - c2 * b1);
  int d2 = (a1 * c2 - a2 * c1);
  r.first = -((double)d1 / d);
  r.second = -((double)d2 / d);
  return r;
}
bool eq(double a, double b) { return (fabs(a - b) <= (1E-13)); }
bool les(double a, double b) { return ((b - a) > (1E-13)); }
int main() {
  cin >> tx1 >> ty1 >> tx2 >> ty2;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> X[i] >> Y[i];
  X[n] = X[0];
  Y[n] = Y[0];
  bool canWalk = false;
  for (int i = 0; i < n; i++) {
    if (pointOnLine(X[i], Y[i], tx1, ty1, tx2, ty2) &&
        pointOnLine(X[i + 1], Y[i + 1], tx1, ty1, tx2, ty2))
      canWalk = true;
  }
  if (canWalk) {
    printf("%0.7f\n", dist(tx1, ty1, tx2, ty2));
    cin >> n;
    return 0;
  }
  double tres = 0;
  for (int i = 0; i < n; i++) {
    int X1, Y1, X2, Y2;
    X1 = X[i], Y1 = Y[i], X2 = X[i + 1], Y2 = Y[i + 1];
    if (isF(X1, Y1, X2, Y2, tx1, ty1, tx2, ty2)) {
      pair<double, double> p;
      p = F(X1, Y1, X2, Y2, tx1, ty1, tx2, ty2);
      bool ok = true;
      for (int j = 0; j < P.size(); j++)
        if (eq(P[j].first, p.first) && eq(P[j].second, p.second)) ok = false;
      if (ok) {
        R.push_back(i);
        P.push_back(p);
        if (R.size() == 1)
          tres += dist2(P.back().first, P.back().second, X2, Y2);
        else
          tres += dist2(P.back().first, P.back().second, X1, Y1);
      }
    }
  }
  double sum = 0;
  for (int i = 0; i < n; i++)
    sum += dist(X[i], Y[i], X[(i + 1) % n], Y[(i + 1) % n]);
  double res = 0;
  if (P.size() < 2)
    res = dist(tx1, ty1, tx2, ty2);
  else {
    double d1 = dist2(tx1, ty1, P[0].first, P[0].second),
           d2 = dist2(tx1, ty1, P[1].first, P[1].second);
    double d = dist2(tx1, ty1, tx2, ty2);
    if (les(d2, d1)) swap(d1, d2);
    res = d1 + (d - d2) + (d2 - d1) * 2;
    int i = (R[0] + 1) % n;
    while (i != R[1]) {
      tres += dist(X[i], Y[i], X[(i + 1) % n], Y[(i + 1) % n]);
      i = (i + 1) % n;
    }
    if (les(sum - tres, tres)) tres = sum - tres;
    tres += d1 + (d - d2);
    if (les(tres, res)) res = tres;
  }
  printf("%0.11f\n", res);
  cin >> n;
  return 0;
}