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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

int na[5000005];
VI leny;
int m;
int N;
int przedzi;
int calosc;

struct elem{
	int mx;
	int sum;
	int lejzi;
	elem() {
	}
	elem(int a, int b, int c)  {
		mx = a; sum = b; lejzi = c;
	}
};
elem rt[4000005];

elem combine(elem e1, elem e2) {
	if (e1.mx == e2.mx) {
		return elem(e1.mx, e1.sum + e2.sum, 0);
	}
	if (e1.mx > e2.mx) {
		return elem(e1.mx, e1.sum, 0);
	}
	return elem(e2.mx, e2.sum, 0);
}

int plusik;

void push(int v) {
	if (2*v < 2*N) {
		rt[2*v].lejzi += rt[v].lejzi;
		rt[2*v].mx += rt[v].lejzi;
	}
	if (2*v+1 < 2*N) {
		rt[2*v+1].lejzi += rt[v].lejzi;
		rt[2*v+1].mx += rt[v].lejzi;
	}
	rt[v].lejzi = 0;
}

void doit(int v, int x, int y, int l, int r) {
	if (l > r) return;
	push(v);
	if (l == x && r==y) {
		rt[v].mx += plusik;
		rt[v].lejzi += plusik;
		return;
	}
	int mid = (x + y)/2;
	doit(2*v, x, mid, l, min(r, mid));
	doit(2*v+1, mid+1,y,max(l, mid+1),r);
	rt[v] = combine(rt[2*v], rt[2*v+1]); 
}

void update(int a, int b, int c) {
	if (a == b) return;
	//cout << "UPDATE" << endl;
	//debug3(a,b,c);
	plusik = c;
	doit(1,0,N-1,a,b-1);
	
}

int get_value() {
	//debug(rt[1].sum);
	if (rt[1].mx + calosc == przedzi) return rt[1].sum;
	else return 0;
}


void rob_tree(){
	for (N=1; N<m; N<<=1);
	FOR(i,0,N) {
		if (i < m) {
			rt[N+i] = elem(0,leny[i],0); 
		} else {
			rt[N+i] = elem(0,0,0);
		}
	}
	FORD(i,N-1,1) {
		rt[i] = combine(rt[2*i], rt[2*i+1]);
		//cout << "i => " << rt[i].sum << endl;
	}
}


int rob(vector<PII> &v, int X) {
	// przesun
	int mini = v[0].st;
	//debug(X);
	FOR(i,0,v.size()) {
		//debug2(v[i].st, v[i].nd);
		
		mini = min(mini, v[i].st);
	}
	FOR(i,0,v.size()) {
		v[i] = {v[i].st - mini, v[i].nd-mini};
	}
	przedzi = v.size();

	// wez dlugosci
	VI values;
	vector<PII> ve;
	FOR(i,0,v.size()) {
		values.pb(v[i].st); values.pb(v[i].nd);
		ve.pb({v[i].st, i}); ve.pb({v[i].nd, i});
	}
	sort(all(values));
	values.erase(unique(all(values)), values.end());
	sort(all(ve));
	calosc = 0;

	leny.clear();
	int best = X-values.back();
	FOR(i,0,values.size() - 1) leny.pb(values[i+1]-values[i]);
	leny.pb(X-values.back());
	m = values.size();

	map<int, int> heh;
	FOR(i,0,values.size()) heh[values[i]] = i;
	
	rob_tree();

	FOR(i,0,v.size()) {
		int start = heh[v[i].st], meta = heh[v[i].nd];
		if (v[i].st == 0) {
			na[i] = 1;
			update(start, meta, 1);
		} else {
			na[i] = -1;
			update(0, start, 1);
			update(meta, m, 1);
		}
	}
	best = max(best, get_value());
	FOR(i,0,ve.size()) {
		if (ve[i].st == 0) continue;
		if (ve[i].st != ve[i-1].st) best = max(best, get_value());

		int kto = ve[i].nd;
		int start = heh[v[kto].st], meta = heh[v[kto].nd];
		if (na[kto] == 1) {
			update(start, meta, -2);
			calosc += 1;
		} else {
			update(start, meta, 2);
			calosc -= 1;
		}
		na[kto] *= -1;
	}
	best = max(best, get_value()); 
	//debug(best);
	return best;
}


int main() {
	make3(n, x, y);
	vector<PII> v, w;
	FOR(i,0,n) {
		make4(a, b, c, d);
		if (a > c) swap(a, c);
		if (b > d) swap(b, d);
		v.pb({a,c});
		w.pb({b,d});
	}
	printf("%lld\n", rob(v, x) * 1LL * rob(w, y));
}