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;
int const N = 15000, C = N << 4;
int id[C], n, bf, go[C], w, h;
bool vis[C], vv[4];
struct P;
P *p1, *p2;
struct P {
  int x, y;
  P() {}
  void sc() { scanf("%d%d", &x, &y); }
  P(int a, int b) : x(a), y(b) {}
  int id() {
    if (x > p1->x && x < p2->x) {
      if (y < p1->y && y > p2->y) return 0;
      if (y >= p1->y) return 1;
      return -1;
    }
    if (y < p1->y && y > p2->y) return x <= p1->x ? 2 : -2;
    if (x <= p1->x && y >= p1->y) return 3;
    if (x <= p1->x && y <= p2->y) return 4;
    if (x >= p2->x && y >= p1->y) return 5;
    return 6;
  }
} p10, p20, p[N];
inline void adop(int x) {
  id[x] = 1;
  bf = x;
}
inline void adcl(int x) {
  id[x] = 2;
  go[bf] = x;
}
inline void g(int v) {
  while (!vis[v]) {
    vis[v] = true;
    v = go[v];
  }
}
inline int rid(P p, int id) {
  if (id == 1) return w + h + p2->x - p.x;
  if (id == -1) return p.x - p1->x;
  if (id == -2) return w + p.y - p2->y;
  return w + h + w + p1->y - p.y;
}
inline void ad(P a, P b) {
  int x = a.id(), y = b.id();
  if (x == y) return;
  if (x >= 3 || y >= 3) {
    if (a.x <= p1->x && b.x <= p1->x)
      vv[0] ^= 1;
    else if (a.x >= p2->x && b.x >= p2->x)
      vv[1] ^= 1;
    else if (a.y >= p1->y && b.y >= p1->y)
      vv[2] ^= 1;
    else
      vv[3] ^= 1;
    return;
  }
  if (!x)
    adcl(rid(b, y));
  else if (!y)
    adop(rid(a, x));
  else
    adop(rid(a, x)), adcl(rid(b, y));
}
int main() {
  p1 = &p10;
  p2 = &p20;
  p1->sc();
  p2->sc();
  w = p2->x - p1->x;
  h = p1->y - p2->y;
  scanf("%d", &n);
  for (int i = 0; i < (int)(n); ++i) p[i].sc();
  int i = -1;
  for (int j = 0; j < (int)(n); ++j)
    if (p[j].id() != 0) {
      i = j;
      break;
    }
  if (i == -1) {
    printf("1\n");
    return 0;
  }
  bf = -1;
  for (int it = 0; it < (int)(n); ++it) {
    int j = i + 1 == n ? 0 : i + 1;
    ad(p[i], p[j]);
    i = j;
  }
  i = 0;
  while (i < C && id[i] != 1) ++i;
  if (i == C) {
    printf("%d\n", vv[0] || vv[1] || vv[2] || vv[3] ? 1 : 0);
    return 0;
  }
  int j = i;
  for (int it = 0; it < (int)(C); ++it) {
    if (i-- == 0) i = C - 1;
    if (id[i] == 1)
      j = i;
    else if (id[i] == 2)
      go[i] = j;
  }
  int an = 0;
  for (int i = 0; i < (int)(C); ++i)
    if (id[i] && !vis[i]) ++an, g(i);
  printf("%d\n", an);
}