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;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 15000;
struct P {
  int x, y;
  P() {}
  P(int x, int y) : x(x), y(y) {}
};
int wlx, wly, whx, why;
int n;
P p[MAXN];
int whor, wver;
int inter[2 * MAXN], ninter;
int all[2 * MAXN], nall;
int nxt[2 * MAXN];
bool been[2 * MAXN];
void addinter(const P &a, const P &b) {
  if (a.x == b.x) {
    int x = a.x;
    if (x < wlx || x > whx) return;
    int ly = min(a.y, b.y), hy = max(a.y, b.y);
    int u = ly <= wly && wly <= hy ? whor + wver + x - wlx : -1;
    int v = ly <= why && why <= hy ? whx - x : -1;
    if (a.y > b.y) swap(u, v);
    if (u != -1) inter[ninter++] = u;
    if (v != -1) inter[ninter++] = v;
  } else if (a.y == b.y) {
    int y = a.y;
    if (y < wly || y > why) return;
    int lx = min(a.x, b.x), hx = max(a.x, b.x);
    int u = lx <= wlx && wlx <= hx ? whor + why - y : -1;
    int v = lx <= whx && whx <= hx ? whor + wver + whor + y - wly : -1;
    if (a.x > b.x) swap(u, v);
    if (u != -1) inter[ninter++] = u;
    if (v != -1) inter[ninter++] = v;
  }
}
bool insidepolygon(const P &a) {
  int cnt = 0;
  for (int i = (0); i < (n); ++i) {
    int j = (i + 1) % n;
    if (p[i].x != p[j].x || p[i].x >= a.x) continue;
    int ly = min(p[i].y, p[j].y), hy = max(p[i].y, p[j].y);
    if (ly < a.y && a.y < hy) ++cnt;
  }
  return cnt % 2 == 1;
}
bool outsidewindow(const P &a) {
  return a.x < wlx || a.x > whx || a.y < wly || a.y > why;
}
int solve() {
  swap(wly, why);
  wlx *= 3, wly *= 3, whx *= 3, why *= 3;
  ++wlx, ++wly, --whx, --why;
  for (int i = (0); i < (n); ++i) p[i].x *= 3, p[i].y *= 3;
  whor = whx - wlx, wver = why - wly;
  int outidx = 0;
  while (outidx < n && !outsidewindow(p[outidx])) ++outidx;
  if (outidx >= n) return 1;
  ninter = 0;
  for (int i = (0); i < (n); ++i) {
    int a = (outidx + i) % n, b = (outidx + i + 1) % n;
    addinter(p[a], p[b]);
  }
  assert(ninter % 2 == 0);
  if (ninter == 0) return insidepolygon(P(wlx, wly)) ? 1 : 0;
  nall = 0;
  for (int i = (0); i < (ninter); ++i) all[nall++] = inter[i];
  sort(all, all + nall);
  nall = unique(all, all + nall) - all;
  assert(nall == ninter);
  for (int i = (0); i < (ninter); ++i)
    inter[i] = lower_bound(all, all + nall, inter[i]) - all;
  for (int i = (0); i < (ninter); ++i) nxt[inter[i]] = inter[(i + 1) % n];
  assert(ninter <= n);
  int ret = 0;
  for (int i = (0); i < (ninter); ++i) been[i] = false;
  for (int i = 0; i < ninter; i += 2)
    if (!been[inter[i]]) {
      ++ret;
      int at = inter[i];
      while (!been[at]) {
        been[at] = true;
        at = nxt[at];
        been[at] = true;
        at = (at + 1) % ninter;
      }
    }
  return ret;
}
void run() {
  scanf("%d%d%d%d", &wlx, &wly, &whx, &why);
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d%d", &p[i].x, &p[i].y);
  printf("%d\n", solve());
}
int main() {
  run();
  return 0;
}