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;
struct data {
  int x, y;
} p[100000];
set<pair<pair<int, int>, int> > cur;
vector<pair<int, int> > ve[100000];
int sx, sy, tx, ty, n, ans, id, flag, fa[100000];
int find1(int x) { return fa[x] == x ? x : find1(fa[x]); }
void mod(pair<int, int> x) {
  ++id;
  int m1, m2, flag1 = 1;
  fa[id] = id;
  for (auto it = cur.begin(); it != cur.end();) {
    if (x.first == it->first.first) {
      flag1--;
      fa[id] = fa[it->second];
      m1 = x.second;
      m2 = it->first.second;
      if (m1 >= m2) swap(m1, m2);
      x = make_pair(m1, m2);
      it = cur.erase(it);
      break;
    } else if (x.second == it->first.second) {
      flag1--;
      fa[id] = fa[it->second];
      m1 = x.first;
      m2 = it->first.first;
      if (m1 >= m2) swap(m1, m2);
      x = make_pair(m1, m2);
      it = cur.erase(it);
      break;
    } else if (x.first > it->first.first && x.second < it->first.second) {
      flag1--;
      fa[id] = fa[it->second];
      fa[id + 1] = fa[it->second];
      fa[id + 2] = fa[it->second];
      cur.insert({make_pair(it->first.first, x.first), ++id});
      cur.insert({make_pair(x.second, it->first.second), ++id});
      x = make_pair(0, 0);
      cur.erase(it);
      break;
    } else if (x.second == it->first.first) {
      if (find1(id) != find1(it->second))
        flag1--, fa[find1(id)] = find1(it->second);
      m1 = x.first;
      m2 = it->first.second;
      x = make_pair(m1, m2);
      it = cur.erase(it);
      continue;
    } else if (x.first == it->first.second) {
      if (find1(id) != find1(it->second))
        flag1--, fa[find1(id)] = find1(it->second);
      m1 = it->first.first;
      m2 = x.second;
      x = make_pair(m1, m2);
      it = cur.erase(it);
      continue;
    }
    it++;
  }
  if (flag) ans += flag1;
  if (x.first < x.second) cur.insert(make_pair(x, id));
}
int main() {
  int m1, m2;
  scanf("%d%d%d%d%d", &sx, &sy, &tx, &ty, &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &p[i].x, &p[i].y);
  }
  p[n + 1] = p[1];
  swap(sy, ty);
  for (int i = 1; i <= n; i++) {
    if (p[i].x == p[i + 1].x) continue;
    m1 = max(min(p[i].x, p[i + 1].x), sx);
    m2 = min(max(p[i].x, p[i + 1].x), tx);
    if (m1 < m2) ve[p[i].y].push_back(make_pair(m1, m2));
  }
  for (int i = 0; i < ty; i++) {
    for (auto x : ve[i]) mod(x);
    if (i == sy) ans = cur.size(), flag = 1;
  }
  printf("%d\n", ans);
}