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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#include<iostream>
#include<vector>
#include<list>
#include<cassert>
#include <algorithm>
#include <memory>
#include <tuple>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <iostream>
#include <string>
#include <math.h>    

using namespace std;

unsigned short CountOnes(unsigned long long m)
{
	unsigned short counter = 0;

	for (int i = 0; i < 64; ++i)
	{
		if ((unsigned long long)1 << i & m)
		{
			++counter;

		}
	}
	return counter;
}


class GrandArea
{
public:
	GrandArea(unsigned long long x, unsigned long long y) : X(x), Y(y)
	{
		
		Area = X * Y;
		Data.resize(Area / 64 + 1);
		std::fill(Data.begin(), Data.end(), 0);
	
	};

	unsigned long long X, Y, Area, Ones = 0;
	vector<unsigned long long> Data;

	void FillOnes()
	{
		std::fill(Data.begin(), Data.end(), (unsigned long long)-1);
	}


	// AddPoint
	void AddPoint(unsigned long long x, unsigned long long y)
	{
		unsigned long long index = y * X + x;
		Data[index / 64] |= ((unsigned long long)1 << index % 64);
		++Ones;
	}

	//AddArea
	void AddArea1(unsigned long long x1, unsigned long long y1, unsigned long long x2, unsigned long long y2)
	{
		for (unsigned long long i = y1; i < y2; ++i)
		{


			for (unsigned long long j = x1; j < x2; ++j)
			{
				AddPoint(i, j);
			}
		}
	}

	void AddArea2(unsigned long long x1, unsigned long long y1, unsigned long long x2, unsigned long long y2)
	{
		AddArea1(0, y1, x1, y2);
		AddArea1(x2, y1, X, y2);
	}

	void AddArea3(unsigned long long x1, unsigned long long y1, unsigned long long x2, unsigned long long y2)
	{
		AddArea1(x1, 0, x2, y1);
		AddArea1(x1, y2, x2, Y);
	}

	void AddArea4(unsigned long long x1, unsigned long long y1, unsigned long long x2, unsigned long long y2)
	{
		AddArea1(0, 0, x1, y1);
		AddArea1(x2, 0, X, y1);
		AddArea1(0, y2, x1, Y);
		AddArea1(x2, y2, X, Y);
	}

	// GetOnes
	unsigned long long GetOnes()
	{
		unsigned long long res = 0;

		for (auto& d : Data)
		{
			res += CountOnes(d);
		}

		return res;
	}
	
	// GetCommonOnes
	unsigned long long GetCommonOnes(GrandArea& ga)
	{
		unsigned long long res = 0;

		for (unsigned long long i = 0; i < Data.size(); ++i)
		{
			res += CountOnes(Data[i] & ga.Data[i]);
		}

		return res;
	}

	void Combine(GrandArea& ga)
	{
		for (unsigned long long i = 0; i < Data.size(); ++i)
		{
			Data[i] &= ga.Data[i];
		}
	}

	// GetCommonGrandArea(GrandArea) 
	GrandArea* GetCommonGrandArea(GrandArea& ga)
	{
		GrandArea* newGa  = new GrandArea(X,Y);

		for (unsigned long long i = 0; i < Data.size(); ++i)
		{
			unsigned long long comm = Data[i] & ga.Data[i];
			newGa->Data[i] = comm;
			newGa->Ones += CountOnes(comm);
		}

		return newGa;
	}
};


int main()
{
	unsigned long long N, X, Y;

	cin >> N >> X >> Y;

	GrandArea RES(X, Y);
	RES.FillOnes();

	for (unsigned long long i = 0; i < N; ++i)
	{
		unsigned long long x1, y1, x2, y2 = 0;
		cin >> x1 >> y1 >> x2 >> y2;

		if (x1 > x2)
		{
			unsigned long long tmp = x1;
			x1 = x2;
			x2 = tmp;
		}
		if (y1 > y2)
		{
			unsigned long long tmp = y1;
			y1 = y2;
			y2 = tmp;
		}

		unsigned long long biggestCommonOnes = 0;
		unsigned short index = 0;

		GrandArea ga1(X, Y);
		ga1.AddArea1(x1, y1, x2, y2);
		unsigned long long comm1 = RES.GetCommonOnes(ga1);
		if (comm1 > biggestCommonOnes)
		{
			index = 1;
			biggestCommonOnes = comm1;
		}

		GrandArea ga2(X, Y);
		ga2.AddArea2(x1, y1, x2, y2);
		unsigned long long comm2 = RES.GetCommonOnes(ga2);
		if (comm2 > biggestCommonOnes)
		{
			index = 2;
			biggestCommonOnes = comm2;
		}

		GrandArea ga3(X, Y);
		ga3.AddArea3(x1, y1, x2, y2);
		unsigned long long comm3 = RES.GetCommonOnes(ga3);
		if (comm3 > biggestCommonOnes)
		{
			index = 3;
			biggestCommonOnes = comm3;
		}

		GrandArea ga4(X, Y);
		ga4.AddArea4(x1, y1, x2, y2);
		unsigned long long comm4 = RES.GetCommonOnes(ga4);
		if (comm4 > biggestCommonOnes)
		{
			index = 4;
			biggestCommonOnes = comm4;
		}

		switch (index)
		{
		case 1:
			RES.Combine(ga1);
			break;

		case 2:
			RES.Combine(ga2);
			break;

		case 3:
			RES.Combine(ga3);
			break;

		case 4:
			RES.Combine(ga4);
			break;
		default:
			cout << 0;
			return 0;
			break;
		}

	}

	cout << RES.GetOnes();

	return 0;
}