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>
long long h, w;
static 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);
}
static std::vector<std::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) std::swap(a, b), fl = 1;
  std::vector<std::pair<long long, long long> > ans;
  if (a <= 0 && b >= w) {
    ans.push_back(std::make_pair(x, 0));
    ans.push_back(std::make_pair(x, w));
  } else if (a > 0) {
    ans.push_back(std::make_pair(x, w));
  } else {
    ans.push_back(std::make_pair(x, 0));
  }
  if (fl) std::reverse(ans.begin(), ans.end());
  return ans;
}
const int MAXN = 120000;
long long x[MAXN];
std::vector<long long> 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(int argc, char* argv[]) {
  std::ios_base::sync_with_stdio(false), std::cin.tie(0);
  std::cout.tie(0);
  long long x1, y1, x2, y2;
  std::cin >> x1 >> y1 >> x2 >> y2;
  x1 *= 2, y1 *= 2, x2 *= 2, y2 *= 2;
  std::swap(y1, y2);
  h = x2 - x1;
  w = y2 - y1;
  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::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) {
      std::rotate(x, x + i, x + n);
      std::rotate(y, y + i, y + n);
      fl = 1;
      break;
    }
  }
  if (!fl) {
    std::cout << 1 << "\n";
    return 0;
  }
  x[n] = x[0];
  y[n] = y[0];
  int cnt = 0;
  std::vector<std::pair<long long, long long> > 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(std::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(std::make_pair(get(x.second, x.first), cnt++));
    }
  }
  if (vv.empty()) {
    long long a = h / 2, b = w / 2;
    double ang = 0;
    for (int i = 0; i < n; ++i) {
      long long xa = x[i] - a;
      long long ya = y[i] - a;
      long long x1a = x[i + 1] - a;
      long long yb = y[i] - b;
      long long y1b = y[i + 1] - b;
      long long y1a = y[i + 1] - a;
      ang += std::atan2(xa * y1b - yb * x1a, xa * x1a + ya * y1a);
    }
    if (std::abs(ang) <= 1)
      std::cout << 0 << "\n";
    else
      std::cout << 1 << "\n";
    return 0;
  }
  for (size_t i = 0; i < vv.size(); i += 2) {
    add_edge(vv[i].second, vv[i + 1].second);
  }
  std::sort(vv.begin(), vv.end());
  for (int i = 0; i < vv.size(); ++i) {
    if (vv[i].second == 0) {
      std::rotate(vv.begin(), vv.begin() + i, vv.end());
      break;
    }
  }
  std::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;
  }
  std::cout << ans << "\n";
  return 0;
}