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
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

struct Event{
	int pos, copos;
	
	bool operator<(const Event& e)const{
		return pos<e.pos;
	}
};

struct ITree{
	int size, start, propperSize;
	int *cnt, *cellsize, *wnk;
	
	void init(int els){
		propperSize=els;
		start=1;
		while(start<els)
			start*=2;
		size=2*start;
		
		cnt = new int[size];
		cellsize = new int[size];
		wnk = new int[size];
		fill(cnt, cnt+size, 0);
		fill(cellsize, cellsize+size, 0);
		fill(wnk, wnk+size, 0);
	}
	void deinit(){
		delete []wnk;
		delete []cellsize;
		delete []cnt;
	}
	
	void setCellSize(int i, int s){
		cellsize[start+i]=wnk[start+i]=s;
	}
	void build(){
		for(int i=start-1;i>=1;i--)
			wnk[i]=wnk[2*i]+wnk[2*i+1];
	}
	
	int getFreeSum(){
		return wnk[1];
	}
	void _updateWnk(int v){
		if(v>=start)
			wnk[v] = (cnt[v]==0)?cellsize[v]:0;
		else
			wnk[v] = (cnt[v]==0)?(wnk[2*v]+wnk[2*v+1]):0;
	}
	void _mod(int a, int b, int val, int v, int rA, int rB){
		if(a<=rA && rB<=b){
			cnt[v]+=val;
			_updateWnk(v);
		}
		else{
			int rM=(rA+rB)/2;
			if(a<=rM)
				_mod(a, b, val, 2*v, rA, rM);
			if(rM<b)
				_mod(a, b, val, 2*v+1, rM+1, rB);
			_updateWnk(v);
		}
	}
	void mod(int a, int b, int val){
		if(a<=b)
			_mod(a, b, val, 1, 0, start-1);
	}
	
	void _comboMod(int a, int b, int midVal, int v, int rA, int rB){
		if(rB<a)
			cnt[v]-=midVal;
		else if(a<=rA && rB<=b)
			cnt[v]+=midVal;
		else if(b<rA && rB<propperSize)
			cnt[v]-=midVal;
		else{
			int rM=(rA+rB)/2;
			_comboMod(a, b, midVal, 2*v, rA, rM);
			if(rM+1<propperSize)
				_comboMod(a, b, midVal, 2*v+1, rM+1, rB);
		}
		
		_updateWnk(v);
	}
	void comboMod(int a, int b, int midVal){
		if(a<=b)
			_comboMod(a, b, midVal, 1, 0, start-1);
	}
};

struct Range{
	int before, after;
};

long long solveForOneDimension(const vector<pair<int,int>>&Segments, int X){
	int n = (int)Segments.size();
	
	//oznacz przedziały
	vector<int>ChangePos;
	for(auto seg : Segments){
		ChangePos.push_back(seg.first);
		ChangePos.push_back(seg.second);
	}
	ChangePos.push_back(0);
	ChangePos.push_back(X);
	sort(ChangePos.begin(), ChangePos.end());
	ChangePos.erase(unique(ChangePos.begin(), ChangePos.end()), ChangePos.end());
	
	auto rangeBefore = [&](int pos)->int{
		return lower_bound(ChangePos.begin(), ChangePos.end(), pos)-ChangePos.begin()-1;
	};
	auto rangeAfter = [&](int pos)->int{
		return lower_bound(ChangePos.begin(), ChangePos.end(), pos)-ChangePos.begin();
	};
	auto rangeBeforeAfter = [&](int pos)->Range{
		int ra = lower_bound(ChangePos.begin(), ChangePos.end(), pos)-ChangePos.begin();
		return {ra-1, ra};
	};
		
	//przygotuj event tab
	vector<Event>EvTab;
	for(auto seg : Segments){
		EvTab.push_back({ seg.first, seg.second });
		EvTab.push_back({ seg.second, seg.first });
	}
	sort(EvTab.begin(), EvTab.end());
	
	//ustaw stan początkowy
	ITree tree;
	tree.init(ChangePos.size()-1);
	for(int i=0;i<(int)ChangePos.size()-1;i++)
		tree.setCellSize(i, ChangePos[i+1]-ChangePos[i]);
	tree.build();
	
	for(auto seg : Segments){
		if(seg.first==0)
			tree.mod(rangeAfter(seg.second), rangeBefore(X), 1);
		else
			tree.mod(rangeAfter(seg.first), rangeBefore(seg.second), 1);
	}
	
	//zamiataj (jeśli można to tak nazwać)
	int it=0;
	while(EvTab[it].pos==0)
		it++;
	int best=max(0, tree.getFreeSum());
	while(it<2*n){
		int pos=EvTab[it].pos;
		while(it<2*n && EvTab[it].pos==pos){
			Event ev = EvTab[it++];
			Range Pos = rangeBeforeAfter(ev.pos);
			Range Copos = rangeBeforeAfter(ev.copos);
			if(ev.pos < ev.copos)
				tree.comboMod(Pos.after, Copos.before, -1);
			else
				tree.comboMod(Copos.after, Pos.before, 1);
		}
		
		best=max(best, tree.getFreeSum());
	}
	
	tree.deinit();
	return best;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, X, Y;
	cin >> n >> X >> Y;
	
	vector<pair<int,int>>Xtab,Ytab;
	for(int i=0;i<n;i++){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		Xtab.push_back({min(x1,x2), max(x1,x2)});
		Ytab.push_back({min(y1,y2), max(y1,y2)});
	}
	
	long long res1 = solveForOneDimension(Xtab, X);
	long long res2 = solveForOneDimension(Ytab, Y);
	cout << res1*res2 << "\n";
	
	return 0;
}