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;
int h, w;
int get(int x, int y) {
  if (!y) 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(int h, int w, int x, int a, int b) {
  vector<pair<long long, long long> > ans;
  if (a <= 0 && b <= 0) return ans;
  if (a >= w && b >= w) return ans;
  if (x >= h || x <= 0) return ans;
  if (a > 0 && a < w && b > 0 && b < w) return ans;
  int fl = 0;
  if (a > b) swap(a, b), fl = 1;
  if (a <= 0 && b >= w) {
    ans.push_back(pair<long long, long long>(x, 0));
    ans.push_back(pair<long long, long long>(x, w));
  } else if (a > 0)
    ans.push_back(pair<long long, long long>(x, w));
  else
    ans.push_back(pair<long long, long long>(x, 0));
  if (fl) reverse(ans.begin(), ans.end());
  return ans;
}
int x[120005], y[120005];
bool vis[120005];
vector<int> e[120005];
void add(int x, int y) {
  e[x].push_back(y);
  e[y].push_back(x);
}
void dfs(int x) {
  vis[x] = 1;
  for (int i = 0; i < e[x].size(); i++)
    if (!vis[e[x][i]]) dfs(e[x][i]);
}
int main() {
  int x1, x2, y1, y2;
  scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
  swap(y1, y2);
  x1 *= 2;
  x2 *= 2;
  y1 *= 2;
  y2 *= 2;
  h = x2 - x1, w = y2 - y1;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &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) return puts("1"), 0;
  x[n] = x[0];
  y[n] = y[0];
  int cnt = 0;
  vector<pair<long long, int> > vec;
  for (int i = 0; i < n; i++)
    if (x[i] == x[i + 1]) {
      vector<pair<long long, long long> > tmp = get(h, w, x[i], y[i], y[i + 1]);
      for (int j = 0; j < tmp.size(); j++)
        vec.push_back(
            pair<long long, int>(get(tmp[j].first, tmp[j].second), cnt++));
    } else {
      vector<pair<long long, long long> > tmp = get(w, h, y[i], x[i], x[i + 1]);
      for (int j = 0; j < tmp.size(); j++)
        vec.push_back(
            pair<long long, int>(get(tmp[j].second, tmp[j].first), cnt++));
    }
  if (!vec.size()) {
    int a = h / 2, b = w / 2;
    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] - b) * (y[i + 1] - b));
    printf("%d", abs(ang) <= 1 ? 0 : 1);
    return 0;
  }
  for (int i = 0; i < vec.size(); i += 2) add(vec[i].second, vec[i + 1].second);
  sort(vec.begin(), vec.end());
  for (int i = 0; i < vec.size(); i++)
    if (vec[i].second == 0) {
      rotate(vec.begin(), vec.begin() + i, vec.end());
      break;
    }
  rotate(vec.begin(), vec.begin() + 1, vec.end());
  for (int i = 0; i < vec.size(); i += 2) add(vec[i].second, vec[i + 1].second);
  int ans = 0;
  for (int i = 0; i < cnt; i++)
    if (!vis[i]) dfs(i), ans++;
  printf("%d", ans);
}