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 asfpasokf, ifjsiojofsj, x2, y2, m;
int n;
int x[22222], y[22222];
int w[111111];
const int ULAZNA = 0;
const int IZLAZNA = 1;
bool unutra(int x, int y) {
  return asfpasokf < x && x < x2 && ifjsiojofsj < y && y < y2;
}
bool unutraa(int x, int y) {
  return asfpasokf <= x && x <= x2 && ifjsiojofsj <= y && y <= y2;
}
struct tacka {
  int tip, x, y, z;
  tacka(int tip, int x, int y) : tip(tip), x(x), y(y) {
    if (y == y2) {
      z = x - asfpasokf;
    } else if (x == x2) {
      z = (x2 - asfpasokf) + (y2 - y);
    } else if (y == ifjsiojofsj) {
      z = (x2 - asfpasokf) + (y2 - ifjsiojofsj) + (x2 - x);
    } else {
      z = (x2 - asfpasokf) + (y2 - ifjsiojofsj) + (x2 - asfpasokf) +
          (y - ifjsiojofsj);
    }
    z = m - z - 1;
  }
};
vector<tacka> pt;
int u[111111], v[111111];
bool vis[111111];
bool jbg() {
  int c = 0;
  for (int i = 0; i < n; i++) {
    if (x[i] != x[i + 1]) {
      int z = x[i] < x[i + 1] ? 1 : -1;
      if (y[i] > ifjsiojofsj) c += z;
    }
  }
  return c;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  cin >> asfpasokf >> ifjsiojofsj >> x2 >> y2;
  swap(ifjsiojofsj, y2);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  m = 2 * (x2 + y2 - asfpasokf - ifjsiojofsj);
  x[n] = x[0];
  y[n] = y[0];
  for (int i = 0; i < n; i++) {
    cerr << "Segment " << x[i] << ' ' << y[i];
    cerr << ' ' << x[i + 1] << ' ' << y[i + 1] << '\n';
  }
  for (int i = 0; i < n; i++) {
    if (unutra(x[i], y[i]) && !unutra(x[i + 1], y[i + 1])) {
      if (x[i] == x[i + 1]) {
        int xx = x[i];
        int a = y[i];
        int b = y[i + 1];
        int yy;
        if (a < b) {
          yy = y2;
        } else {
          yy = ifjsiojofsj;
        }
        pt.push_back(tacka(IZLAZNA, xx, yy));
      } else {
        int yy = y[i];
        int a = x[i];
        int b = x[i + 1];
        int xx;
        if (a < b) {
          xx = x2;
        } else {
          xx = asfpasokf;
        }
        pt.push_back(tacka(IZLAZNA, xx, yy));
      }
    } else if (!unutra(x[i], y[i]) && unutra(x[i + 1], y[i + 1])) {
      if (x[i] == x[i + 1]) {
        int xx = x[i];
        int a = y[i];
        int b = y[i + 1];
        int yy;
        if (a < b) {
          yy = ifjsiojofsj;
        } else {
          yy = y2;
        }
        pt.push_back(tacka(ULAZNA, xx, yy));
      } else {
        int yy = y[i];
        int a = x[i];
        int b = x[i + 1];
        int xx;
        if (a < b) {
          xx = asfpasokf;
        } else {
          xx = x2;
        }
        pt.push_back(tacka(ULAZNA, xx, yy));
      }
    } else if (!unutra(x[i], y[i]) && !unutra(x[i + 1], y[i + 1])) {
      if (x[i] == x[i + 1] && asfpasokf < x[i] && x[i] < x2) {
        int a = y[i];
        int b = y[i + 1];
        if (a < b) {
          if (a <= ifjsiojofsj && y2 <= b) {
            pt.push_back(tacka(ULAZNA, x[i], ifjsiojofsj));
            pt.push_back(tacka(IZLAZNA, x[i], y2));
          }
        } else {
          if (b <= ifjsiojofsj && y2 <= a) {
            pt.push_back(tacka(ULAZNA, x[i], y2));
            pt.push_back(tacka(IZLAZNA, x[i], ifjsiojofsj));
          }
        }
      }
      if (y[i] == y[i + 1] && ifjsiojofsj < y[i] && y[i] < y2) {
        int a = x[i];
        int b = x[i + 1];
        if (a < b) {
          if (a <= asfpasokf && x2 <= b) {
            pt.push_back(tacka(ULAZNA, asfpasokf, y[i]));
            pt.push_back(tacka(IZLAZNA, x2, y[i]));
          }
        } else {
          if (b <= asfpasokf && x2 <= a) {
            pt.push_back(tacka(ULAZNA, x2, y[i]));
            pt.push_back(tacka(IZLAZNA, asfpasokf, y[i]));
          }
        }
      }
    }
  }
  if (pt.size() == 0) {
    if (unutraa(x[0], y[0]))
      cout << 1;
    else if (jbg())
      cout << 1;
    else
      cout << 0;
    return 0;
  }
  if (pt[0].tip == IZLAZNA) {
    rotate(pt.begin(), pt.begin() + 1, pt.end());
  }
  cerr << pt.size() << " sz\n";
  cerr << m << " m" << '\n';
  for (int i = 0; i < (int)pt.size(); i += 2) {
    int z1 = pt[i].z;
    int z2 = pt[i + 1].z;
    cerr << "zz " << z1 << ' ' << z2 << '\n';
    int j = (i + 2) / 2;
    w[z1] = -j;
    w[z2] = j;
    u[j] = z1;
    v[j] = z2;
  }
  for (int i = 0; i < m; i++) cerr << w[i] << ' ';
  cerr << '\n';
  int sol = 0;
  for (int i = 0; i < m; i++) {
    int x = i;
    if (!vis[x] && w[x] > 0) {
      sol++;
      while (1) {
        if (vis[x]) break;
        vis[x] = 1;
        if (w[x] == 0)
          x = (x + 1) % m;
        else if (w[x] < 0)
          x = u[-w[x]] ^ v[-w[x]] ^ x;
        else
          x = (x + 1) % m;
      }
    }
  }
  cout << sol << '\n';
}