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;
const double PI = acos(-1);
template <typename T>
T getint() {
  T val = 0;
  char c;
  bool neg = false;
  while ((c = getchar()) && !(c >= '0' && c <= '9')) {
    neg |= c == '-';
  }
  do {
    val = (val * 10) + c - '0';
  } while ((c = getchar()) && (c >= '0' && c <= '9'));
  return val * (neg ? -1 : 1);
}
struct SumTree {
  vector<int> t;
  vector<int> tree;
  vector<int> lazy;
  SumTree(vector<int>& t_) {
    t = t_;
    tree.assign(4 * (int)(t).size(), 0);
    lazy.assign(4 * (int)(t).size(), -1);
  }
  void build() { build(1, 0, (int)(t).size() - 1); }
  int query(int i, int j) { return query(1, 0, (int)(t).size() - 1, i, j); }
  void update(int i, int j, int val) {
    update(1, 0, (int)(t).size() - 1, i, j, val);
  }
  void update(int i, int val) { updatept(1, 0, (int)(t).size() - 1, i, val); }

 private:
  inline int combine(int x, int y) { return x + y; }
  void propogate(int ind, int L, int R) {
    if (lazy[ind] != -1) {
      if (L == R) {
        tree[ind] = lazy[ind];
      } else {
        tree[ind] = lazy[ind] * (R - L + 1);
        lazy[2 * ind] = lazy[2 * ind + 1] = lazy[ind];
      }
      lazy[ind] = -1;
    }
  }
  void pull(int ind, int L, int R) {
    propogate(2 * ind, L, (L + R) / 2);
    propogate(2 * ind + 1, (L + R) / 2 + 1, R);
    tree[ind] = combine(tree[2 * ind], tree[2 * ind + 1]);
  }
  void build(int ind, int L, int R) {
    if (L == R) {
      tree[ind] = t[L];
    } else {
      build(2 * ind, L, (L + R) / 2);
      build(2 * ind + 1, (L + R) / 2 + 1, R);
      pull(ind, L, R);
    }
  }
  int query(int ind, int L, int R, int i, int j) {
    if (R < i || j < L) return 0;
    propogate(ind, L, R);
    if (i <= L && R <= j) return tree[ind];
    return combine(query(2 * ind, L, (L + R) / 2, i, j),
                   query(2 * ind + 1, (L + R) / 2 + 1, R, i, j));
  }
  void update(int ind, int L, int R, int i, int j, int val) {
    if (R < i || j < L) return;
    propogate(ind, L, R);
    if (i <= L && R <= j) {
      lazy[ind] = val;
      propogate(ind, L, R);
      return;
    }
    update(2 * ind, L, (L + R) / 2, i, j, val);
    update(2 * ind + 1, (L + R) / 2 + 1, R, i, j, val);
    pull(ind, L, R);
  }
  void updatept(int ind, int L, int R, int i, int val) {
    if (R < i || i < L) return;
    propogate(ind, L, R);
    if (L == R) {
      lazy[ind] = val;
      propogate(ind, L, R);
      return;
    }
    updatept(2 * ind, L, (L + R) / 2, i, val);
    updatept(2 * ind + 1, (L + R) / 2 + 1, R, i, val);
    pull(ind, L, R);
  }
};
struct SegTree {
  vector<int> t;
  vector<int> tree;
  vector<int> lazy;
  SumTree* sum = NULL;
  SegTree(vector<int>& t_) {
    sum = new SumTree(t_);
    t = t_;
    tree.assign(4 * (int)(t).size(), 0);
    lazy.assign(4 * (int)(t).size(), -1);
  }
  void build() { build(1, 0, (int)(t).size() - 1); }
  int query(int i, int j) { return query(1, 0, (int)(t).size() - 1, i, j); }
  void update(int i, int j, int val) {
    sum->update(i, j, val);
    update(1, 0, (int)(t).size() - 1, i, j, val);
  }

