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;
int n;
int lx, rx, ly, ry, px[15010], py[15010];
class seg {
 public:
  int y, ldx, cxy;
  bool is_add;
  bool operator<(const seg &t) const { return y < t.y; }
  seg(int _y, int _x1, int _x2, bool a) {
    y = _y, ldx = _x1, cxy = _x2;
    is_add = a;
  }
};
class pt {
 public:
  int ldx;
  mutable int cxy, g;
  pt(int _x1, int _x2, int _g) { ldx = _x1, cxy = _x2, g = _g; };
  bool operator<(const pt &t) const { return ldx < t.ldx; }
};
vector<seg> s;
vector<pair<int, int> > group;
int cnt;
set<pt> p;
int getf(int x) {
  while (group[x].second >= 0) x = group[x].second;
  return x;
}
void merge(int g1, int g2) {
  g1 = getf(g1);
  g2 = getf(g2);
  group[g2].second = g1;
  group[g1].first += group[g2].first - 1;
}
void process(seg s) {
  pt d(s.ldx, 0, 0);
  auto prev = p.lower_bound(d);
  if (prev->ldx > s.ldx) --prev;
  auto next = prev;
  next++;
  if (s.is_add) {
    if (prev->cxy == s.ldx) {
      prev->cxy = s.cxy;
      if (next->ldx == s.cxy) {
        merge(prev->g, next->g);
        prev->cxy = next->cxy;
        p.erase(next);
      }
    } else if (next->ldx == s.cxy) {
      int ldx = s.ldx, cxy = next->cxy, gr = getf(next->g);
      p.erase(next);
      p.emplace(ldx, cxy, gr);
    } else {
      group.push_back(make_pair(1, -1));
      p.emplace(s.ldx, s.cxy, group.size() - 1);
    }
  } else {
    int ldx, cxy, gr;
    ldx = prev->ldx;
    cxy = prev->cxy;
    gr = getf(prev->g);
    p.erase(prev);
    if (s.ldx == ldx && s.cxy == cxy) {
      group[gr].first--;
      if (group[gr].first == 0 && s.y > ly) cnt++;
    } else {
      if (s.ldx > ldx && s.cxy == cxy)
        p.emplace(ldx, s.ldx, gr);
      else if (s.cxy < cxy && s.ldx == ldx)
        p.emplace(s.cxy, cxy, gr);
      else {
        p.emplace(ldx, s.ldx, gr);
        if (s.y <= ly) {
          group.push_back(make_pair(1, -1));
          gr = group.size() - 1;
        } else {
          group[gr].first++;
        }
        p.emplace(s.cxy, cxy, gr);
      }
    }
  }
}
void add_seg(int y, int ldx, int cxy) {
  bool is_add = 0;
  if (ldx > cxy) swap(ldx, cxy), is_add = 1;
  if (ldx >= rx || cxy <= lx) return;
  ldx = max(ldx, lx);
  cxy = min(cxy, rx);
  s.emplace_back(y, ldx, cxy, is_add);
}
int main() {
  scanf("%d%d%d%d", &lx, &ry, &rx, &ly);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d%d", &px[i], &py[i]);
  px[n] = px[0];
  py[n] = py[0];
  for (int i = 0; i < n; i++) {
    if (py[i] == py[i + 1]) add_seg(py[i], px[i + 1], px[i]);
  }
  sort(s.begin(), s.end());
  p.emplace(-1, -1, -1);
  p.emplace(1e9 + 1, 1e9 + 1, -1);
  for (auto &x : s) {
    if (x.y >= ry) {
      for (auto &c : group)
        if (c.second < 0 && c.first > 0) cnt++;
      break;
    }
    process(x);
  }
  printf("%d\n", cnt);
  return 0;
}