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 X1, Y1, X2, Y2;
int N;
int X[151515], Y[151515];
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> X1 >> Y1 >> X2 >> Y2;
  swap(Y1, Y2);
  cin >> N;
  for (i = 0; i < (N); i++) cin >> X[i] >> Y[i];
  X[N] = X[0], Y[N] = Y[0];
  vector<vector<int>> V;
  for (i = 0; i < (N); i++) {
    if (X[i] == X[i + 1] && X1 < X[i] && X[i] < X2) {
      if (Y[i + 1] > Y[i]) {
        if (Y[i] <= Y1 && Y[i + 1] > Y1)
          V.push_back({X[i], Y1, (2 + (int)V.size())});
        if (Y[i] < Y2 && Y[i + 1] >= Y2)
          V.push_back({X[i], Y2, -(2 + (int)V.size())});
      } else {
        if (Y[i] >= Y2 && Y[i + 1] < Y2)
          V.push_back({X[i], Y2, (2 + (int)V.size())});
        if (Y[i] > Y1 && Y[i + 1] <= Y1)
          V.push_back({X[i], Y1, -(2 + (int)V.size())});
      }
    }
    if (Y[i] == Y[i + 1] && Y1 < Y[i] && Y[i] < Y2) {
      if (X[i + 1] > X[i]) {
        if (X[i] <= X1 && X[i + 1] > X1)
          V.push_back({X1, Y[i], (2 + (int)V.size())});
        if (X[i] < X2 && X[i + 1] >= X2)
          V.push_back({X2, Y[i], -(2 + (int)V.size())});
      } else {
        if (X[i] >= X2 && X[i + 1] < X2)
          V.push_back({X2, Y[i], (2 + (int)V.size())});
        if (X[i] > X1 && X[i + 1] <= X1)
          V.push_back({X1, Y[i], -(2 + (int)V.size())});
      }
    }
  }
  if (V.empty()) {
    if (X1 < X[0] && X[0] < X2 && Y1 < Y[0] && Y[0] < Y2) {
      cout << 1 << endl;
      return;
    }
    int num = 0;
    X1 = X1 * 2 + 1;
    Y1 = Y1 * 2 + 1;
    for (i = 0; i < (N + 1); i++) X[i] *= 2, Y[i] *= 2;
    for (i = 0; i < (N); i++) {
      if (X[i] == X[i + 1] && X[i] > X1 &&
          (min(Y[i], Y[i + 1]) < Y1 && max(Y[i], Y[i + 1]) > Y1))
        num++;
    }
    cout << num % 2 << endl;
    return;
  }
  if (V.back()[2] > 0) {
    auto a = V.back();
    a[2] = 1;
    V.pop_back();
    V.insert(V.begin(), a);
  }
  int mi = 1010;
  for (auto& v : V)
    if (v[2] > 0) mi = min(mi, v[2]);
  map<pair<int, int>, int> M;
  for (auto& v : V) {
    x = v[2];
    if (x > 0)
      x -= mi;
    else
      x += mi;
    M[{v[0], v[1]}] = x;
  }
  vector<int> W;
  for (x = X1; x < X2; x++)
    if (M.count({x, Y2})) W.push_back(M[{x, Y2}]);
  for (y = Y2; y > Y1; y--)
    if (M.count({X2, y})) W.push_back(M[{X2, y}]);
  for (x = X2; x > X1; x--)
    if (M.count({x, Y1})) W.push_back(M[{x, Y1}]);
  for (y = Y1; y < Y2; y++)
    if (M.count({X1, y})) W.push_back(M[{X1, y}]);
  while (1) {
    int d = 0;
    for (auto& w : W) {
      if (w >= 0)
        d++;
      else
        d--;
      if (d < 0) break;
    }
    if (d == 0) break;
    rotate(W.begin(), W.begin() + 1, W.end());
  }
  int num = 0;
  set<int> did;
  for (auto& w : W) {
    if (w >= 0)
      did.insert(w);
    else {
      x = (-w) - 1;
      if (did.count(x)) num++;
    }
  }
  cout << num << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}