 private:
  inline int combine(int x, int y) { return max(x, y); }
  void propogate(int ind, int L, int R) {
    if (lazy[ind] != -1) {
      if (L == R) {
        tree[ind] = lazy[ind];
      } else {
        tree[ind] = lazy[ind];
        lazy[2 * ind] = lazy[2 * ind + 1] = lazy[ind];
      }
      lazy[ind] = -1;
    }
  }
  void pull(int ind, int L, int R) {
    propogate(2 * ind, L, (L + R) / 2);
    propogate(2 * ind + 1, (L + R) / 2 + 1, R);
    tree[ind] = combine(tree[2 * ind], tree[2 * ind + 1]);
  }
  void build(int ind, int L, int R) {
    if (L == R) {
      tree[ind] = t[L];
    } else {
      build(2 * ind, L, (L + R) / 2);
      build(2 * ind + 1, (L + R) / 2 + 1, R);
      pull(ind, L, R);
    }
  }
  int query(int ind, int L, int R, int i, int j) {
    if (R < i || j < L) return 0;
    propogate(ind, L, R);
    if (i <= L && R <= j) return tree[ind];
    return combine(query(2 * ind, L, (L + R) / 2, i, j),
                   query(2 * ind + 1, (L + R) / 2 + 1, R, i, j));
  }
  void update(int ind, int L, int R, int i, int j, int val) {
    if (R < i || j < L) return;
    propogate(ind, L, R);
    if (i <= L && R <= j) {
      lazy[ind] = val;
      propogate(ind, L, R);
      return;
    }
    update(2 * ind, L, (L + R) / 2, i, j, val);
    update(2 * ind + 1, (L + R) / 2 + 1, R, i, j, val);
    pull(ind, L, R);
  }
};
struct vert {
  int x, y1, y2;
};
const int MAXN = 30001;
int par[MAXN], sz[MAXN];
void init() {
  memset(par, -1, sizeof par);
  for (int i = 0; i < MAXN; ++i) sz[i] = 1;
}
int get(int x) {
  if (par[x] == -1) return x;
  return par[x] = get(par[x]);
}
void merge(int x, int y) {
  int px = get(x), py = get(y);
  if (px == py) return;
  if (sz[px] > sz[py]) swap(px, py);
  par[px] = py;
  sz[py] += sz[px];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  init();
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int n;
  cin >> n;
  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i].first >> p[i].second;
  }
  vector<vert> v;
  for (int i = 0; i < n; ++i) {
    pair<int, int> akt = p[i], nxt = p[(i + 1) % n];
    if (akt.first == nxt.first) {
      pair<int, int> seg = {min(akt.second, nxt.second),
                            max(akt.second, nxt.second)};
      if (seg.second < y2 || seg.first > y1) continue;
      vert kovi = {akt.first, max(seg.first, y2), min(seg.second, y1) - 1};
      if (kovi.y1 > kovi.y2) continue;
      v.push_back(kovi);
    }
  }
  sort((v).begin(), (v).end(), [](vert& egyik, vert& masik) -> bool {
    if (egyik.x == masik.x) return egyik.y1 < masik.y1;
    return egyik.x < masik.x;
  });
  vector<int> ures(16000);
  SegTree st(ures);
  vector<int> fontos;
  int id = 1;
  for (vert i : v) {
    if (i.x >= x2) break;
    int val = st.query(i.y1, i.y2);
    if (val > 0) {
      if (i.x <= x1 && st.query(i.y2 + 1, i.y2 + 1) == val && i.y1 - 1 >= 0 &&
          st.query(i.y1 - 1, i.y1 - 1) == val) {
        if (st.query(i.y2 + 1, i.y2 + 1) == val) {
          int akt = 0;
          for (int j = 15; j >= 0; j--) {
            int nxt = akt + (1 << j);
            if (i.y2 + 1 + nxt <= 15555 &&
                st.sum->query(i.y2 + 1, i.y2 + 1 + nxt) == (nxt + 1) * val) {
              akt = nxt;
            }
          }
          st.update(i.y2 + 1, i.y2 + 1 + akt, id++);
        }
      }
      if (i.x > x1) fontos.push_back(val);
      st.update(i.y1, i.y2, 0);
    } else {
      int l = 0, r = 0;
      if (i.y1 >= 1) l = st.query(i.y1 - 1, i.y2);
      r = st.query(i.y1, i.y2 + 1);
      if (i.x >= x1 && i.x <= x2) {
        if (l > 0) merge(l, id);
        if (r > 0) merge(r, id);
      }
      if (i.x >= x1) fontos.push_back(id);
      st.update(i.y1, i.y2, id++);
    }
  }
  for (int i = 0; i < 16000; ++i) {
    int q = st.query(i, i);
    if (q) fontos.push_back(q);
  }
  vector<int> lst;
  for (auto i : fontos) {
    lst.push_back(get(i));
  }
  sort((lst).begin(), (lst).end());
  lst.resize(distance(lst.begin(), unique((lst).begin(), (lst).end())));
  cout << (int)(lst).size() << "\n";
  return 0;
}