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 Range {
  int x, y1, y2, num;
  bool operator<(const Range &p) const { return y1 < p.y1; }
};
set<Range> Set;
int Bx, By, Ex, Ey, UF[100100];
int Find(int a) {
  if (a == UF[a]) return a;
  return UF[a] = Find(UF[a]);
}
struct Seg {
  int x, y1, y2;
  bool operator<(const Seg &p) const { return x < p.x; }
} w[100100];
struct point {
  int x, y;
} P[100100];
struct Rect {
  int bx, by, ex, ey;
  bool operator<(const Rect &p) const { return by < p.by; }
} R[100100];
int n, cnt, RC, Res;
void Add(int x1, int y1, int x2, int y2) {
  x1 = max(x1, Bx);
  x2 = min(x2, Ex);
  y1 = max(y1, By);
  y2 = min(y2, Ey);
  if (x1 < x2 && y1 < y2) {
    R[++RC] = {x1, y1, x2, y2};
    UF[RC] = RC;
  }
}
void Del(set<Range>::iterator it, Range tp) {
  vector<Range> TP;
  for (auto it2 = it; it2 != Set.end();) {
    int y1 = max(tp.y1, it2->y1);
    int y2 = min(tp.y2, it2->y2);
    if (y1 >= y2) break;
    Add(it2->x, y1, tp.x, y2);
    TP.push_back({it2->x, it2->y1, y1});
    TP.push_back({it2->x, y2, it2->y2});
    auto tt = it2;
    it2++;
    Set.erase(tt);
  }
  for (auto &t : TP) {
    if (t.y1 < t.y2) {
      Set.insert(t);
    }
  }
}
void Merge(int a, int b) {
  a = Find(a), b = Find(b);
  if (a != b) {
    UF[a] = b;
    Res--;
  }
}
void Del2(set<Range>::iterator bit, Range tp, int by) {
  vector<Range> TP;
  for (auto it = bit; it != Set.end();) {
    int y1 = max(tp.y1, it->y1);
    int y2 = min(tp.y2, it->y2);
    if (y1 >= y2) break;
    if (it->x == by) {
      Merge(it->num, tp.num);
    }
    TP.push_back({it->x, it->y1, y1});
    TP.push_back({it->x, y2, it->y2});
    auto tt = it;
    it++;
    Set.erase(tt);
  }
  for (auto &t : TP) {
    if (t.y1 < t.y2) {
      Set.insert(t);
    }
  }
  Set.insert(tp);
}
int main() {
  int i, j;
  scanf("%d%d%d%d", &Bx, &Ey, &Ex, &By);
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d%d", &P[i].x, &P[i].y);
  }
  P[n] = P[0];
  for (i = 0; i < n; i++) {
    if (P[i].x == P[i + 1].x) {
      w[cnt++] = {P[i].x, min(P[i].y, P[i + 1].y), max(P[i].y, P[i + 1].y)};
    }
  }
  sort(w, w + cnt);
  for (i = 0; i < cnt; i++) {
    auto it = Set.lower_bound({w[i].x, w[i].y1, w[i].y2});
    Range tp = {w[i].x, w[i].y1, w[i].y2};
    if (Set.empty()) {
      Set.insert(tp);
      continue;
    }
    if (it != Set.begin()) it--;
    if (it->y2 <= tp.y1) it++;
    if (it == Set.end() || it->y1 >= w[i].y2 || it->y2 <= w[i].y1) {
      Set.insert(tp);
    } else {
      Del(it, tp);
    }
  }
  sort(R + 1, R + RC + 1);
  Res = RC;
  for (i = 1; i < RC; i++) {
    for (j = i + 1; j <= RC; j++) {
      if (R[i].ey == R[j].by && max(R[i].bx, R[j].bx) < min(R[i].ex, R[j].ex)) {
        Merge(i, j);
      }
    }
  }
  printf("%d\n", Res);
}