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;
pair<int, int> A, B;
const int maxn = 2e4;
vector<int> tab[maxn];
bool vis[maxn];
vector<pair<int, int>> v;
bool checkp(pair<int, int> x) {
  if (A.first < x.first && x.first < B.first && B.second < x.second &&
      x.second < A.second)
    return true;
  return false;
}
void dfs(int a) {
  vis[a] = true;
  for (int b : tab[a])
    if (vis[b] == false) dfs(b);
}
void connect(vector<pair<pair<int, int>, int>> &inFrame) {
  for (int i = 0; i < inFrame.size(); i += 2) {
    int a = inFrame[i].second;
    int b = inFrame[i + 1].second;
    tab[a].push_back(b);
    tab[b].push_back(a);
  }
}
bool check2(pair<int, int> a) {
  int res = 0;
  for (int i = 0; i < v.size() - 1; i++) {
    pair<int, int> x = v[i], y = v[i + 1];
    if (x.first == y.first && a.first < x.first &&
        ((x.second < a.second && a.second < y.second) ||
         (y.second < a.second && a.second < x.second))) {
      res ^= 1;
    }
  }
  return res ? true : false;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> A.first >> A.second >> B.first >> B.second;
  A.first *= 2;
  A.second *= 2;
  B.first *= 2;
  B.second *= 2;
  cin >> n;
  for (int i = 0; i < n; i++) {
    pair<int, int> x;
    cin >> x.first >> x.second;
    x.first *= 2;
    x.second *= 2;
    v.push_back(x);
  }
  v.push_back(v.front());
  vector<pair<int, int>> np;
  for (int i = 0; i < n; i++) {
    pair<int, int> x = v[i], y = v[i + 1];
    bool cX = checkp(x), cY = checkp(y);
    if (cX && cY) {
      np.push_back(x);
      np.push_back(y);
    }
    if ((cX && cY == false) || (cX == false && cY)) {
      if (x.first == y.first) {
        if (x.second >= A.second) {
          np.push_back({x.first, A.second});
          np.push_back(y);
        } else if (y.second >= A.second) {
          np.push_back(x);
          np.push_back({x.first, A.second});
        } else if (x.second <= B.second) {
          np.push_back({x.first, B.second});
          np.push_back(y);
        } else {
          np.push_back(x);
          np.push_back({x.first, B.second});
        }
      } else {
        if (x.first >= B.first) {
          np.push_back({B.first, x.second});
          np.push_back(y);
        } else if (y.first >= B.first) {
          np.push_back(x);
          np.push_back({B.first, y.second});
        } else if (x.first <= A.first) {
          np.push_back({A.first, x.second});
          np.push_back(y);
        } else {
          np.push_back(x);
          np.push_back({A.first, y.second});
        }
      }
    }
    if (cX == false && cY == false) {
      if (x.first == y.first && A.first < x.first && x.first < B.first &&
          min(x.second, y.second) <= B.second &&
          A.second <= max(y.second, x.second)) {
        np.push_back({x.first, A.second});
        np.push_back({x.first, B.second});
      } else if (x.second == y.second && B.second < x.second &&
                 x.second < A.second && min(x.first, y.first) <= A.first &&
                 B.first <= max(x.first, y.first)) {
        np.push_back({A.first, x.second});
        np.push_back({B.first, x.second});
      }
    }
  }
  if (check2({A.first + 1, B.second + 1})) np.push_back({A.first, B.second});
  if (check2({A.first + 1, A.second - 1})) np.push_back({A.first, A.second});
  if (check2({B.first - 1, B.second + 1})) np.push_back({B.first, B.second});
  if (check2({B.first - 1, A.second - 1})) np.push_back({B.first, A.second});
  sort(np.begin(), np.end());
  auto it = unique(np.begin(), np.end());
  np = vector<pair<int, int>>(np.begin(), it);
  vector<pair<pair<int, int>, int>> inFrame;
  int i = 0;
  for (pair<int, int> x : np) {
    inFrame.push_back({x, i++});
  }
  sort(inFrame.begin(), inFrame.end());
  connect(inFrame);
  for (auto &x : inFrame) {
    swap(x.first.first, x.first.second);
  }
  sort(inFrame.begin(), inFrame.end());
  connect(inFrame);
  int res = 0;
  for (int j = 0; j < i; j++) vis[j] = false;
  for (int j = 0; j < i; j++) {
    if (vis[j] == false) {
      dfs(j);
      res++;
    }
  }
  cout << res << "\n";
  return 0;
}