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;
set<pair<int, int> > have;
struct Seg {
  int x, y1, y2;
  bool operator<(const Seg& o) const { return x < o.x; }
};
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int x1, x2, y1, y2;
  cin >> x1 >> y2 >> x2 >> y1;
  int n;
  cin >> n;
  vector<pair<int, int> > pts(n);
  for (auto& p : pts) {
    cin >> p.first >> p.second;
  }
  vector<Seg> segs;
  for (int i = 0; i < n; ++i) {
    if (pts[i].first == pts[(i + 1) % n].first) {
      segs.push_back({pts[i].first, pts[i].second, pts[(i + 1) % n].second});
    }
  }
  sort(segs.begin(), segs.end());
  int ans = 0;
  for (auto s : segs) {
    if (s.x >= x2) break;
    if (s.y1 > s.y2) {
      if (s.y1 <= y1 || s.y2 >= y2) {
        continue;
      }
      s.y1 = min(s.y1, y2);
      s.y2 = max(s.y2, y1);
      have.insert({s.y2, s.y1});
    } else {
      if (s.y2 <= y1 || s.y1 >= y2) {
        continue;
      }
      s.y2 = min(s.y2, y2);
      s.y1 = max(s.y1, y1);
      bool rtop = 0, rbot = 0;
      while (true) {
        auto it = have.upper_bound(pair<int, int>(s.y1, -1e9));
        if (it == have.end()) {
          break;
        }
        if (it->first == s.y2) {
          rtop = 1;
          break;
        }
        if (it->first > s.y2) {
          break;
        }
        pair<int, int> res = *it;
        have.erase(it);
        res.first = s.y2;
        if (res.first < res.second) {
          have.insert(res);
        }
      }
      auto it = have.upper_bound(pair<int, int>(s.y1, -1e9));
      if (it != have.begin()) {
        it = prev(it);
        if (it->second >= s.y1) {
          pair<int, int> res = *it;
          have.erase(it);
          if (it->second > s.y2) {
            have.insert({res.first, s.y1});
            have.insert({s.y2, res.second});
            if (s.x > x1) {
              --ans;
            }
            continue;
          }
          res.second = s.y1;
          if (res.second > res.first) {
            have.insert(res);
          }
          rbot = 1;
        }
      }
      if (rtop && rbot && s.x > x1) {
        --ans;
        continue;
      }
      it = have.upper_bound(pair<int, int>(s.y1, -1e9));
      if (it != have.end()) {
        assert(it->first >= s.y2);
        if (it->first == s.y2) {
          continue;
        }
      }
      if (it != have.begin()) {
        it = prev(it);
        assert(it->second <= s.y1);
        if (it->second == s.y1) {
          continue;
        }
      }
      if (s.x > x1) {
        ans++;
      }
    }
  }
  ans += have.size();
  for (auto it = have.begin(); it != have.end() && next(it) != have.end();
       ++it) {
    if (it->second == next(it)->first) {
      --ans;
    }
  }
  cout << ans << "\n";
  return 0;
}