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 splitstr(const string &s, vector<T> &out) {
  istringstream in(s);
  out.clear();
  copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
static void redirect(int argc, const char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  if (argc > 1) {
    static filebuf f;
    f.open(argv[1], ios::in);
    cin.rdbuf(&f);
    if (!cin) {
      cerr << "Failed to open '" << argv[1] << "'" << endl;
      exit(1);
    }
  }
  if (argc > 2) {
    static filebuf f;
    f.open(argv[2], ios::out | ios::trunc);
    cout.rdbuf(&f);
    if (!cout) {
      cerr << "Failed to open '" << argv[2] << "'" << endl;
    }
  }
  cin.exceptions(ios::failbit);
}
template <typename T>
static inline T dot(const std::complex<T> &a, const std::complex<T> &b) {
  return real(conj(a) * b);
}
template <typename T>
static inline T cross(const std::complex<T> &a, const std::complex<T> &b) {
  return imag(conj(a) * b);
}
template <typename T>
static inline T cross(const std::complex<T> &a, const std::complex<T> &b,
                      const std::complex<T> &c) {
  return cross(b - a, c - a);
}
class CompareX {
 public:
  template <typename T>
  bool operator()(const std::complex<T> &a, const std::complex<T> &b) const {
    if (a.real() != b.real())
      return a.real() < b.real();
    else
      return a.imag() < b.imag();
  }
};
class UnionFind {
 private:
  mutable std::vector<int> parent;

 public:
  explicit UnionFind(int size = 0) : parent(size, -1) {}
  int size() const { return parent.size(); }
  int find(int x) const {
    assert(x >= 0 && x < size());
    int y = x;
    while (parent[y] >= 0) y = parent[y];
    while (parent[x] >= 0) {
      int nxt = parent[x];
      parent[x] = y;
      x = nxt;
    }
    return y;
  }
  bool merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (-parent[x] > -parent[y]) std::swap(x, y);
    parent[y] += parent[x];
    parent[x] = y;
    return true;
  }
};
static void clip(vector<pair<complex<long long>, complex<long long>>> &edges,
                 const complex<long long> &p, const complex<long long> &q) {
  vector<pair<complex<long long>, complex<long long>>> out;
  vector<complex<long long>> cuts;
  for (const auto &e : edges) {
    long long c1 = cross(p, q, e.first);
    long long c2 = cross(p, q, e.second);
    if (c1 > 0 && c2 > 0)
      out.push_back(e);
    else if (c1 > 0 || c2 > 0) {
      complex<long long> cut = (e.first * c2 - e.second * c1) / (c2 - c1);
      if (c1 > 0)
        out.emplace_back(e.first, cut);
      else
        out.emplace_back(cut, e.second);
      cuts.push_back(cut);
    }
  }
  sort(begin(cuts), end(cuts),
       [&](const complex<long long> &a, const complex<long long> &b) {
         return dot(q - p, b - a) > 0;
       });
  for (int i = 0; i + 1 < ((long long)(cuts).size()); i += 2)
    out.emplace_back(cuts[i], cuts[i + 1]);
  edges = move(out);
}
static void solve() {
  int N;
  long long x1, y1, x2, y2;
  cin >> x1 >> y2 >> x2 >> y1;
  cin >> N;
  vector<complex<long long>> pnts(N);
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    pnts[i] = complex<long long>(x, y);
  }
  vector<pair<complex<long long>, complex<long long>>> edges(N);
  for (int i = 0; i < N; i++) edges[i] = make_pair(pnts[i], pnts[(i + 1) % N]);
  clip(edges, complex<long long>(100000, y2), complex<long long>(-1, y2));
  clip(edges, complex<long long>(x1, 100000), complex<long long>(x1, -1));
  clip(edges, complex<long long>(-1, y1), complex<long long>(100000, y1));
  clip(edges, complex<long long>(x2, -1), complex<long long>(x2, 100000));
  map<complex<long long>, int, CompareX> ids;
  int M = 0;
  for (const auto &e : edges) {
    if (!ids.count(e.first)) ids[e.first] = M++;
    if (!ids.count(e.second)) ids[e.second] = M++;
  }
  UnionFind uf(M);
  int C = M;
  for (const auto &e : edges)
    if (uf.merge(ids[e.first], ids[e.second])) C--;
  cout << C << '\n';
}
int main(int argc, const char **argv) {
  redirect(argc, argv);
  solve();
  return 0;
}