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 long long N = 1e5 + 10;
int n;
int X1, Y1, X2, Y2;
vector<pair<long long, long long> > polygon;
int ind = 1;
struct point {
  int x, y;
  int kierunek;
  point(int x, int y, int kierunek) {
    this->x = x;
    this->y = y;
    this->kierunek = kierunek;
  }
  point() : x(0), y(0) {}
  bool operator<(const point b) const {
    if (kierunek != b.kierunek) return kierunek < b.kierunek;
    if (kierunek == 1) return x > b.x;
    if (kierunek == 3) return x < b.x;
    if (kierunek == 2) return y > b.y;
    if (kierunek == 4) return y < b.y;
  }
  bool operator==(const point b) const {
    return x == b.x && y == b.y && kierunek == b.kierunek;
  }
} plansza[N];
bool wewnatrz(pair<long long, long long> a) {
  return a.first < X2 && a.first > X1 && a.second < Y1 && a.second > Y2;
}
int jaki_kierunek(pair<long long, long long> a, pair<long long, long long> b) {
  pair<long long, long long> mn(min(a.first, b.first), min(a.second, b.second));
  pair<long long, long long> wi(max(a.first, b.first), max(a.second, b.second));
  if (mn.first < X2 && X2 <= wi.first) return 4;
  if (mn.first <= X1 && X1 < wi.first) return 2;
  if (mn.second < Y1 && Y1 <= wi.second) return 1;
  if (mn.second <= Y2 && Y2 < wi.second) return 3;
}
set<point> s;
map<point, point> droga;
map<point, int> istnieje;
void wypisz(point poczatek) {
  cerr << poczatek.x << " " << poczatek.y << " " << poczatek.kierunek << "\n";
}
long long ilewek(pair<long long, long long> p1, pair<long long, long long> p2,
                 pair<long long, long long> p3) {
  return ((p2.first - p1.first) * (p3.second - p1.second) -
          (p3.first - p1.first) * (p2.second - p1.second));
}
bool czyprzecinaja(pair<long long, long long> p1, pair<long long, long long> p2,
                   pair<long long, long long> p3,
                   pair<long long, long long> p4) {
  long long iW1 = ilewek(p1, p2, p3);
  long long iW2 = ilewek(p1, p2, p4);
  long long iW3 = ilewek(p3, p4, p1);
  long long iW4 = ilewek(p3, p4, p2);
  return iW1 * iW2 < 0 && iW3 * iW4 < 0;
}
int przechodzi(pair<long long, long long> a, pair<long long, long long> b) {
  if (!wewnatrz(a) && !wewnatrz(b)) {
    pair<long long, long long> mn(min(a.first, b.first),
                                  min(a.second, b.second));
    pair<long long, long long> wi(max(a.first, b.first),
                                  max(a.second, b.second));
    if (mn.first <= X1 && X2 <= wi.first && Y2 < mn.second && mn.second < Y1)
      return 1;
    if (mn.second <= Y2 && Y1 <= wi.second && X1 < mn.first && mn.first < X2)
      return 2;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> X1 >> Y1 >> X2 >> Y2;
  X1 *= 2;
  Y1 *= 2;
  X2 *= 2;
  Y2 *= 2;
  pair<long long, long long> wew(X1 + 1, Y2 + 1);
  pair<long long, long long> inf(30001, Y2);
  cin >> n;
  bool jestNaZewnatrz = 0;
  int start;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    polygon.push_back(make_pair(2 * x, 2 * y));
    if (!wewnatrz(polygon[i]) && !jestNaZewnatrz) {
      jestNaZewnatrz = true;
      start = i;
    }
  }
  for (int i = 0; i < n; i++) polygon.push_back(polygon[i]);
  if (jestNaZewnatrz) {
    bool aktywny = false;
    point pocz;
    int wyn = 0;
    for (int i = start + 1; i <= start + n; i++) {
      if (!aktywny && przechodzi(polygon[i - 1], polygon[i])) {
        int co = przechodzi(polygon[i - 1], polygon[i]);
        pair<long long, long long> srodek;
        if (co == 1) {
          srodek.first = X1 + 1;
          srodek.second = polygon[i].second;
        } else {
          srodek.first = polygon[i].first;
          srodek.second = Y2 + 1;
        }
        int strona = jaki_kierunek(polygon[i - 1], srodek);
        point pom(srodek.first, srodek.second, strona);
        s.insert(pom);
        pocz = pom;
        strona = jaki_kierunek(srodek, polygon[i]);
        point pom2(polygon[i].first, polygon[i].second, strona);
        droga[pocz] = pom2;
        s.insert(pom2);
        continue;
      }
      if (aktywny && !wewnatrz(polygon[i])) {
        aktywny = false;
        int strona = jaki_kierunek(polygon[i - 1], polygon[i]);
        point pom(polygon[i].first, polygon[i].second, strona);
        droga[pocz] = pom;
        s.insert(pom);
      }
      if (!aktywny && wewnatrz(polygon[i])) {
        aktywny = true;
        int strona = jaki_kierunek(polygon[i - 1], polygon[i]);
        point pom(polygon[i].first, polygon[i].second, strona);
        s.insert(pom);
        pocz = pom;
      }
    }
    if (s.size() == 0) {
      int licz = 0;
      for (int i = 1; i <= n; i++) {
        if (czyprzecinaja(polygon[i - 1], polygon[i], wew, inf)) licz++;
      }
      if (licz % 2)
        cout << "1";
      else
        cout << "0";
    } else {
      assert(s.size() % 2 == 0);
      while (s.size()) {
        wyn++;
        set<point>::iterator poczatek = s.begin(), poczatek2;
        point koniecGlowny = *s.rbegin();
        if (!wewnatrz(make_pair(poczatek->x, poczatek->y))) {
          poczatek++;
          koniecGlowny = *s.begin();
        }
        while (true) {
          point koniec = droga[*poczatek];
          poczatek2 = s.find(koniec);
          poczatek2++;
          if (poczatek2 == s.end()) poczatek2 = s.begin();
          wypisz(*poczatek2);
          if (koniec == koniecGlowny) {
            s.erase(poczatek);
            s.erase(s.find(koniec));
            break;
          } else {
            s.erase(poczatek);
            s.erase(s.find(koniec));
            poczatek = poczatek2;
          }
        }
      }
      cout << wyn << "\n";
    }
  } else
    cout << "1";
}