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 int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
struct Point {
  int x, y;
  Point(int _x = 0, int _y = 0) : x(_x), y(_y) {}
  Point operator+(const Point &b) const { return Point(x + b.x, y + b.y); }
  Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); }
  int operator^(const Point &b) const { return (x * b.y - y * b.x); }
} p[maxn];
Point a, b, c, d, e;
int w, h;
vector<pair<int, int> > f;
bool isPointOnSegment(Point p, Point s, Point e) {
  return ((p - s) ^ (s - e)) == 0 && ((p.x - s.x) * (p.x - e.x)) <= 0 &&
         ((p.y - s.y) * (p.y - e.y)) <= 0;
}
void pre_solve(Point u, Point v) {
  if (u.x == v.x) {
    if (u.x == a.x || u.x == b.x) return;
    if (min(u.y, v.y) >= c.y || max(u.y, v.y) <= a.y) return;
    if (abs(u.y - a.y) < abs(u.y - d.y)) {
      e = Point(u.x, a.y);
      if (isPointOnSegment(e, a, b) && isPointOnSegment(e, u, v))
        f.push_back(pair<int, int>(e.x - a.x, ((b - a) ^ (v - a)) > 0));
      e = Point(u.x, c.y);
      if (isPointOnSegment(e, c, d) && isPointOnSegment(e, u, v))
        f.push_back(pair<int, int>(w + h + c.x - e.x, ((d - c) ^ (v - c)) > 0));
    } else {
      e = Point(u.x, c.y);
      if (isPointOnSegment(e, c, d) && isPointOnSegment(e, u, v))
        f.push_back(pair<int, int>(w + h + c.x - e.x, ((d - c) ^ (v - c)) > 0));
      e = Point(u.x, a.y);
      if (isPointOnSegment(e, a, b) && isPointOnSegment(e, u, v))
        f.push_back(pair<int, int>(e.x - a.x, ((b - a) ^ (v - a)) > 0));
    }
  } else {
    if (u.y == a.y || u.y == d.y) return;
    if (min(u.x, v.x) >= c.x || max(u.x, v.x) <= a.x) return;
    if (abs(u.x - a.x) < abs(u.x - b.x)) {
      e = Point(a.x, u.y);
      if (isPointOnSegment(e, a, d) && isPointOnSegment(e, u, v))
        f.push_back(
            pair<int, int>(w + w + h + d.y - e.y, ((a - d) ^ (v - d)) > 0));
      e = Point(c.x, u.y);
      if (isPointOnSegment(e, b, c) && isPointOnSegment(e, u, v))
        f.push_back(pair<int, int>(w + e.y - b.y, ((c - b) ^ (v - b)) > 0));
    } else {
      e = Point(c.x, u.y);
      if (isPointOnSegment(e, b, c) && isPointOnSegment(e, u, v))
        f.push_back(pair<int, int>(w + e.y - b.y, ((c - b) ^ (v - b)) > 0));
      e = Point(a.x, u.y);
      if (isPointOnSegment(e, a, d) && isPointOnSegment(e, u, v))
        f.push_back(
            pair<int, int>(w + w + h + d.y - e.y, ((a - d) ^ (v - d)) > 0));
    }
  }
}
int inConvexPoly(int n, Point a) {
  p[n] = p[0];
  for (int i = 0; i < n; i++) {
    if (((p[i] - a) ^ (p[i + 1] - a)) < 0)
      return 0;
    else if (isPointOnSegment(a, p[i], p[i + 1]))
      return 1;
  }
  return 1;
}
int check(int n) {
  int vis = 1;
  for (int i = 0; i < n; i++) {
    if (a.x <= p[i].x && p[i].x <= c.x && a.y <= p[i].y && p[i].y <= c.y)
      vis &= 1;
    else
      vis = 0;
  }
  if (!vis) {
    vis = 1;
    vis &= inConvexPoly(n, a);
    vis &= inConvexPoly(n, b);
    vis &= inConvexPoly(n, c);
    vis &= inConvexPoly(n, d);
  }
  return vis;
}
int fp[maxn], tot;
int ff(int x) {
  if (fp[x] != x) fp[x] = ff(fp[x]);
  return fp[x];
}
void funion(int x, int y) {
  x = ff(x);
  y = ff(y);
  if (x != y) {
    fp[x] = y;
    tot--;
  }
}
int main() {
  int n, m, i;
  scanf("%d%d%d%d", &a.x, &c.y, &c.x, &a.y);
  b = Point(c.x, a.y);
  d = Point(a.x, c.y);
  w = c.x - a.x;
  h = c.y - a.y;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d%d", &p[i].x, &p[i].y);
  p[n] = p[0];
  for (i = 0; i < n; i++) pre_solve(p[i], p[i + 1]);
  tot = m = f.size();
  if (m == 0) {
    printf("%d\n", check(n));
    return 0;
  }
  for (i = 0; i <= (w + h) * 2; i++) fp[i] = i;
  for (i = 1; i < m; i++) {
    if (f[i - 1].second == 1 && f[i].second == 0)
      funion(f[i - 1].first, f[i].first);
  }
  if (f[m - 1].second == 1 && f[0].second == 0)
    funion(f[m - 1].first, f[0].first);
  sort(f.begin(), f.end());
  f.push_back(f[0]);
  for (i = 0; i < m; i++) {
    if (f[i].second == 0 && f[i + 1].second == 1)
      funion(f[i].first, f[i + 1].first);
  }
  printf("%d\n", tot);
  return 0;
}