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;
vector<int> ga[30010], gb[30010];
pair<int, int> a[30010], b[30010];
int n, m, lx[30010 << 1], tx, ty, ly[30010 << 1];
char s[2][30010], s1[2][30010], s2[2][30010];
int v[30010 << 1], f[30010 << 1], g[2][30010];
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
int main() {
  int x1, y1, x2, y2;
  scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d%d", &a[i].first, &a[i].second), lx[++tx] = a[i].first,
                                              ly[++ty] = a[i].second;
  b[++m] = pair<int, int>(x1, y1);
  b[++m] = pair<int, int>(x1, y2);
  b[++m] = pair<int, int>(x2, y1);
  b[++m] = pair<int, int>(x2, y2);
  for (int i = 1; i <= m; ++i) lx[++tx] = b[i].first, ly[++ty] = b[i].second;
  sort(lx + 1, lx + tx + 1), tx = unique(lx + 1, lx + tx + 1) - lx - 1;
  sort(ly + 1, ly + ty + 1), ty = unique(ly + 1, ly + ty + 1) - ly - 1;
  for (int i = 1; i <= n; ++i) {
    int x = lower_bound(lx + 1, lx + tx + 1, a[i].first) - lx;
    int y = lower_bound(ly + 1, ly + ty + 1, a[i].second) - ly;
    ga[x - 1].push_back(y);
  }
  for (int i = 1; i <= m; ++i) {
    int x = lower_bound(lx + 1, lx + tx + 1, b[i].first) - lx;
    int y = lower_bound(ly + 1, ly + ty + 1, b[i].second) - ly;
    gb[x - 1].push_back(y);
  }
  int p = 0, np = 1, ans = 0;
  for (int i = 1; i <= ty; ++i) g[np][i] = i;
  for (int i = tx; i >= 1; --i, swap(p, np)) {
    for (int j = 1; j <= ty; ++j) s[p][j] = s1[p][j] = 0;
    for (auto x : ga[i]) s[p][x] ^= 1;
    for (auto x : gb[i]) s1[p][x] ^= 1;
    for (int j = 1; j <= ty; ++j) {
      s[p][j] ^= s[np][j] ^ s[p][j - 1] ^ s[np][j - 1];
      s1[p][j] ^= s1[np][j] ^ s1[p][j - 1] ^ s1[np][j - 1];
      s2[p][j] = s[p][j] & s1[p][j];
      ans += s2[p][j];
    }
    for (int j = 1; j <= ty * 2; ++j) f[j] = j, v[j] = 0;
    for (int j = 1; j <= ty; ++j) {
      if (s2[p][j] == 1)
        f[j] = (j != 1 && s2[p][j] == s2[p][j - 1] ? ans--, f[j - 1] : j);
      if (s2[np][j] == 1) g[np][j] += ty;
    }
    for (int j = 1; j <= ty; ++j)
      if (s2[np][j] == 1 && s2[p][j] == 1) {
        int x = find(g[np][j]), y = find(j);
        if (x != y) ans--, f[x] = y;
      }
    int tp = 0;
    for (int j = 1; j <= ty; ++j)
      if (s2[p][j] == 1) {
        int x = find(j);
        if (!v[x])
          g[p][j] = ++tp, v[x] = tp;
        else
          g[p][j] = v[x];
      }
  }
  printf("%d", ans);
}