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 N = 100050;
int go[N][4], nxt[N], xl, yl, xr, yr, n, tsz, esz = 1, my[N], csz, sec[N];
map<pair<int, int>, int> edx;
pair<int, int> pts[N];
bool was[N];
vector<int> ply[N];
double area[N];
long long cross(pair<int, int> a, pair<int, int> b) {
  return (long long)a.first * b.second - (long long)a.second * b.first;
}
double Area(vector<int> p) {
  double ans = 0;
  for (int i = 0, j = (int)p.size() - 1; i < p.size(); j = i, i++) {
    ans += cross(pts[p[i]], pts[p[j]]);
  }
  return abs(ans) / 2;
}
void Connect(int u, int v) {
  edx[{u, v}] = ++esz;
  sec[esz] = v;
  edx[{v, u}] = ++esz;
  sec[esz] = u;
  if (pts[u].first == pts[v].first) {
    if (pts[u].second > pts[v].second) swap(u, v);
    go[v][0] = u;
    go[u][2] = v;
  } else {
    if (pts[u].first > pts[v].first) swap(u, v);
    go[v][1] = u;
    go[u][3] = v;
  }
}
void Build(int u) {
  for (int i = 0; i < 4; i++)
    if (go[u][i]) {
      for (int j = 1; j <= 4; j++)
        if (go[u][(i + j) % 4]) {
          nxt[edx[{go[u][i], u}]] = edx[{u, go[u][(i + j) % 4]}];
          break;
        }
    }
}
vector<int> side[4], E[N];
void AddEdge(int u, int v) {
  E[u].push_back(v);
  E[v].push_back(u);
}
double sum[2];
bool vis[N];
int ty[N];
void DFS(int u, int t = 0) {
  vis[u] = 1;
  sum[t] += area[u];
  ty[u] = t;
  for (int v : E[u])
    if (!vis[v]) DFS(v, t ^ 1);
}
bool CuttingRayTest(double first, double second) {
  int cnt = 0;
  for (int i = 1, j = n; i <= n; j = i, i++) {
    if (pts[i].first == pts[j].first && pts[i].first > first) {
      int mx = max(pts[i].second, pts[j].second);
      int mn = min(pts[i].second, pts[j].second);
      if (mn < second && mx > second) cnt++;
    }
  }
  return cnt % 2;
}
int main() {
  scanf("%i %i %i %i", &xl, &yr, &xr, &yl);
  scanf("%i", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%i %i", &pts[i].first, &pts[i].second);
  }
  tsz = n;
  pts[++tsz] = {xl, yl};
  pts[++tsz] = {xr, yl};
  pts[++tsz] = {xr, yr};
  pts[++tsz] = {xl, yr};
  side[0] = {n + 1, n + 2};
  side[1] = {n + 2, n + 3};
  side[2] = {n + 3, n + 4};
  side[3] = {n + 4, n + 1};
  for (int i = 1, j = n; i <= n; j = i, i++) {
    if (pts[i].first == pts[j].first) {
      int mn = min(pts[i].second, pts[j].second);
      int mx = max(pts[i].second, pts[j].second);
      if (xl < pts[i].first && pts[i].first < xr && mx > yl && mn < yr) {
        if (mn <= yl && mx >= yr) {
          pts[++tsz] = {pts[i].first, yl};
          side[0].push_back(tsz);
          pts[++tsz] = {pts[i].first, yr};
          side[2].push_back(tsz);
          Connect(tsz - 1, tsz);
        } else if (mn <= yl) {
          pts[++tsz] = {pts[i].first, yl};
          side[0].push_back(tsz);
          Connect(tsz, pts[i].second == mx ? i : j);
        } else if (mx >= yr) {
          pts[++tsz] = {pts[i].first, yr};
          side[2].push_back(tsz);
          Connect(tsz, pts[i].second == mn ? i : j);
        } else
          Connect(i, j);
      }
    } else {
      int mn = min(pts[i].first, pts[j].first);
      int mx = max(pts[i].first, pts[j].first);
      if (yl < pts[i].second && pts[i].second < yr && mx > xl && mn < xr) {
        if (mn <= xl && mx >= xr) {
          pts[++tsz] = {xl, pts[i].second};
          side[3].push_back(tsz);
          pts[++tsz] = {xr, pts[i].second};
          side[1].push_back(tsz);
          Connect(tsz - 1, tsz);
        } else if (mn <= xl) {
          pts[++tsz] = {xl, pts[i].second};
          side[3].push_back(tsz);
          Connect(tsz, pts[i].first == mx ? i : j);
        } else if (mx >= xr) {
          pts[++tsz] = {xr, pts[i].second};
          side[1].push_back(tsz);
          Connect(tsz, pts[i].first == mn ? i : j);
        } else
          Connect(i, j);
      }
    }
  }
  for (int s = 0; s < 4; s++) {
    sort(side[s].begin(), side[s].end(),
         [&](int i, int j) { return pts[i] < pts[j]; });
    for (int i = 1; i < side[s].size(); i++)
      Connect(side[s][i - 1], side[s][i]);
  }
  for (int i = 1; i <= tsz; i++) Build(i);
  for (int i = 2; i <= esz; i++)
    if (!was[i]) {
      csz++;
      int j = i;
      while (!was[j]) {
        was[j] = 1;
        my[j] = csz;
        ply[csz].push_back(sec[j]);
        j = nxt[j];
      }
      area[csz] = 1;
    }
  int ban = my[edx[{side[0][1], side[0][0]}]];
  for (int i = 2; i <= esz; i += 2) {
    if (my[i] != ban && my[i + 1] != ban) {
      AddEdge(my[i], my[i + 1]);
    }
  }
  DFS(1 == ban ? 2 : 1);
  int xr = 1;
  if (CuttingRayTest(xl + 0.5, yl + 0.5)) xr = 0;
  double ans = sum[ty[my[edx[{side[0][0], side[0][1]}]]] ^ xr];
  printf("%.0f", ans);
  return 0;
}