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
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

const long long int Q = 1000000000039; // 10e12 + 39
const long long int P = 31;

const int N_MAX = 500000;

long long int Potega[3*N_MAX];
bool S[3*N_MAX];

int main() {
	int n, X, Y;
	scanf("%d %d %d", &n, &X, &Y);
	Potega[0] = 1;
	for (int i = 1; i < 3*n; ++i) {
		Potega[i] = 1LL * Potega[i-1] * P;
	}
	vector< pair<int, int> > Xt, Yt;
	Xt.push_back(make_pair(0, 0));
	Xt.push_back(make_pair(X, 0));
	Yt.push_back(make_pair(0, 0));
	Yt.push_back(make_pair(Y, 0));
	for (int i = 1; i <= n; ++i) {
		int x1, y1, x2, y2;
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		Xt.push_back(make_pair(x1, i));
		Xt.push_back(make_pair(x2, i));
		Yt.push_back(make_pair(y1, i));
		Yt.push_back(make_pair(y2, i));
	}
	sort(Xt.begin(), Xt.end());
	sort(Yt.begin(), Yt.end());
	long long int X_max = 0, Y_max = 0;
	map< long long int, long long int > MX, MY;
	
	long long int slowo = 0;
	for (int i = 0; i < 2*(n+1) - 1; ++i) {
		int przedzial = Xt[i].second;
		int dlugosc = Xt[i + 1].first - Xt[i].first;
		S[przedzial] = !S[przedzial];
		if (S[przedzial]) {
			slowo += Potega[przedzial] % Q;
		} else {
			slowo -= Potega[przedzial] % Q;
		}
		long long int prev = MX[slowo];
		MX[slowo] += dlugosc;
		X_max = max(X_max, prev + dlugosc);
		MX[slowo] = prev + dlugosc;
	}

	slowo = 0; S[0] = 0;
	for (int i = 0; i < 2*(n+1) - 1; ++i) {
		int przedzial = Yt[i].second;
		int dlugosc = Yt[i + 1].first - Yt[i].first;
		S[przedzial] = !S[przedzial];
		if (S[przedzial]) {
			slowo += Potega[przedzial] % Q;
		} else {
			slowo -= Potega[przedzial] % Q;
		}
		long long int prev = MY[slowo];
		MY[slowo] += dlugosc;
		Y_max = max(Y_max, prev + dlugosc);
		MY[slowo] = prev + dlugosc;
	}
	printf("%lld\n", X_max * Y_max);
	return 0;
}