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 = 15000 + 5;
int n;
int x1, __asd, x2, __bsd, cnt;
pair<int, int> a[N];
vector<int> add[N * 2], del[N * 2];
vector<pair<pair<int, int>, int> > v[N];
map<int, int> h;
void dfs(int x1, int __asd, int __bsd, int id) {
  h[id] = 1;
  for (auto tmp : v[x1 + 1]) {
    if (tmp.first.second < __asd or __bsd < tmp.first.first) continue;
    if (!h[tmp.second])
      dfs(x1 + 1, tmp.first.first, tmp.first.second, tmp.second);
  }
  if (x1 > 0)
    for (auto tmp : v[x1 - 1]) {
      if (tmp.first.second < __asd or __bsd < tmp.first.first) continue;
      if (!h[tmp.second])
        dfs(x1 - 1, tmp.first.first, tmp.first.second, tmp.second);
    }
}
int main() {
  scanf("%d %d %d %d", &x1, &__asd, &x2, &__bsd);
  swap(__asd, __bsd);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i].first, &a[i].second);
  }
  a[n + 1] = a[1];
  for (int i = 1; i <= n; i++) {
    pair<int, int> x = a[i], y = a[i + 1];
    if (x.first == y.first) continue;
    if (x.first > y.first) swap(x, y);
    add[x.first].push_back(x.second);
    del[y.first].push_back(x.second);
  }
  map<int, int> M;
  for (int i = 0; i < x2; i++) {
    for (auto x : add[i]) {
      if (x > __asd) {
        M[x]++;
      }
    }
    for (auto x : del[i]) {
      if (x > __asd) {
        M.erase(x);
      }
    }
    if (M.empty() or i < x1) continue;
    int cur = M.size();
    int last = __asd;
    for (auto x : M) {
      if (cur % 2) {
        v[i].push_back({{last, min(__bsd - 1, x.first - 1)}, ++cnt});
      }
      if (x.first >= __bsd) break;
      cur--;
      last = x.first;
    }
  }
  int ans = 0;
  for (int i = 0; i < N - 1; i++) {
    for (auto &x : v[i]) {
      if (!h[x.second]) {
        ans++;
        dfs(i, x.first.first, x.first.second, x.second);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}