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;
bitset<15010> v[15010], mask;
int X1, X2, Y1, Y2, x[15010], y[15010];
int Compress(int n, int x[], int& x1, int& x2) {
  vector<int> v;
  for (int i = 0; i < n; ++i) v.push_back(x[i]);
  v.push_back(x1);
  v.push_back(x2);
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  for (int i = 0; i < n; ++i)
    x[i] = lower_bound(v.begin(), v.end(), x[i]) - v.begin();
  x1 = lower_bound(v.begin(), v.end(), x1) - v.begin();
  x2 = lower_bound(v.begin(), v.end(), x2) - v.begin();
  if (x1 > x2) swap(x1, x2);
  return v.size();
}
void DFS(int x, int y) {
  v[y].reset(x);
  if (x < 15010 && v[y].test(x + 1)) {
    DFS(x + 1, y);
  }
  if (y < 15010 && v[y + 1].test(x)) {
    DFS(x, y + 1);
  }
  if (x > 0 && v[y].test(x - 1)) {
    DFS(x - 1, y);
  }
  if (y > 0 && v[y - 1].test(x)) {
    DFS(x, y - 1);
  }
}
int main() {
  int n;
  scanf("%d%d%d%d", &X1, &Y1, &X2, &Y2);
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d%d", &x[i], &y[i]);
  int mx = Compress(n, x, X1, X2);
  int my = Compress(n, y, Y1, Y2);
  for (int i = 0; i < n; ++i) {
    int j = (i + 1) % n;
    if (y[i] == y[j]) {
      v[y[i]].set(x[i]);
      v[y[j]].set(x[j]);
    }
  }
  for (int j = 0; j < my; ++j) {
    bool k = v[j][0];
    for (int i = 1; i < mx; ++i) {
      k ^= v[j][i];
      v[j][i] = k;
    }
    if (j) v[j] ^= v[j - 1];
  }
  for (int i = X1; i < X2; ++i) mask.set(i);
  for (int j = 0; j < my; ++j) {
    if (j < Y1 || j >= Y2)
      v[j].reset();
    else
      v[j] &= mask;
  }
  int ans = 0;
  for (int j = Y1; j < Y2; ++j) {
    if (!v[j].any()) {
      continue;
    }
    for (int i = X1; i < X2; ++i) {
      if (!v[j].test(i)) {
        continue;
      }
      ++ans;
      DFS(i, j);
    }
  }
  printf("%d\n", ans);
  return 0;
}