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

using namespace std;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) (int)(x).size()
#define CLEAR(tab) memset(tab, 0, sizeof(tab))
#define REP(x, n) for(int x = 0; x < (n); x++)
#define FOR(x, b, e) for(int x = (b); x <= (e); x++)
#define FORD(x, b, e) for(int x = (b); x >= (e); x--)
#define VAR(v, n) __typeof(n) v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define DEBUG(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)

typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MXN = 500010;
const int C = 4 * 262144;
const int INF = 1000000001;

int n, X[2];
vector<PII> pkt[2];
vector<PII> event[2 * MXN];
set<PII> actP, actK;

int tree[2 * C + 10];
int cnt[2 * C + 10];
int wyn[2 * C + 10];

void dodaj(int w, int L, int R, int l, int r, int val) {
	if(l <= L && R <= r) {
		tree[w] += val;
		if(tree[w] == 0) {
			if(w < C)
				wyn[w] = wyn[2 * w] + wyn[2 * w + 1];
			else
				wyn[w] = cnt[w];
		}
		else
			wyn[w] = 0;
		return;
	}
	
	int S = (L + R) / 2;
	if(l <= S)
		dodaj(2 * w, L, S, l, r, val);
	if(r > S)
		dodaj(2 * w + 1, S + 1, R, l, r, val);

	if(tree[w] > 0)
		wyn[w] = 0;
	else if(w < C)
		wyn[w] = wyn[2 * w] + wyn[2 * w + 1];
	else
		wyn[w] = cnt[w];
}

int licz(int w, int L, int R, int l, int r) {
	if(l <= L && R <= r)
		return wyn[w];
	int S = (L + R) / 2;
	int res = 0;
	if(l <= S)
		res += licz(2 * w, L, S, l, r);
	if(r > S)
		res += licz(2 * w + 1, S + 1, R, l, r);
	if(tree[w])
		res = 0;
	return res;
}

int solve(vector<PII> &vec, int t) {
	vector<PII> vec2;
	
	FOR(i, 0, SIZE(vec) - 1) {
		vec2.PB(MP(vec[i].F, -(i + 1) ) );
		vec2.PB(MP(vec[i].S, i + 1) );
	}
	vec2.PB(MP(0, SIZE(vec) + 1) );
	vec2.PB(MP(X[t], SIZE(vec) + 1) );
	sort(ALL(vec2) );	
	
	int liczy = 1;
	
	FOR(i, 0, SIZE(vec2) - 1) {
		int iter = i;
		while(iter < SIZE(vec2) && vec2[iter].F == vec2[i].F) {
			int ind = vec2[iter].S;
			if(ind != SIZE(vec) + 1) {
				if(ind < 0)
					vec[-ind - 1].F = liczy;
				if(ind > 0)
					vec[ind - 1].S = liczy;
			}
			iter++;
		}
		cnt[liczy + C] = vec2[i].F;
		liczy++;
		i = iter - 1;
	}
	vec2.clear();
	
	cnt[C + liczy] = X[t];
	FOR(i, 1, liczy) {
		cnt[i + C] = cnt[i + C + 1] - cnt[i + C];
		wyn[i + C] = cnt[i + C];
	}
	FORD(i, C - 1, 1)
		wyn[i] = wyn[2 * i] + wyn[2 * i + 1];
	
	FOR(i, 0, SIZE(vec) - 1) {
		event[vec[i].F].PB(MP(1, i) );
		event[vec[i].S].PB(MP(0, i) );
		dodaj(1, 0, C - 1, vec[i].F, vec[i].S - 1, 1);
	}

	int res = 0;
	FOR(i, 0, liczy) {
		FOREACH(it, event[i]) {
			PII p1 = *it;
			int ind = p1.S;
			PII p2 = vec[ind];
			if(p1.F == 0) {
				dodaj(1, 0, C - 1, p2.F, p2.S - 1, 1);
				actP.erase(MP(p2.F, ind) );
				actK.erase(MP(p2.S, ind) );
			}
			else if(p1.F == 1) {
				actP.insert(MP(p2.F, ind) );
				actK.insert(MP(p2.S, ind) );
				dodaj(1, 0, C - 1, p2.F, p2.S - 1, -1);
			}

		}
		if(SIZE(event[i]) ) {
			PII B = MP(1, liczy - 1);
			if(SIZE(actP) > 0)
				B = MP(actP.rbegin() -> F, actK.begin() -> F);
			res = max(res, licz(1, 0, C - 1, B.F, B.S - 1) );
			event[i].clear();
		}
	}
	
	actP.clear();
	actK.clear();
	CLEAR(tree);
	CLEAR(cnt);
	CLEAR(wyn);
	return res;
}

void test() {
	scanf("%d", &n);
	FOR(i, 0, 1)
		scanf("%d", &X[i]);
	FOR(i, 1, n) {
		int x1, y1, x2, y2;
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		if(x1 > x2)
			swap(x1, x2);
		if(y1 > y2)
			swap(y1, y2);
		pkt[0].PB(MP(x1, x2) );
		pkt[1].PB(MP(y1, y2) );
	}
	
	int q[2];
	FOR(i, 0, 1)
		q[i] = solve(pkt[i], i);
	printf("%lld\n", (LL)q[0] * q[1]);
}

int main() {
	int te = 1;
//	scanf("%d", &te);
	while(te--)
		test();
	return 0;
}