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>
#pragma GCC optimize "-O3"
using namespace std;
long long h, w;
long long get(long long x, long long y) {
  if (y == 0) {
    return x;
  }
  if (x == h) {
    return h + y;
  }
  if (y == w) {
    return h + w + (h - x);
  }
  return h + w + h + (w - y);
}
vector<pair<long long, long long> > get(long long h, long long w, long long x,
                                        long long a, long long b) {
  if (a <= 0 && b <= 0) return {};
  if (a >= w && b >= w) return {};
  if (x >= h || x <= 0) return {};
  if (a > 0 && a < w && b > 0 && b < w) return {};
  int fl = 0;
  if (a > b) swap(a, b), fl = 1;
  vector<pair<long long, long long> > ans;
  if (a <= 0 && b >= w) {
    ans.push_back(make_pair(x, 0));
    ans.push_back(make_pair(x, w));
  } else if (a > 0) {
    ans.push_back(make_pair(x, w));
  } else {
    ans.push_back(make_pair(x, 0));
  }
  if (fl) reverse(ans.begin(), ans.end());
  return ans;
}
const int MAXN = 120000;
long long x[MAXN];
vector<int> eds[MAXN];
int was[MAXN];
long long y[MAXN];
void add_edge(int a, int b) {
  eds[a].push_back(b);
  eds[b].push_back(a);
}
void dfs1(int v) {
  was[v] = 1;
  for (int u : eds[v]) {
    if (!was[u]) dfs1(u);
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  x1 *= 2, y1 *= 2, x2 *= 2, y2 *= 2;
  swap(y1, y2);
  h = x2 - x1;
  w = y2 - y1;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
    x[i] *= 2, y[i] *= 2;
    x[i] -= x1;
    y[i] -= y1;
  }
  int fl = 0;
  for (int i = 0; i < n; ++i) {
    if (x[i] < 0 || y[i] < 0 || x[i] > h || y[i] > w) {
      rotate(x, x + i, x + n);
      rotate(y, y + i, y + n);
      fl = 1;
      break;
    }
  }
  if (!fl) {
    cout << 1 << "\n";
    return 0;
  }
  x[n] = x[0];
  y[n] = y[0];
  int cnt = 0;
  vector<pair<long long, int> > vv;
  for (int i = 0; i < n; ++i) {
    if (x[i] == x[i + 1]) {
      auto tmp = get(h, w, x[i], y[i], y[i + 1]);
      for (auto x : tmp) vv.push_back(make_pair(get(x.first, x.second), cnt++));
    } else {
      auto tmp = get(w, h, y[i], x[i], x[i + 1]);
      for (auto x : tmp) vv.push_back(make_pair(get(x.second, x.first), cnt++));
    }
  }
  if (vv.empty()) {
    long long a = h / 2, b = w / 2;
    long double ang = 0;
    for (int i = 0; i < n; ++i)
      ang += atan2((x[i] - a) * (y[i + 1] - b) - (y[i] - b) * (x[i + 1] - a),
                   (x[i] - a) * (x[i + 1] - a) + (y[i] - a) * (y[i + 1] - a));
    if (abs(ang) <= 1)
      cout << 0 << "\n";
    else
      cout << 1 << "\n";
    return 0;
  }
  assert(vv.size() % 2 == 0);
  for (int i = 0; i < vv.size(); i += 2) {
    add_edge(vv[i].second, vv[i + 1].second);
  }
  sort(vv.begin(), vv.end());
  for (int i = 0; i < vv.size(); ++i) {
    if (vv[i].second == 0) {
      rotate(vv.begin(), vv.begin() + i, vv.end());
      break;
    }
  }
  rotate(vv.begin(), vv.begin() + 1, vv.end());
  for (int i = 0; i < vv.size(); i += 2) {
    add_edge(vv[i].second, vv[i + 1].second);
  }
  int ans = 0;
  for (int i = 0; i < cnt; ++i) {
    if (!was[i]) dfs1(i), ++ans;
  }
  cout << ans << "\n";
  return 0;
}