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


#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

int read() { int n; scanf("%d", &n); return n; }

const int MAXN = 500000 + 9;

int n;
int nn;
int X;
int Y;
int w[MAXN];
int weight[MAXN][8];
PII x[MAXN * 2];
PII y[MAXN * 2];

const int  p = 1000000000 + 1011;
const int p1 = 1000123456 + 3;
const int p2 = 1001234567 + 2;

int rnd() { return (rand() >> 5) & 1023; }

typedef pair<PII, PII> PI4;
typedef pair<PI4, PI4> PI8;
typedef pair<PI8, int> PI9;

#define get0 first.first.first.first
#define get1 first.first.first.second
#define get2 first.first.second.first
#define get3 first.first.second.second
#define get4 first.second.first.first
#define get5 first.second.first.second
#define get6 first.second.second.first
#define get7 first.second.second.second
#define get8 second



int brute(PII *data, int len) {
	vector<int> used(n, 0);
	map<vector<int>, int> m;

	int res = 0;

	int last = 0;
	for (int i=0; i<nn; ) {
		int fst = data[i].first;
		int cur = m[used] += fst - last;
		if (cur > res) res = cur;
		for (; i < nn && data[i].first == fst; ++i) {
			int idx = data[i].second;
			if (idx > 0) {
				idx = idx - 1;
				used[idx] = 1;
			} else {
				idx = 0 - idx - 1;
				used[idx] = 0;
			}
		}
		last = fst;
	}

	int cur = m[used] += len - last;
	if (cur > res) res = cur;

	return res;
}

int solve(PII *data, int len) {
	PI9 hhash;
	hhash.get0 = 0;
	hhash.get1 = 0;
	hhash.get2 = 0;
	hhash.get3 = 0;
	hhash.get4 = 0;
	hhash.get5 = 0;
	hhash.get6 = 0;
	hhash.get7 = 0;
	hhash.get8 = 0;

	map<PI9, int> m;

	int res = 0;

	int last = 0;
	for (int i=0; i<nn; ) {
		int fst = data[i].first;
		int cur = m[hhash] += fst - last;
		if (cur > res) res = cur;
		for (; i < nn && data[i].first == fst; ++i) {
			int idx = data[i].second;
			if (idx > 0) {
				idx = idx - 1;
				hhash.get0 += weight[idx][0]; if (hhash.get0 >= p1) hhash.get0 -= p1;
				hhash.get1 += weight[idx][1]; if (hhash.get1 >= p1) hhash.get1 -= p1;
				hhash.get2 += weight[idx][2]; if (hhash.get2 >= p1) hhash.get2 -= p1;
				hhash.get3 += weight[idx][3]; if (hhash.get3 >= p1) hhash.get3 -= p1;
				hhash.get4 += weight[idx][4]; if (hhash.get4 >= p2) hhash.get4 -= p2;
				hhash.get5 += weight[idx][5]; if (hhash.get5 >= p2) hhash.get5 -= p2;
				hhash.get6 += weight[idx][6]; if (hhash.get6 >= p2) hhash.get6 -= p2;
				hhash.get7 += weight[idx][7]; if (hhash.get7 >= p2) hhash.get7 -= p2;
				hhash.get8 += w[idx]; if (hhash.get8 >= p) hhash.get8 -= p;
			} else {
				idx = 0 - idx - 1;
				hhash.get0 -= weight[idx][0]; if (hhash.get0 < 0) hhash.get0 += p1;
				hhash.get1 -= weight[idx][1]; if (hhash.get1 < 0) hhash.get1 += p1;
				hhash.get2 -= weight[idx][2]; if (hhash.get2 < 0) hhash.get2 += p1;
				hhash.get3 -= weight[idx][3]; if (hhash.get3 < 0) hhash.get3 += p1;
				hhash.get4 -= weight[idx][4]; if (hhash.get4 < 0) hhash.get4 += p2;
				hhash.get5 -= weight[idx][5]; if (hhash.get5 < 0) hhash.get5 += p2;
				hhash.get6 -= weight[idx][6]; if (hhash.get6 < 0) hhash.get6 += p2;
				hhash.get7 -= weight[idx][7]; if (hhash.get7 < 0) hhash.get7 += p2;
				hhash.get8 -= w[idx]; if (hhash.get8 < 0) hhash.get8 += p;
			}
		}
		last = fst;
	}

	int cur = m[hhash] += len - last;
	if (cur > res) res = cur;

	return res;
}

int main() {
	srand(20191212);
	n = read();
	nn = n << 1;
	X = read();
	Y = read();

	for (int i=0; i<n; ++i) {
		int x1 = read();
		int y1 = read();
		int x2 = read();
		int y2 = read();
		if (x1 > x2) { int tmp = x1; x1 = x2; x2 = tmp; }
		if (y1 > y2) { int tmp = y1; y1 = y2; y2 = tmp; }
		x[i<<1].first = x1;
		x[i<<1].second = i + 1;
		x[(i<<1)|1].first = x2;
		x[(i<<1)|1].second = 0 - i - 1;
		y[i<<1].first = y1;
		y[i<<1].second = i + 1;
		y[(i<<1)|1].first = y2;
		y[(i<<1)|1].second = 0 - i - 1;
	}

	sort(x, x + nn);
	sort(y, y + nn);

	weight[0][0] = rnd();
	weight[0][4] = 123456 + rnd();
	w[0] = 1;
	for (int i=1; i<n; ++i) {
		weight[i][0] = weight[i-1][0] + rnd();
		weight[i][4] = weight[i-1][4] + rnd();
		w[i] = w[i-1] * 2; if (w[i] >= p) w[i] -= p;
	}

	for (int i=n-1; i>=0; --i) {
		weight[i][1] = (1LL * weight[i][0] * weight[i][0]) % p1;
		weight[i][2] = (1LL * weight[i][0] * weight[i][1]) % p1;
		weight[i][3] = (1LL * weight[i][1] * weight[i][2]) % p1;
		weight[i][5] = (1LL * weight[i][4] * weight[i][4]) % p2;
		weight[i][6] = (1LL * weight[i][4] * weight[i][5]) % p2;
		weight[i][7] = (1LL * weight[i][5] * weight[i][6]) % p2;
	}

	int rx = solve(x, X);
	int ry = solve(y, Y);
//	int rx = brute(x, X);
//	int ry = brute(y, Y);

	fprintf(stderr, "x: %d\n", rx);
	fprintf(stderr, "y: %d\n", ry);

	ll res = 1LL * rx * ry;
	printf("%lld\n", res);

	return 0;
}