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
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <utility>
#include <stack>
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define MP make_pair
#define FOR(v,p,k) for(int v=(p);v<=(k);++v)
#define FORD(v,p,k) for(int v=(p);v>=(k);--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define VAR(v,i) __typeof(i) v=(i)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define SIZE(x) (int)x.size()
#define ALL(c) c.begin(),c.end()

#define ODD(x) ((x)%2)
#define EVEN(x) (!(ODD(x)))

int get_longest_intersection(vector<PII> &xt) {
    priority_queue<int> q;
    unordered_map<LL, int> vals;
    int active_cnt = 0, prev=0, best=0;
    int max_cnt = xt.size()+1;

    for(auto &x: xt) {
        int curr = x.ST;
        if (curr > prev) {
            LL key = (LL)(-q.top()) * max_cnt + active_cnt;
            vals[key] += curr - prev;
            best = max(best, vals[key]);
        }
        prev = curr;
        if (x.ST < x.ND) {
            active_cnt++;
            q.push(-x.ND);
        } else {
            active_cnt--;
            q.pop();
        }
    }
    return best;
}

int main() {
    int n, X, Y;
    scanf("%d%d%d", &n, &X, &Y);
    vector<PII> xt, yt;
    xt.reserve(2*n+2);
    yt.reserve(2*n+2);
    xt.PB(MP(0,X));
    xt.PB(MP(X,0));
    yt.PB(MP(0,Y));
    yt.PB(MP(Y,0));

    REP(i,n) {
        int x1,x2,y1,y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        xt.PB(MP(x1, x2));
        xt.PB(MP(x2, x1));
        yt.PB(MP(y1, y2));
        yt.PB(MP(y2, y1));
    }
    sort(begin(xt), end(xt));
    sort(begin(yt), end(yt));

    int best_x = get_longest_intersection(xt);
    int best_y = get_longest_intersection(yt);
    printf("%lld\n", (LL) best_x * best_y);
    return 0;
}