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;
bitset<15010> L, R, U, D;
int x[15010], y[15010];
unordered_map<long long, int> mp;
int tot, ok[15010];
int a, b, c, d;
int ind(pair<int, int> p) {
  long long tmp = p.first * 150010 + p.second;
  if (mp[tmp])
    return mp[tmp];
  else {
    ok[++tot] = 1;
    return mp[tmp] = tot;
  }
}
vector<int> e[100010];
void add(pair<int, int> p1, pair<int, int> p2) {
  int a = ind(p1), b = ind(p2);
  e[a].push_back(b);
  e[b].push_back(a);
}
int vis[150010];
int dfs(int u) {
  int ret = ok[u];
  vis[u] = 1;
  for (auto &v : e[u]) {
    if (!vis[v]) ret |= dfs(v);
  }
  return ret;
}
int main() {
  cin >> a >> d >> c >> b;
  a++, b++, c++, d++;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i];
    x[i]++, y[i]++;
    if (x[i] < a) x[i] = a;
    if (x[i] > c) x[i] = c;
    if (y[i] < b) y[i] = b;
    if (y[i] > d) y[i] = d;
  }
  x[n + 1] = x[1];
  y[n + 1] = y[1];
  bitset<15010> tmp;
  tmp.set();
  for (int i = 1; i <= n; i++) {
    if (x[i] == x[i + 1] && y[i] == y[i + 1]) continue;
    if (x[i] == x[i + 1]) {
      if (x[i] == a)
        L ^= (tmp << min(y[i], y[i + 1])) &
             (tmp >> (15010 - max(y[i], y[i + 1])));
      else if (x[i] == c)
        R ^= (tmp << min(y[i], y[i + 1])) &
             (tmp >> (15010 - max(y[i], y[i + 1])));
      else
        add({x[i], y[i]}, {x[i + 1], y[i + 1]});
    } else if (y[i] == y[i + 1]) {
      if (y[i] == b)
        D ^= (tmp << min(x[i], x[i + 1])) &
             (tmp >> (15010 - max(x[i], x[i + 1])));
      else if (y[i] == d)
        U ^= (tmp << min(x[i], x[i + 1])) &
             (tmp >> (15010 - max(x[i], x[i + 1])));
      else
        add({x[i], y[i]}, {x[i + 1], y[i + 1]});
    }
  }
  int preL = 0, preR = 0, preU = 0, preD = 0;
  for (int i = 1; i < 15010; i++) {
    if (!L[i] && L[i - 1]) add({a, preL + 1}, {a, i});
    if (!L[i]) preL = i;
    if (!R[i] && R[i - 1]) add({c, preR + 1}, {c, i});
    if (!R[i]) preR = i;
    if (!D[i] && D[i - 1]) add({preD + 1, b}, {i, b});
    if (!D[i]) preD = i;
    if (!U[i] && U[i - 1]) add({preU + 1, d}, {i, d});
    if (!U[i]) preU = i;
  }
  int ans = 0;
  for (int i = 1; i <= tot; i++) {
    if (!vis[i]) ans += dfs(i);
  }
  cout << ans << endl;
}