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
#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int n, X, Y;
vector< pair<int, pair<int, int> > >v;
pair<int, int> x[1000005], y[1000005]; // <x, index> , <y, index>
int x_1, y_1, x_2, y_2;
int nth[500002];

long long find_best(pair<int, int> tab[], int M) {
  for (int i = 0; i <= n; i++) {
    nth[i] = 0;
  }
  v.clear();
  long long off = M - tab[2*n].first;
  int pos = 0;
  long long best = 0;
  int ranges_nr = 0;
  for (int i = 1; i <= 2*n; i++) {
    int range = (tab[i].first-pos);
    pos = tab[i].first;
    int square = tab[i].second;
    nth[square]++;
    if (ranges_nr == 0) {
      off += range;
      ranges_nr++;
      v.push_back({square, {ranges_nr, 0}});
    } else {
      v[v.size()-1].second.second += range;
      if (nth[square] == 1) {
        ranges_nr++;
        v.push_back({square, {ranges_nr, 0}});
      } else {
        ranges_nr--;
        auto top = v[v.size()-1];
        while (nth[top.first] == 2) {
          v.pop_back();
          if (top.second.second > best) {
            best = top.second.second;
          }
          if (v.empty())
            break;
          top = v[v.size()-1];
        }
        if ((!v.empty()) && ranges_nr != top.second.first) {
          if (top.second.second > best) {
            best = top.second.second;
          }
          v[v.size()-1].second.first = ranges_nr;
          v[v.size()-1].second.second = 0;
        }
      }
    }
  }
  return max(off, best);
}

int main() {
  ios::sync_with_stdio(false);

  cin >> n >> X >> Y;
  for (int i = 1; i <= n; i++) {
    cin >> x_1 >> y_1;
    cin >> x_2 >> y_2;
    x[2*i-1] = {x_1, i};
    x[2*i] = {x_2, i};
    y[2*i-1] = {y_1, i};
    y[2*i] = {y_2, i};
  }
  sort(x + 1, x + 2*n + 1);
  sort(y + 1, y + 2*n + 1);
  long long w = find_best(x, X);
  long long h = find_best(y, Y);
  long long score = w*h;
  cout << score << endl;
  return 0;
}