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;
const int MAXN = 16000;
struct Line {
  int first, y1, y2;
  bool window;
  bool operator<(const Line &l) const {
    if (first == l.first) return !window;
    return first < l.first;
  }
};
int wx1, wx2, wy1, wy2;
bool counting = false;
vector<Line> lines;
vector<pair<int, int> > ps;
map<int, int> low;
bool visible(int y1, int y2) { return counting && y2 > wy1 && y1 < wy2; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> wx1 >> wy1 >> wx2 >> wy2;
  swap(wy1, wy2);
  lines.push_back({wx1, wy1, wy2, true});
  lines.push_back({wx2, wy1, wy2, true});
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int first, second;
    cin >> first >> second;
    ps.push_back({first, second});
  }
  for (int i = 0; i < N; i++) {
    int j = (i + 1) % N;
    if (ps[i].first == ps[j].first) {
      int y1 = min(ps[i].second, ps[j].second);
      int y2 = max(ps[i].second, ps[j].second);
      lines.push_back({ps[i].first, y1, y2, false});
    }
  }
  int ans = 0;
  sort((lines).begin(), (lines).end());
  for (Line &l : lines) {
    if (l.window) {
      counting ^= 1;
      if (counting) {
        for (auto &p : low) {
          int lower = p.first, upper = p.second;
          if (visible(lower, upper)) {
            ans++;
          }
        }
      } else
        break;
    } else {
      if (l.first >= wx2) continue;
      auto it = low.upper_bound(l.y1);
      if (it != low.begin()) {
        --it;
        int lower = it->first, upper = it->second;
        if (upper >= l.y2) {
          low.erase(it);
          if (lower != l.y1) low[lower] = l.y1;
          if (upper != l.y2) low[l.y2] = upper;
          continue;
        }
      }
      bool merge2 = false;
      it = low.upper_bound(l.y1);
      if (it != low.begin()) {
        --it;
        int lower = it->first, upper = it->second;
        if (upper == l.y1) {
          low.erase(it);
          low[lower] = l.y2;
          if (!visible(lower, upper) && visible(lower, l.y2)) ans++;
          l.y1 = lower;
          merge2 = true;
        }
      }
      it = low.upper_bound(l.y1);
      if (it != low.end()) {
        int lower = it->first, upper = it->second;
        if (lower == l.y2) {
          low.erase(it);
          low[l.y1] = upper;
          if (!merge2 && !visible(lower, upper) && visible(l.y1, upper)) ans++;
          if (merge2 && visible(lower, upper) && visible(l.y1, l.y2)) ans--;
          continue;
        }
      }
      if (merge2) continue;
      low.emplace(l.y1, l.y2);
      if (visible(l.y1, l.y2)) ans++;
    }
  }
  cout << ans << '\n';
}