#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007, dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
const double eps = 1e-8, pi = acos(-1);
void read(int &k) {
  k = 0;
  char x = getchar();
  while (x < '0' || x > '9') x = getchar();
  while (x >= '0' && x <= '9') {
    k = k * 10 - 48 + x;
    x = getchar();
  }
}
int cmp(double x, double y) {
  if (fabs(x - y) < eps) return 0;
  return x < y ? -1 : 1;
}
struct point {
  double x, y, z;
  point() { z = 1; }
  point(double xx, double yy, double zz) {
    x = xx;
    y = yy;
    z = zz;
  }
  double operator*(point b) { return x * b.x + y * b.y + z * b.z; }
  point operator*(double k) { return (point){k * x, k * y, z}; }
  point operator/(point b) {
    return (point){y * b.z - z * b.y, z * b.x - x * b.z, x * b.y - y * b.x};
  }
  point operator-(point b) { return (point){x - b.x, y - b.y, z}; }
  point operator+(point b) { return (point){x + b.x, y + b.y, z}; }
  void rotate(double theta) {
    point T = *this;
    x = T.x * cos(theta) - T.y * sin(theta);
    y = T.x * sin(theta) + T.y * cos(theta);
  }
  void output() { printf("%.9lf %.9lf ", x, y); }
  bool operator<(point b) const {
    int t = cmp(x, b.x);
    if (t == 0) return cmp(y, b.y) < 0;
    return t < 0;
  }
};
point V, P, WL, WR, ML, MR, dir, tP, tmp;
int inl(point x, point y, point z) { return cmp(x * (y / z), 0) == 0; }
point Normal(point y, point z) {
  point tmp = z - y;
  tmp.rotate(pi / 2);
  return tmp;
}
point Mirror(point x, point y, point z) {
  point nvec;
  nvec = Normal(y, z);
  point tmp = y / z, o, nxt;
  o = (point){tmp.y, -tmp.x, 0};
  o.z = -(x.x * o.x + x.y * o.y);
  nxt = o / tmp;
  nxt.x /= nxt.z;
  nxt.y /= nxt.z;
  nxt.z = 1;
  return nxt * 2 - x;
}
int in(point x, point y, point z) {
  int flag1 = 0, flag2 = 0;
  if (cmp(x.x, y.x) >= 0 && cmp(x.x, z.x) <= 0) flag1 = 1;
  if (cmp(x.x, z.x) >= 0 && cmp(x.x, y.x) <= 0) flag1 = 1;
  if (cmp(x.y, y.y) >= 0 && cmp(x.y, z.y) <= 0) flag2 = 1;
  if (cmp(x.y, z.y) >= 0 && cmp(x.y, y.y) <= 0) flag2 = 1;
  return flag1 & flag2;
}
int intersect(point x0, point y0, point x1, point y1, point &ret) {
  point l1, l2;
  l1 = x0 / y0;
  l2 = x1 / y1;
  ret = l1 / l2;
  if (cmp(ret.z, 0) == 0) return 0;
  ret.x /= ret.z;
  ret.y /= ret.z;
  ret.z = 1;
  return in(ret, x0, y0) && in(ret, x1, y1);
}
int cross(point x0, point y0, point x1, point y1) {
  if (inl(x1, x0, y0) && inl(y1, x0, y0))
    return in(x1, x0, y0) || in(y1, x0, y0) || in(x0, x1, y1) || in(y0, x1, y1);
  point a = y0 - x0;
  int flag1 = 0, flag2 = 0;
  if (cmp(((x1 - x0) / a).z * ((y1 - x0) / a).z, 0) <= 0) flag1 = 1;
  a = y1 - x1;
  if (cmp(((x0 - x1) / a).z * ((y0 - x1) / a).z, 0) <= 0) flag2 = 1;
  return flag1 & flag2;
}
int sgn(double x) { return cmp(x, 0); }
point midvectical(point x, point y) {
  point ret = x / y, z = (x + y) * 0.5;
  swap(ret.x, ret.y);
  ret.y = -ret.y;
  ret.z = -(z.x * ret.x + z.y * ret.y);
  return ret;
}
double dist(point a, point b) { return hypot(a.x - b.x, a.y - b.y); }
double ans, sum, tot;
point S, T, a[110], lis[10];
int cnt, n, sm, len;
int main() {
  scanf("%lf%lf%lf%lf", &S.x, &S.y, &T.x, &T.y);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lf%lf", &a[i].x, &a[i].y);
  a[n] = a[0];
  point las = (point){1000, 1000, 1};
  for (int i = 0; i < n; i++) {
    sum += dist(a[i + 1], a[i]);
    if (intersect(a[i], a[i + 1], S, T, tmp)) {
      if (tmp < las || las < tmp) {
        lis[++len] = tmp;
        if (!cnt)
          tot += dist(tmp, a[i + 1]);
        else
          tot += dist(a[i], tmp);
        cnt ^= 1;
        las = tmp;
        continue;
      }
    } else if (inl(a[i], S, T) && inl(a[i + 1], S, T))
      sm++;
    if (cnt) tot += dist(a[i], a[i + 1]);
  }
  if (len < 2 || sm) {
    printf("%.9lf\n", dist(S, T));
    return 0;
  }
  if (len >= 2) {
    sort(lis + 1, lis + len + 1);
    for (int i = 2; i <= len; i++)
      if (!(lis[i - 1] < lis[i]) && !(lis[i] < lis[i - 1])) {
        for (int j = i + 1; j <= len; j++) lis[j - 1] = lis[j];
        len--;
      }
    ans = 1e50;
    if (dist(lis[1], S) > dist(lis[2], S)) swap(lis[1], lis[2]);
    ans =
        min(dist(S, lis[1]) + 2 * dist(lis[1], lis[2]) + dist(lis[2], T), ans);
    ans = min(dist(lis[1], S) + dist(lis[2], T) + min(tot, sum - tot), ans);
    printf("%.9lf\n", ans);
    return 0;
  }
  while (1)
    ;
  return 0;
}
