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;
struct point {
  int i, j;
  point() {}
  point(int i, int j) : i(i), j(j) {}
};
vector<point> shiftar(vector<point> v, int len) {
  int n = int(v.size());
  vector<point> nextv = v;
  for (int i = 0; i < n; i++) nextv[i] = v[(i + len) % n];
  return nextv;
}
vector<pair<int, int> > shiftar(vector<pair<int, int> > v, int len) {
  int n = int(v.size());
  vector<pair<int, int> > nextv = v;
  for (int i = 0; i < n; i++) nextv[i] = v[(i + len) % n];
  return nextv;
}
point leer() {
  point p;
  cin >> p.i >> p.j;
  return p;
}
point p1, p2;
int n;
vector<point> v;
bool dentro(point p) {
  return p1.i < p.i and p.i < p2.i and p1.j < p.j and p.j < p2.j;
}
bool todosdentro() {
  for (int i = 0; i < n; i++)
    if (not dentro(v[i])) return false;
  return true;
}
const int limite = 1000000;
int identificador[limite];
int computaidentificador(int u) {
  int &idu = identificador[u];
  if (idu == 0) return u;
  idu = computaidentificador(idu);
  return idu;
}
int uniones = 0;
void unir(int u, int v) {
  u = computaidentificador(u);
  v = computaidentificador(v);
  if (u == v) return;
  identificador[u] = v;
  uniones++;
}
pair<int, int> lista[4][15001];
int numids = 0;
vector<pair<int, int> > w;
void anyade(pair<int, int> lista[15001]) {
  for (int i = 0; i < 15001; i++)
    if (lista[i].first != -1) w.push_back(lista[i]);
}
void anyaderev(pair<int, int> lista[15001]) {
  reverse(lista, lista + 15001);
  anyade(lista);
}
bool interior(double i, double j) {
  int imax = -1;
  bool esinterior = false;
  for (int k = 0; k < n; k++) {
    point p = v[k];
    point pp = v[(k + 1) % n];
    if (p.i < imax) continue;
    if (i < p.i) continue;
    if (pp.j < j and j < p.j) {
      esinterior = true;
      imax = p.i;
    } else if (p.j < j and j < pp.j) {
      esinterior = false;
      imax = p.i;
    }
  }
  return esinterior;
}
void escribe(point p) { cout << "(" << p.i << "," << p.j << ")" << endl; }
void escribe(string s, point p) {
  cout << s << " ";
  escribe(p);
}
int main() {
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 15001; j++) lista[i][j] = pair<int, int>(-1, -1);
  ios::sync_with_stdio(false);
  p1 = leer();
  p2 = leer();
  swap(p1.j, p2.j);
  cin >> n;
  v = vector<point>(n);
  for (int i = 0; i < n; i++) v[i] = leer();
  if (todosdentro()) {
    cout << 1 << endl;
    exit(0);
  }
  {
    int i = 0;
    while (dentro(v[i])) i++;
    v = shiftar(v, i);
  }
  int id = 0;
  for (int i = 0; i < n; i++) {
    point p = v[i];
    point pp = v[(i + 1) % n];
    if (p1.i < p.i and p.i < p2.i and pp.j < p2.j and p2.j <= p.j) {
      id = ++numids;
      lista[0][p.i] = pair<int, int>(1, id);
    }
    if (p1.i < p.i and p.i < p2.i and pp.j <= p1.j and p1.j < p.j) {
      lista[2][p.i] = pair<int, int>(0, id);
    }
    if (p1.i < p.i and p.i < p2.i and p.j <= p1.j and p1.j < pp.j) {
      id = ++numids;
      lista[2][p.i] = pair<int, int>(1, id);
    }
    if (p1.i < p.i and p.i < p2.i and p.j < p2.j and p2.j <= pp.j) {
      lista[0][p.i] = pair<int, int>(0, id);
    }
    if (p1.j < p.j and p.j < p2.j and p.i <= p1.i and p1.i < pp.i) {
      id = ++numids;
      lista[1][p.j] = pair<int, int>(1, id);
    }
    if (p1.j < p.j and p.j < p2.j and p.i < p2.i and p2.i <= pp.i) {
      lista[3][p.j] = pair<int, int>(0, id);
    }
    if (p1.j < p.j and p.j < p2.j and pp.i < p2.i and p2.i <= p.i) {
      id = ++numids;
      lista[3][p.j] = pair<int, int>(1, id);
    }
    if (p1.j < p.j and p.j < p2.j and pp.i <= p1.i and p1.i < p.i) {
      lista[1][p.j] = pair<int, int>(0, id);
    }
  }
  anyade(lista[0]);
  anyaderev(lista[3]);
  anyaderev(lista[2]);
  anyade(lista[1]);
  {
    vector<pair<int, int> > v = w;
    if (int(v.size()) == 0) {
      if (interior(p1.i + 0.5, p1.j + 0.5))
        cout << 1 << endl;
      else
        cout << 0 << endl;
      exit(0);
    }
    if (v[0].first == 0) v = shiftar(v, 1);
    for (int i = 0; i < int(v.size()); i += 2)
      unir(v[i].second, v[i + 1].second);
    cout << numids - uniones << endl;
  }
}