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
210
#include <cstdio>
#include <cstdlib>
#include <list>
using namespace std;

int n, X, Y;
int x1, y1, x2, y2;

struct Rect {
	int x1;
	int y1;
	int x2;
	int y2;
	
	Rect() {
		
	}
	
	Rect(int _x1, int _y1, int _x2, int _y2) {
		x1 = _x1;
		y1 = _y1;
		x2 = _x2;
		y2 = _y2;
	}
	
	unsigned long long int area() {
		return abs(x2 - x1) * abs (y2 - y1);
	}
	
	Rect cross(Rect rect) {
		 // printf("cross (%d %d %d %d) (%d %d %d %d)\n", x1, y1, x2, y2, rect.x1, rect.y1, rect.x2, rect.y2);
		Rect r = rect;
		if (x1 >= rect.x2 || x2 <= rect.x1 || y1 >= rect.y2 || y2 <= rect.y1) {
			return Rect(0,0,0,0);
		}
		if (x1 < rect.x1) {
			if (x2 < rect.x2) {
				r.x1 = rect.x1;
				r.x2 = x2;
				// dx = x2 - rect.x1;
			} else {
				r.x1 = rect.x1;
				r.x2 = rect.x2;
				// dx = rect.x2 - rect.x1;
			}
		} else {
			if (rect.x2 < x2) {
				r.x1 = x1;
				r.x2 = rect.x2;
				// dx = rect.x2 - x1;
			} else {
				r.x1 = x1;
				r.x2 = x2;
				// dx = x2 - x1;
			}
		}
		
		if (y1 < rect.y1) {
			if (y2 < rect.y2) {
				r.y1 = rect.y1;
				r.y2 = y2;
				// dy = y2 - rect.y1;
			} else {
				r.y1 = rect.y1;
				r.y2 = rect.y2;
				// dy = rect.y2 - rect.y1;
			}
		} else {
			if (rect.y2 < y2) {
				r.y1 = y1;
				r.y2 = rect.y2;
				// dy = rect.y2 - y1;
			} else {
				r.y1 = y1;
				r.y2 = y2;
				// dy = y2 - y1;
			}
		}
		 // printf("result (%d %d %d %d) \n", r.x1, r.y1, r.x2, r.y2);
		return r;
	}
	
	Rect* t1() { // to samo
		Rect* rects = new Rect[1];
		rects[0] = Rect(x1,y1,x2,y2);
		return rects;
	}
	
	Rect* t2() { // poziomo
		Rect* rects = new Rect[2];
		rects[0] = Rect(0, y1, x1, y2);
		rects[1] = Rect(x2, y1, X, y2);
		return rects;
	}
	
	Rect* t3() { // pionowo
		Rect* rects = new Rect[2];
		rects[0] = Rect(x1, 0, x2, y1);
		rects[1] = Rect(x1, y2, x2, Y);
		return rects;
	}
	
	Rect* t4() {
		Rect* rects = new Rect[4];
		rects[0] = Rect(0, 0, x1, y1);
		rects[1] = Rect(x2, y2, X, Y);
		rects[2] = Rect(0, y2, x1, Y);
		rects[3] = Rect(x2, 0, X, y1);				
		return rects;
	}
};

struct Field {
	Rect* rects;
	int size;
	
	Field(Rect* _rects, int _size) {
		rects = _rects;
		size = _size;
	}
	
	unsigned long long int area() {
		unsigned long long int r = 0;
		for(int i=0; i<size;i++) {
			r += rects[i].area();
		}
		return r;
	}
	
	Field cross(Rect* toCross, int n) {
		Rect* temp = new Rect[100000];
		int new_size = 0;
		for(int i=0;i<size;i++) {
			for(int j=0;j<n;j++) {
				Rect r = rects[i].cross(toCross[j]);
				// printf("ij %d %d\n", i,j);
				// printf("%d %d %d %d\n", r.x1, r.y1, r.x2, r.y2);
				if (r.area() > 0) {
					temp[new_size++] = r; 			
				}
			}
		}
		
		Rect* result = new Rect[new_size];
		for(int i=0; i<new_size;i++) {
			result[i] = temp[i];
		}
		
		delete[] temp; 
		// printf("result new size %d\n", new_size);
		return Field(result, new_size);
	}
};

unsigned long long int CommonArea(Field f1, Field f2) {
	return 0;
}

int main () {
	scanf("%d %d %d", &n, &X, &Y);
	list<Field> fields;
	Rect* tmp = new Rect[1];
	tmp[0] = Rect(0,0,X,Y);
	fields.push_back(Field(tmp,1));
	for (int i=0; i<n; i++) {
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		
		if( x1 > x2) {
			int ttt = x2;
			x2 = x1;
			x1 = ttt;
		}
		if ( y1 > y2) {
			int ttt = y2;
			y2 = y1;
			y1 = ttt;
		}
		
		
		Rect r = Rect(x1, y1, x2, y2);
		list<Field> tmp2;
		for(list<Field>::iterator it = fields.begin(); it != fields.end(); it++) {
			// printf("cross1\n");
			Field c1 = (*it).cross(r.t1(), 1);
			// printf("cross2\n");
			Field c2 = (*it).cross(r.t2(), 2);
			// printf("cross3\n");
			Field c3 = (*it).cross(r.t3(), 2);		
			// printf("cross4\n");
			Field c4 = (*it).cross(r.t4(), 4);
			// printf("areas: c1 %llu c2 %llu c3 %llu c4 %llu\n\nma", c1.area(), c2.area(), c3.area(), c4.area());
			if(c1.area() > 0) tmp2.push_back(c1);
			if(c2.area() > 0) tmp2.push_back(c2);
			if(c3.area() > 0) tmp2.push_back(c3);
			if(c4.area() > 0) tmp2.push_back(c4);
		}
		
		fields = tmp2;
	}
	
	int max_area = 0;
	for(list<Field>::iterator it = fields.begin(); it != fields.end(); it++) {
		if( (*it).area() > max_area) max_area = (*it).area();
	}
	
	printf("%d\n", max_area);
	
	
	return 0;
}