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;
struct Pt {
  long long int x, y;
  friend istream &operator>>(istream &is, Pt &a) {
    is >> a.x >> a.y;
    return is;
  }
  friend ostream &operator<<(ostream &os, Pt &a) {
    os << "[" << a.x << "," << a.y << "]";
    return os;
  }
};
struct Edge {
  long long int a, b, h;
  friend ostream &operator<<(ostream &os, Edge &a) {
    os << "[" << a.a << "," << a.b << "," << a.h << "]";
    return os;
  }
  bool operator<(const Edge &x) const {
    return h != x.h ? h < x.h : (b != x.b ? b < x.b : a < x.a);
  }
};
struct Pair {
  long long int x, s;
  bool operator<(const Pair &p) const { return x < p.x; }
  friend ostream &operator<<(ostream &os, Pair &a) {
    os << "[" << a.x << "," << a.s << "]";
    return os;
  }
};
int main() {
  ios::sync_with_stdio(false);
  Pt s, e;
  cin >> s >> e;
  if (s.x > e.x) swap(s.x, e.x);
  if (s.y > e.y) swap(s.y, e.y);
  long long int N;
  cin >> N;
  vector<Pt> points(N);
  vector<Edge> edges(N / 2);
  for (long long int i = (0); i < (long long int)(N); ++i) cin >> points[i];
  for (int i = points[0].y != points[1].y; i < N; i += 2) {
    long long int j = (i + 1) % N;
    edges[i / 2] = {points[i].x, points[j].x, points[i].y};
  }
  for (Edge &w : edges)
    if (w.a > w.b) swap(w.a, w.b);
  sort(edges.begin(), edges.end());
  for (Edge &w : edges) {
    w.a = max(min(w.a, e.x), s.x);
    w.b = max(min(w.b, e.x), s.x);
  }
  for (auto it = edges.begin(); it != edges.end();) {
    if (it->a == it->b)
      it = edges.erase(it);
    else
      ++it;
  }
  long long int total = 0;
  bool f = 1;
  set<Pair> c;
  bool counting = false;
  for (Edge &w : edges) {
    long long int a = w.a, b = w.b;
    if (f && s.y < w.h) {
      f = 0;
      total = c.size() / 2;
    }
    if (e.y <= w.h) break;
    auto ita = c.find({a});
    bool aa = ita != c.end();
    auto itb = c.find({b});
    bool bb = itb != c.end();
    bool flip = 0;
    if (!f) {
      if (aa && bb) {
        if (ita->s == 0 && itb->s == 1) {
          total--;
        }
      } else if (!aa && !bb) {
        auto itt = c.upper_bound({b});
        if (itt == c.end() || itt->s == 1) {
          total++;
        } else {
          flip = 1;
        }
      } else
        ;
    } else {
      if (!aa && !bb) {
        auto itt = c.upper_bound({b});
        if (itt == c.end() || itt->s == 1) {
        } else {
          flip = 1;
        }
      }
    }
    long long int sa = ita != c.end() && ita->s;
    long long int sb = itb != c.end() && itb->s;
    if (aa)
      c.erase(ita);
    else
      c.insert({a, (sb || !bb) ^ flip});
    if (bb)
      c.erase(itb);
    else
      c.insert({b, (sa) ^ flip});
  }
  cout << total << endl;
  return 0;
}