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 int N = 1e5 + 1;
int x[N], y[N];
int n, H, W;
int get(int first, int second) {
  if (first == 0) return second;
  if (second == H) return H + first;
  if (first == W) return H + W + H - second;
  return H + W + H + W - first;
}
int p[N];
int s[N];
int lead(int x) { return p[x] == x ? x : p[x] = lead(p[x]); }
int join(int x, int y) {
  x = lead(x);
  y = lead(y);
  if (x == y) return 0;
  if (s[x] < s[y]) swap(x, y);
  p[y] = x;
  s[x] += s[y];
  return 1;
}
void input() {
  int first, second;
  cin >> first >> second >> W >> H;
  swap(H, second);
  W -= first;
  H -= second;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
    x[i] -= first;
    y[i] -= second;
  }
}
void solve() {
  bool in = 1;
  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);
      in = 0;
      break;
    }
  if (in) {
    puts("1");
    exit(0);
  }
  x[n] = x[0];
  y[n] = y[0];
  vector<pair<int, int> > v;
  int tot = 0;
  for (int i = 0; i < n; ++i) {
    int L = max(min(x[i], x[i + 1]), 0);
    int R = min(max(x[i], x[i + 1]), W);
    int U = max(min(y[i], y[i + 1]), 0);
    int D = min(max(y[i], y[i + 1]), H);
    if (L > R) continue;
    if (U > D) continue;
    if (L == R && U == D) continue;
    if (L == R && (L == 0 || L == W)) continue;
    if (U == D && (U == 0 || U == H)) continue;
    if (x[i] > x[i + 1]) swap(L, R);
    if (y[i] > y[i + 1]) swap(U, D);
    if (L == 0 || U == 0 || L == W || U == H) v.push_back({get(L, U), tot++});
    if (R == 0 || D == 0 || R == W || D == H) v.push_back({get(R, D), tot++});
  }
  if (v.empty()) {
    bool in = 0;
    for (int i = 0; i < n; ++i) {
      int L = min(x[i], x[i + 1]);
      int R = max(x[i], x[i + 1]);
      int U = min(y[i], y[i + 1]);
      int D = max(y[i], y[i + 1]);
      if (L <= 0 && R >= 0 && U <= 0 && D >= 0) {
        in = 1;
        break;
      }
      if (L >= 0 || R < 0) continue;
      in ^= (D <= 0);
    }
    if (in)
      puts("1");
    else
      puts("0");
    exit(0);
  }
  iota(p, p + tot, 0);
  fill(s, s + tot, 1);
  for (int i = 0; i < tot; i += 2) join(i, i + 1);
  sort(v.begin(), v.end());
  for (int i = 0; i < tot; ++i)
    if (v[i].second == 0) {
      rotate(v.begin(), v.begin() + i, v.end());
      break;
    }
  for (int i = 0; i < tot; i += 2) join(v[i].second, v[i + 1].second);
  set<int> S;
  for (int i = 0; i < tot; i += 1) S.insert(lead(i));
  cout << S.size() << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  input();
  solve();
}