1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <algorithm>
#include <map>
#include <set>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>

#define ll long long
#define LIM 500005

using namespace std;

int n, w, h;
int* xs = new int[LIM*2];
int* ys = new int[LIM*2];
int* x2 = new int[LIM*2];
int* y2 = new int[LIM*2];

ll computeElementHash(ll e) {
  return e*64565467433LL + e*e + 1;
}

ll computeSizeHash(ll s) {
  return 10000001471LL*(s+1)+10000003171LL*(s*s);
}

void add(map<int, set<ll>*>& m, int k, ll v) {
  if(m.find(k) == m.end()) {
    set<ll>* s = new set<ll>;
    s->insert(computeElementHash(v));
    m[k] = s;
  } else {
    m[k]->insert(computeElementHash(v));
  }
}

void add(map<int, set<ll>*>& op, map<int, set<ll>*>& cl, int from, int to, ll v) {
  int mi = min(from, to);
  int ma = max(from, to);
  add(op, mi, v);
  add(cl, ma, v);
}

int getMin(int* a) {
  int mi = INT_MAX;
  for(int i=0;i<2*n;i++) {
    mi = min(mi, a[i]);
  }
  return mi;
}

void translate(int* a, int offset) {
  for(int i=0;i<n*2;i++) {
    a[i] += offset;
  }
}

ll bh(int* xs, int s, int* sorted) {
  map<int, set<ll>*> op;
  map<int, set<ll>*> cl;
  for(int i=0;i<n;i++) {
    add(op, cl, xs[2*i], xs[2*i+1], i);
  }
  map<ll, ll> byHash;
  set<ll> cur;
  int prev = 0;
  ll h2 = 0;
  for(int i=0;i<s;i++) {
    int x = sorted[i];
    ll hc = computeSizeHash(cur.size()) + h2;
    ll z = 0;
    if(byHash.find(hc) != byHash.end()) {
      z = byHash[hc];
    }
    z += x-prev;
    byHash[hc] = z;

    if(op.find(x) != op.end()) {
      set<ll>* ops = op[x];
      for(auto it=ops->begin();it!=ops->end();it++) {
        if(cur.find(*it) == cur.end()) {
          cur.insert(*it);
          h2 += *it;
        }
      }
    }
    if(cl.find(x) != cl.end()) {
      set<ll>* cls = cl[x];
      for(auto it=cls->begin();it!=cls->end();it++) {
        if(cur.find(*it) != cur.end()) {
          cur.erase(*it);
          h2 -= *it;
        }
      }
    }
    prev = x;
  }
  ll best = 0;
  for(auto it=byHash.begin();it!=byHash.end();it++) {
    best = max(best, it->second);
  }
  return best;
}

ll solve() {
  int miX = getMin(xs);
  int miY = getMin(ys);
  translate(xs, -miX);
  translate(ys, -miY);

  int s = n*2+1;
  memcpy(x2,xs,2*n*sizeof(int));
  memcpy(y2,ys,2*n*sizeof(int));

  x2[s-1] = w;
  y2[s-1] = h;
  sort(x2, x2+s);
  sort(y2, y2+s);

  ll bx = bh(xs, s, x2);
  ll by = bh(ys, s, y2);

  return bx * by;
}

int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);

  scanf("%d%d%d", &n, &w, &h);
  for(int i=0;i<n;i++) {
    scanf("%d%d%d%d", &(xs[2*i]), &(ys[2*i]), &(xs[2*i+1]), &(ys[2*i+1]));
  }

  ll res = solve();

  printf("%lld\n", res);
  return 0;
}