Problem: Petya has a polygon consisting of n vertices. All sides of the Petya's polygon are parallel to the coordinate axes, and each two adjacent sides of the Petya's polygon are perpendicular. It is guaranteed that the polygon is simple, that is, it doesn't have self-intersections and self-touches. All internal area of the polygon (borders are not included) was painted in black color by Petya.

Also, Petya has a rectangular window, defined by its coordinates, through which he looks at the polygon. A rectangular window can not be moved. The sides of the rectangular window are parallel to the coordinate axes.

<image> Blue color represents the border of a polygon, red color is the Petya's window. The answer in this case is 2.

Determine the number of black connected areas of Petya's polygon, which can be seen through the rectangular window.

Input

The first line contain four integers x_1, y_1, x_2, y_2 (x_1 < x_2, y_2 < y_1) — the coordinates of top-left and bottom-right corners of the rectangular window. 

The second line contains a single integer n (4 ≤ n ≤ 15 000) — the number of vertices in Petya's polygon.

Each of the following n lines contains two integers — the coordinates of vertices of the Petya's polygon in counterclockwise order. Guaranteed, that the given polygon satisfies the conditions described in the statement.

All coordinates of the rectangular window and all coordinates of the vertices of the polygon are non-negative and do not exceed 15 000.

Output

Print the number of black connected areas of Petya's polygon, which can be seen through the rectangular window.

Example

Input

5 7 16 3
16
0 0
18 0
18 6
16 6
16 1
10 1
10 4
7 4
7 2
2 2
2 6
12 6
12 12
10 12
10 8
0 8


Output

2

Note

