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 = 15005;
int xx1, xx2, yy1, yy2, n, x[N], y[N], nx, ny;
int process(int a[], int n) {
  vector<int> id(n + 1);
  for (int i = 1; i <= n; i++) id[i] = i;
  sort(id.begin() + 1, id.end(), [&](int x, int y) { return a[x] < a[y]; });
  int cur = 1, i = 1;
  while (i <= n) {
    int t = a[id[i]];
    while (i <= n && a[id[i]] == t) a[id[i++]] = cur;
    ++cur;
  }
  return cur - 1;
}
bitset<N> v[N];
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
void dfs(int x, int y) {
  v[y][x] = 0;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx > 0 && nx < N && ny > 0 && ny < N && v[ny][nx]) dfs(nx, ny);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> xx1 >> yy1 >> xx2 >> yy2;
  swap(yy1, yy2);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];
  x[n + 1] = xx1;
  y[n + 1] = yy1;
  x[n + 2] = xx2;
  y[n + 2] = yy2;
  nx = process(x, n + 2);
  ny = process(y, n + 2);
  for (int i = 1; i <= n; i++) {
    int j = i % n + 1;
    if (y[i] == y[j]) v[y[i]][x[i]] = v[y[j]][x[j]] = 1;
  }
  bitset<N> msk;
  for (int j = 1; j < ny; j++) {
    bool in = v[j][1];
    for (int i = 2; i < nx; i++) v[j][i] = in ^= v[j][i];
    v[j] ^= v[j - 1];
  }
  for (int i = x[n + 1]; i < x[n + 2]; i++) msk[i] = 1;
  for (int j = 1; j < ny; j++)
    if (j < y[n + 1] || j >= y[n + 2])
      v[j].reset();
    else
      v[j] &= msk;
  int ans = 0;
  for (int j = y[n + 1]; j < y[n + 2]; j++)
    if (v[j].any())
      for (int i = x[n + 1]; i < x[n + 2]; i++)
        if (v[j][i]) ++ans, dfs(i, j);
  cout << ans << endl;
  return 0;
}