human
Can you solve the below in CPP?
Polycarpus has a chessboard of size n × m, where k rooks are placed. Polycarpus hasn't yet invented the rules of the game he will play. However, he has already allocated q rectangular areas of special strategic importance on the board, they must be protected well. According to Polycarpus, a rectangular area of ​​the board is well protected if all its vacant squares can be beaten by the rooks that stand on this area. The rooks on the rest of the board do not affect the area's defense. The position of the rooks is fixed and cannot be changed. We remind you that the the rook beats the squares located on the same vertical or horizontal line with it, if there are no other pieces between the square and the rook. Help Polycarpus determine whether all strategically important areas are protected.

Input

The first line contains four integers n, m, k and q (1 ≤ n, m ≤ 100 000, 1 ≤ k, q ≤ 200 000) — the sizes of the board, the number of rooks and the number of strategically important sites. We will consider that the cells of the board are numbered by integers from 1 to n horizontally and from 1 to m vertically. Next k lines contain pairs of integers "x y", describing the positions of the rooks (1 ≤ x ≤ n, 1 ≤ y ≤ m). It is guaranteed that all the rooks are in distinct squares. Next q lines describe the strategically important areas as groups of four integers "x1 y1 x2 y2" (1 ≤ x1 ≤ x2 ≤ n, 1 ≤ y1 ≤ y2 ≤ m). The corresponding rectangle area consists of cells (x, y), for which x1 ≤ x ≤ x2, y1 ≤ y ≤ y2. Strategically important areas can intersect of coincide.

Output

Print q lines. For each strategically important site print "YES" if it is well defended and "NO" otherwise.

Examples

Input

4 3 3 3
1 1
3 2
2 3
2 3 2 3
2 1 3 3
1 2 2 3

Output

YES
YES
NO

Note

Picture to the sample:  For the last area the answer is "NO", because cell (1, 2) cannot be hit by a rook.

What is a Python code to determine whether all strategically important areas are protected?
assistant
#Here is Python code to determine whether all strategically important areas are protected.

#include <bits/stdc++.h>
using namespace std;
template <class V, int NV>
class SegTree_1 {
 public:
  vector<V> val;
  static V const def = 1 << 20;
  V comp(V l, V r) { return min(l, r); };
  SegTree_1() { val = vector<V>(NV * 2, def); };
  V getval(int x, int y, int l = 0, int r = NV, int k = 1) {
    if (r <= x || y <= l) return def;
    if (x <= l && r <= y) return val[k];
    return comp(getval(x, y, l, (l + r) / 2, k * 2),
                getval(x, y, (l + r) / 2, r, k * 2 + 1));
  }
  void update(int entry, V v) {
    entry += NV;
    val[entry] = v;
    while (entry > 1)
      entry >>= 1, val[entry] = comp(val[entry * 2], val[entry * 2 + 1]);
  }
};
int H, W, K, Q;
int X[202000], Y[202000];
int X1[202000], Y1[202000];
int X2[202000], Y2[202000];
int ok[202000];
vector<int> evR[210000], evQ[210000];
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> W >> H >> K >> Q;
  for (i = 0; i < K; i++) cin >> X[i] >> Y[i];
  for (i = 0; i < Q; i++) cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
  for (k = 0; k < 2; k++) {
    SegTree_1<int, 1 << 20> miny;
    for (i = 0; i < 210000; i++) evR[i].clear(), evQ[i].clear();
    for (i = 0; i < K; i++) evR[Y[i]].push_back(i);
    for (i = 0; i < Q; i++) evQ[Y2[i]].push_back(i);
    for (i = 1; i <= W; i++) miny.update(i, 0);
    for (i = 1; i <= H; i++) {
      for (auto& r : evR[i]) miny.update(X[r], i);
      for (auto& r : evQ[i]) ok[r] |= miny.getval(X1[r], X2[r] + 1) >= Y1[r];
    }
    swap(W, H);
    for (i = 0; i < K; i++) swap(X[i], Y[i]);
    for (i = 0; i < Q; i++) swap(X1[i], Y1[i]);
    for (i = 0; i < Q; i++) swap(X2[i], Y2[i]);
  }
  for (i = 0; i < Q; i++) cout << (ok[i] ? "YES" : "NO") << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false);
  for (i = 0; i < argc - 1; i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < s.size(); i++) ungetc(s[s.size() - 1 - i], stdin);
  solve();
  return 0;
}