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 = 50005;
map<pair<int, int>, int> mp;
map<pair<int, int>, int> at;
map<long long, bool> used;
int fa[N], nd, x1, x2, ysghysgsygsh, y2;
int x[N], y[N], ans, n;
long long hsh[N];
pair<int, int> q[N];
int getid(int x, int y) {
  if (mp.find(pair<int, int>(x, y)) == mp.end()) {
    ++nd;
    fa[nd] = nd;
    return mp[pair<int, int>(x, y)] = nd;
  }
  return mp[pair<int, int>(x, y)];
}
int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }
void add(int x, int y) {
  x = get(x);
  y = get(y);
  if (x != y) {
    if (x < y) swap(x, y);
    fa[x] = y;
  }
}
void insert(int sx, int sy, int tx, int ty) {
  if (pair<int, int>(sx, sy) > pair<int, int>(tx, ty))
    swap(sx, tx), swap(sy, ty);
  if (sx == tx && x1 < sx && sx < x2) {
    if (ty <= ysghysgsygsh || sy >= y2) return;
    int py1 = max(ysghysgsygsh, sy), py2 = min(y2, ty);
    add(getid(sx, py1), getid(sx, py2));
  }
  if (sy == ty && ysghysgsygsh < sy && sy < y2) {
    if (tx <= x1 || sx >= x2) return;
    int px1 = max(x1, sx), px2 = min(x2, tx);
    add(getid(px1, sy), getid(px2, sy));
  }
}
void UPDans(int px, int py, int qx, int qy) {
  if (px != -1 && py != -1) {
    long long val = hsh[getid(px, py)];
    if (used[val]) return;
    used[val] = 1;
  }
  int flg = 0;
  for (int i = (int)(1); i <= (int)(n); i++) {
    int sx = x[i], sy = y[i], tx = x[i % n + 1], ty = y[i % n + 1];
    if (sx != tx || sx <= qx) continue;
    if ((sy <= qy) ^ (ty <= qy)) flg ^= 1;
  }
  ans += flg;
}
int main() {
  scanf("%d%d%d%d", &x1, &y2, &x2, &ysghysgsygsh);
  for (int i = (int)(x1 + 1); i <= (int)(x2 - 1); i++) getid(i, ysghysgsygsh);
  for (int i = (int)(ysghysgsygsh + 1); i <= (int)(y2 - 1); i++) getid(x2, i);
  for (int i = (int)(x2 - 1); i >= (int)(x1 + 1); i--) getid(i, y2);
  for (int i = (int)(y2 - 1); i >= (int)(ysghysgsygsh + 1); i--) getid(x1, i);
  int tmp = nd, top = 0, flg = 0;
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d%d", &x[i], &y[i]);
  for (int i = (int)(1); i <= (int)(n); i++)
    flg |= (x[i] < x1 || x[i] > x2 || y[i] < ysghysgsygsh || y[i] > y2);
  if (!flg) return puts("1"), 0;
  for (int i = (int)(1); i <= (int)(n); i++)
    insert(x[i], y[i], x[i % n + 1], y[i % n + 1]);
  for (int i = (int)(1); i <= (int)(tmp); i++)
    if (get(i) != i) q[++top] = pair<int, int>(i, get(i));
  if (!top)
    UPDans(-1, -1, x1, ysghysgsygsh);
  else {
    for (int i = (int)(1); i <= (int)(top); i++) {
      long long val = 1ll * i * i * i;
      hsh[q[i].second + 1] ^= val;
      hsh[q[i].first + 1] ^= val;
    }
    for (int i = (int)(1); i <= (int)(tmp); i++) hsh[i] ^= hsh[i - 1];
    for (int i = (int)(x1 + 1); i <= (int)(x2 - 1); i++)
      UPDans(i, ysghysgsygsh, i - 1, ysghysgsygsh);
    for (int i = (int)(x1 + 1); i <= (int)(x2 - 1); i++)
      UPDans(i, y2, i, y2 - 1);
    for (int i = (int)(ysghysgsygsh + 1); i <= (int)(y2 - 1); i++)
      UPDans(x2, i, x2 - 1, i - 1);
    for (int i = (int)(ysghysgsygsh + 1); i <= (int)(y2 - 1); i++)
      UPDans(x1, i, x1, i);
  }
  printf("%d\n", ans);
}