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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

#ifdef USE_CERR_LOG
#define LOG if (true) cerr
#else
#define LOG if (false) cerr
#endif

typedef long long ll;
typedef unsigned long long ull;

#ifdef USE_FILE_CIN
ifstream fin("../ter.in");
#define cin fin
#endif


struct Rect {
    int idx;
    int x1;
    int y1;
    int x2;
    int y2;
};

enum RectType {
    Proper = 0,
    Horizontal,
    Vertical,
    Negative
};

struct Int128 {
    ull first;
    ull second;
    
    Int128(int val): first(val), second(0) {}
};

int bigBitsCount;

struct BigInt {
    vector<ull> bits;
    
    BigInt(int val): bits(bigBitsCount, val) {}
};

int X, Y, n;
vector<Rect> rects;
vector<int> xPoints;
vector<int> yPoints;

void printRects() {
#ifdef USE_CERR_LOG
    for (const Rect& rect : rects) {
        LOG << rect.idx << ": (" << rect.x1 << "," << rect.y1 << "); (" << rect.x2 << "," << rect.y2 << ")" << endl;
    }
    
    LOG << "--------------------------------" << endl;
#endif
}


inline bool operator < (const Int128& int1, const Int128& int2) {
    if (int1.second == int2.second) return int1.first < int2.first;
    return int1.second < int2.second;
}

inline bool operator < (const BigInt& int1, const BigInt& int2) {
    for (int i = bigBitsCount-1; i>=0; i--) {
        if (int1.bits[i] != int2.bits[i]) return int1.bits[i] < int2.bits[i];
    }
    return false;
}

inline RectType getRectType(const Rect& rect, int x, int y) {
    bool inx = rect.x1 <= x && x < rect.x2;
    bool iny = rect.y1 <= y && y < rect.y2;
    
    if (inx) {
        if (iny) return Proper;
        else return Vertical;
    }
    
    if (iny) return Horizontal;
    else return Negative;
}


inline void updateRectByte(int rectIdx, RectType rectType, ull& rectByte) {
    rectByte += (ull) rectType << (2 * rectIdx);
}


inline void updateRectByte(int rectIdx, RectType rectType, Int128& rectByte) {
    if (rectIdx < 16) {
        rectByte.first += (ull) rectType << (2 * rectIdx);
    } else {
        rectByte.second += (ull) rectType << (2 * (rectIdx - 16));
    }
}

inline void updateRectByte(int rectIdx, RectType rectType, BigInt& rectByte) {
    int byteIdx = rectIdx / 16;
    rectByte.bits[byteIdx] += (ull) rectType << (2 * (rectIdx % 16));
}


void populatePoints() {
    xPoints.reserve(2*n + 2);
    yPoints.reserve(2*n + 2);
    
    xPoints.push_back(0);
    xPoints.push_back(X);
    yPoints.push_back(0);
    yPoints.push_back(Y);
    
    for (Rect& rect : rects) {
        xPoints.push_back(rect.x1);
        xPoints.push_back(rect.x2);
        yPoints.push_back(rect.y1);
        yPoints.push_back(rect.y2);
    }
    
    sort(xPoints.begin(), xPoints.end());
    sort(yPoints.begin(), yPoints.end());
}


template<typename T>
void scanPoints(map<T, ull>& type2surface) {
    int prevX = xPoints[0];
    
    for (size_t i=1; i<xPoints.size(); i++) {
        int x = xPoints[i];
        int prevY = yPoints[0];
        if (x == prevX) continue;
        
        for (size_t j=1; j<yPoints.size(); j++) {
            int y = yPoints[j];
            if (y == prevY) continue;
            
            ull surface = (ull) (x - prevX) * (y - prevY);
            T rectByte(0);
            
            for (Rect& rect : rects) {
                RectType rectType = getRectType(rect, prevX, prevY);
                updateRectByte(rect.idx, rectType, rectByte);
            }
            
            type2surface[rectByte] += surface;
            prevY = y;
        }
        
        prevX = x;
    }
}


template<typename T>
ull getMaxSurface(map<T, ull>& type2surface) {
    ull maxSurface = 0;
    
    for (auto& entry : type2surface) {
        maxSurface = max(maxSurface, entry.second);
    }
    
    return maxSurface;
}


void readData() {
    cin >> n >> X >> Y;
    rects.resize(n);
    int idx = 0;
    
    for (Rect& rect : rects) {
        rect.idx = idx;
        cin >> rect.x1 >> rect.y1 >> rect.x2 >> rect.y2;
        
        if (rect.x1 > rect.x2) {
            swap(rect.x1, rect.x2);
        }
        if (rect.y1 > rect.y2) {
            swap(rect.y1, rect.y2);
        }
        
        idx++;
    }
    
    printRects();
}

int solve() {
    populatePoints();
    
    if (n <= 16) {
        map<ull, ull> type2surface;
        scanPoints(type2surface);
        return getMaxSurface(type2surface);
    } else if (n <= 32) {
        map<Int128, ull> type2surface;
        scanPoints(type2surface);
        return getMaxSurface(type2surface);        
    } else {
        bigBitsCount = ((n - 1) / 16) + 1;
        map<BigInt, ull> type2surface;
        scanPoints(type2surface);
        return getMaxSurface(type2surface);        
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    
    readData();
    cout << solve() << endl;
    
    return 0;
}