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 char nl = '\n';
const long long INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const long long MOD = 1e9 + 7;
const long double EPS = 1e-10;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
struct Segment {
  int x, a, b;
  bool operator<(const Segment& v) const {
    if (x == v.x)
      return a < v.a;
    else
      return x < v.x;
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int top, bottom, left, right;
  cin >> left >> top >> right >> bottom;
  int n;
  cin >> n;
  vector<pair<int, int> > p;
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    p.push_back(pair<int, int>(a, b));
  }
  vector<Segment> segs;
  for (int i = 0; i < n; i++) {
    if (p[i].first == p[(i + 1) % n].first) {
      segs.push_back({p[i].first, p[i].second, p[(i + 1) % n].second});
    }
  }
  sort(segs.begin(), segs.end());
  int ans = 0;
  set<pair<int, int> > cur;
  for (const Segment& s : segs) {
    if (s.x >= right) break;
    a = s.a;
    b = s.b;
    if (a > b) {
      swap(a, b);
      if (b <= bottom || a >= top) continue;
      a = max(a, bottom);
      b = min(b, top);
      auto nxt = cur.lower_bound(pair<int, int>(a, b));
      if (nxt != cur.begin()) {
        auto pre = prev(nxt);
        if (pre->second == a) {
          a = pre->first;
          cur.erase(pre);
        }
      }
      if (nxt->first == b) {
        b = nxt->second;
        cur.erase(nxt);
      }
      cur.insert(pair<int, int>(a, b));
    } else {
      if (b <= bottom || a >= top) continue;
      a = max(a, bottom);
      b = min(b, top);
      auto it = prev(cur.upper_bound(pair<int, int>(a, INF)));
      if (it->first == a && it->second == b) {
        cur.erase(it);
        if (s.x > left) ans++;
      } else if (it->first == a) {
        a = b;
        b = it->second;
        cur.erase(it);
        cur.insert(pair<int, int>(a, b));
      } else if (it->second == b) {
        b = a;
        a = it->first;
        cur.erase(it);
        cur.insert(pair<int, int>(a, b));
      } else {
        if (s.x > left) ans--;
        int va = it->first;
        int vb = a;
        a = b;
        b = it->second;
        cur.erase(it);
        cur.insert(pair<int, int>(va, vb));
        cur.insert(pair<int, int>(a, b));
      }
    }
  }
  ans += cur.size();
  cout << ans << nl;
  return 0;
}