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;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 15005;
struct disj {
  int pa[MAXN];
  void init(int n) { iota(pa, pa + n + 1, 0); }
  int find(int x) { return pa[x] = (pa[x] == x ? x : find(pa[x])); }
  bool uni(int p, int q) {
    p = find(p);
    q = find(q);
    if (p == q) return 0;
    pa[q] = p;
    return 1;
  }
} disj;
struct rect {
  int sx, ex, sy, ey;
};
struct block {
  int pos, s, e;
  bool operator<(const block &b) const { return pi(s, e) < pi(b.s, b.e); }
};
struct swp {
  int yc, xs, xe, act;
  bool operator<(const swp &b) const { return pi(yc, -act) < pi(b.yc, -b.act); }
};
int n;
pi a[MAXN];
vector<rect> ans;
void make_rect() {
  vector<swp> event;
  set<block> s;
  for (int i = 0; i < n; i++) {
    pi p1 = a[i];
    pi p2 = a[(i + 1) % n];
    if (p1.second == p2.second) continue;
    if (p1.second < p2.second) {
      event.push_back({p1.first, p1.second, p2.second, -1});
    } else {
      event.push_back({p1.first, p2.second, p1.second, +1});
    }
  }
  sort(event.begin(), event.end());
  auto rect_close = [&](block b, int pos) {
    if (b.pos < pos) {
      ans.push_back({b.pos, pos, b.s, b.e});
    }
  };
  for (int i = 0; i < event.size();) {
    int e = i;
    while (e < event.size() && event[e].yc == event[i].yc) {
      if (event[e].act == 1) {
        auto lbnd = s.lower_bound({-1, event[e].xs, event[e].xe});
        int curs = event[e].xs;
        int cure = event[e].xe;
        if (lbnd != s.begin() && prev(lbnd)->e == event[e].xs) {
          curs = prev(lbnd)->s;
          rect_close(*prev(lbnd), event[e].yc);
          s.erase(prev(lbnd));
        }
        if (lbnd != s.end() && lbnd->s == event[e].xe) {
          cure = lbnd->e;
          rect_close(*lbnd, event[e].yc);
          s.erase(lbnd);
        }
        s.insert({event[e].yc, curs, cure});
      } else {
        auto lbnd = --s.lower_bound({-1, event[e].xe + 1, -1});
        if (pi(lbnd->s, lbnd->e) == pi(event[e].xs, event[e].xe)) {
          rect_close(*lbnd, event[e].yc);
          s.erase(lbnd);
        } else if (lbnd->s == event[e].xs) {
          rect_close(*lbnd, event[e].yc);
          s.erase(lbnd);
          s.insert({event[e].yc, event[e].xe, lbnd->e});
        } else if (lbnd->e == event[e].xe) {
          rect_close(*lbnd, event[e].yc);
          s.erase(lbnd);
          s.insert({event[e].yc, lbnd->s, event[e].xs});
        } else {
          rect_close(*lbnd, event[e].yc);
          block nxt1 = {event[e].yc, lbnd->s, event[e].xs};
          block nxt2 = {event[e].yc, event[e].xe, lbnd->e};
          s.erase(lbnd);
          s.insert(nxt1);
          s.insert(nxt2);
        }
      }
      e++;
    }
    i = e;
  }
  for (auto &i : ans) {
  }
}
bool insec_by_edge(rect x, rect y) {
  x.sx = max(x.sx, y.sx);
  x.ex = min(x.ex, y.ex);
  x.sy = max(x.sy, y.sy);
  x.ey = min(x.ey, y.ey);
  if (x.sx > x.ex || x.sy > x.ey) return 0;
  if (x.sx < x.ex && x.sy < x.ey) assert(0);
  if (pi(x.sx, x.sy) == pi(x.ex, x.ey)) return 0;
  return 1;
}
int main() {
  pi x, y;
  scanf("%d %d %d %d %d", &x.first, &y.second, &y.first, &x.second, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a[i].first, &a[i].second);
  }
  a[n] = a[0];
  make_rect();
  vector<rect> comp = ans;
  ans.clear();
  for (auto &i : comp) {
    i.sx = max(i.sx, x.first);
    i.ex = min(i.ex, y.first);
    i.sy = max(i.sy, x.second);
    i.ey = min(i.ey, y.second);
    if (i.sx < i.ex && i.sy < i.ey) ans.push_back(i);
  }
  disj.init(ans.size());
  int cnt = 0;
  for (int i = 0; i < ans.size(); i++) {
    for (int j = 0; j < i; j++) {
      if (insec_by_edge(ans[i], ans[j])) {
        cnt += disj.uni(i, j);
      }
    }
  }
  cout << ans.size() - cnt << endl;
}