The example corresponds to the picture above.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <class T>
void mini(T &l, T r) {
  l = min(l, r);
}
template <class T>
void maxi(T &l, T r) {
  l = max(l, r);
}
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool a) { return a ? "T" : "F"; }
string to_string(const char *s) { return to_string((string)s); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
using ll = long long;
using ld = long double;
const int N = 1.5e4 + 10;
struct Point {
  ll x, y;
  Point operator+(Point b) { return Point{x + b.x, y + b.y}; }
  Point operator-(Point b) { return Point{x - b.x, y - b.y}; }
  bool operator<(Point b) const {
    return make_pair(x, y) < make_pair(b.x, b.y);
  }
  bool operator==(Point b) const {
    return make_pair(x, y) == make_pair(b.x, b.y);
  }
  bool operator!=(Point b) const {
    return make_pair(x, y) != make_pair(b.x, b.y);
  }
  ll operator*(Point b) const { return x * b.x + y * b.y; }
  ll operator%(Point b) const { return x * b.y - y * b.x; }
} none{-N, -N};
string to_string(Point a) { return to_string(make_pair(a.x, a.y)); }
ll ox[2], oy[2];
Point pto[4];
Point pt[N];
int n;
vector<Point> vp[4];
int sgn(ll x) {
  if (x > 0) return 1;
  if (x == 0) return 0;
  return -1;
}
int dif(Point x, Point y, Point a, Point b) {
  return sgn((y - x) % (a - x)) * sgn((y - x) % (b - x));
}
Point get_intersect(Point x, Point y, Point a, Point b) {
  if (x.x == y.x) {
    return Point{x.x, a.y};
  } else {
    return Point{a.x, x.y};
  }
}
bool is_left(Point a, Point x, Point y) { return (x - a) % (y - x) > 0; }
tuple<Point, Point> get(Point x, Point y, Point a, Point b) {
  Point t1 = none, t2 = none;
  int d1 = dif(x, y, a, b), d2 = dif(a, b, x, y);
  Point t = get_intersect(x, y, a, b);
  if (max(d1, d2) <= 0) {
    if (is_left(a, x, y) || is_left(b, x, y)) {
      t1 = t;
    }
    if (is_left(x, a, b) || is_left(y, a, b)) {
      t2 = t;
    }
  }
  return make_tuple(t1, t2);
}
bool in(Point x) {
  return x.x >= ox[0] && x.x <= ox[1] && x.y >= oy[1] && x.y <= oy[0];
}
tuple<Point, Point> get_left(Point x, Point y) {
  Point t1, t2;
  Point d = y - x;
  d.x = sgn(d.x), d.y = sgn(d.y);
  Point d2 = {-d.y, d.x};
  t1 = x + d + d2;
  t2 = y - d + d2;
  return make_tuple(t1, t2);
}
tuple<Point, Point> get_left_st(Point x, Point y) {
  Point t1, t2;
  Point d = y - x;
  d.x = sgn(d.x), d.y = sgn(d.y);
  Point d2 = {-d.y, d.x};
  t1 = x + d + d2;
  t2 = x - d + d2;
  return make_tuple(t1, t2);
}
tuple<Point, Point> get_left_ed(Point x, Point y) {
  Point t1, t2;
  Point d = y - x;
  d.x = sgn(d.x), d.y = sgn(d.y);
  Point d2 = {-d.y, d.x};
  t1 = y + d + d2;
  t2 = y - d + d2;
  return make_tuple(t1, t2);
}
struct Dsu {
  vector<int> fa;
  map<Point, int> mp;
  int find(int x) { return fa[x] == x ? x : (fa[x] = find(fa[x])); }
  void mrg(int x, int y) {
    x = find(x), y = find(y);
    if (x != y) fa[x] = y;
  }
  void add(Point a) {
    42;
    if (mp.count(a)) {
      return;
    }
    42;
    int t = fa.size();
    mp[a] = t;
    fa.push_back(t);
  }
  void mrg(Point a, Point b) {
    add(a);
    add(b);
    mrg(mp[a], mp[b]);
  }
  int cnt() {
    set<int> st;
    for (auto &kv : mp) {
      if (in(kv.first)) {
        42;
        42;
        st.insert(find(kv.second));
      }
    }
    return st.size();
  }
} dsu;
int check(Point a, Point b) {
  int c = 0;
  for (int i = 0; i < n; ++i) {
    Point t1, t2;
    tie(t1, t2) = get(a, b, pt[i], pt[(i + 1) % n]);
    if (t1 != none) {
      c ^= 1;
    }
  }
  return c;
}
void run() {
  cin >> ox[0] >> oy[0] >> ox[1] >> oy[1];
  for (int i = 0; i < 2; ++i) ox[i] *= 2, oy[i] *= 2;
  pto[0] = {ox[0], oy[0]};
  pto[1] = {ox[0], oy[1]};
  pto[2] = {ox[1], oy[1]};
  pto[3] = {ox[1], oy[0]};
  cin >> n;
  for (int i = 0; i < n; ++i) {
    ll x, y;
    cin >> x >> y;
    pt[i] = {x * 2, y * 2};
  }
  vector<int> v;
  for (int i = 0; i < n; ++i) {
    vector<Point> v;
    for (int j = 0; j < 4; ++j) {
      Point t1, t2;
      tie(t1, t2) = get(pt[i], pt[(i + 1) % n], pto[j], pto[(j + 1) % 4]);
      if (t1 != none) {
        v.push_back(t1);
      }
      if (t2 != none) {
        vp[j].push_back(t2);
      }
      42;
    }
    auto calc = [=](Point a) {
      return (a - pt[i]) * (pt[(i + 1) % n] - pt[i]);
    };
    sort(v.begin(), v.end(),
         [=](Point a, Point b) { return calc(a) < calc(b); });
    if ((pt[i] - pt[(i + (n - 1)) % n]) % (pt[(i + 1) % n] - pt[i]) < 0) {
      Point a, b;
      tie(a, b) = get_left_st(pt[i], pt[(i + 1) % n]);
      if (v.empty() || v[0] != pt[i]) {
        dsu.mrg(a, b);
      }
    }
    if ((pt[(i + 1) % n] - pt[i]) % (pt[(i + 2) % n] - pt[(i + 1) % n]) < 0) {
      Point a, b;
      tie(a, b) = get_left_ed(pt[i], pt[(i + 1) % n]);
      if (v.empty() || v.back() != pt[(i + 1) % n]) {
        dsu.mrg(a, b);
      }
    }
    v.insert(v.begin(), pt[i]);
    v.push_back(pt[(i + 1) % n]);
    v.erase(unique(v.begin(), v.end()), v.end());
    for (int j = 0; j + 1 < (int)v.size(); ++j) {
      Point a, b;
      tie(a, b) = get_left(v[j], v[j + 1]);
      dsu.mrg(a, b);
    }
  }
  for (int i = 0; i < 4; ++i) {
    vp[i].push_back(pto[i]);
    vp[i].push_back(pto[(i + 1) % 4]);
    42;
    auto calc = [=](Point a) {
      return (a - pto[i]) * (pto[(i + 1) % 4] - pto[i]);
    };
    sort(vp[i].begin(), vp[i].end(),
         [=](Point a, Point b) { return calc(a) < calc(b); });
    vp[i].erase(unique(vp[i].begin(), vp[i].end()), vp[i].end());
    42;
    for (int j = 0; j + 1 < vp[i].size(); ++j) {
      Point a, b;
      tie(a, b) = get_left(vp[i][j], vp[i][j + 1]);
      42;
      42;
      if (dsu.mp.count(a) && dsu.mp.count(b)) dsu.mrg(a, b);
    }
  }
  auto ans = dsu.cnt();
  Point o = {(ox[0] + ox[1]) / 2, (oy[0] + oy[1]) / 2};
  Point p = o + Point{0, N};
  if (check(o, p)) {
    ans = max(ans, 1);
  }
  cout << ans << endl;
}
int main() {
  run();
  return 0;
}