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

int n, X, Y, xans, yans;
vector <int> hor, ver;
map <pair <int, int>, int> horM, verM;
set <int> H, V;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> X >> Y;
	for (int i = 0, x1, y1, x2, y2; i < n; i++)
	{
		cin >> x1 >> y1 >> x2 >> y2;
		
		horM[make_pair(min(x1, x2), max(x1, x2))] = 1;
		verM[make_pair(min(y1, y2), max(y1, y2))] = 1;
		if (!H.count(x1))
		{
			hor.push_back(x1);
			H.insert(x1);
		}
		if (!H.count(x2))
		{
			hor.push_back(x2);
			H.insert(x2);
		}
		if (!V.count(y1))
		{
			ver.push_back(y1);
			V.insert(y1);
		}
		if (!V.count(y2))
		{
			ver.push_back(y2);
			V.insert(y2);
		}
	}
	
	sort(hor.begin(), hor.end());
	sort(ver.begin(), ver.end());
	
	xans = hor[0] + X - hor.back();
	for (int i = 1; i < hor.size(); i++)
	{
		xans = max(xans, hor[i] - hor[i-1]);
		if (horM.count(make_pair(hor[i], hor[i-1])))
		{
			if (i+1 < hor.size())
			{
				if (i-2 >= 0)
					xans = max(xans, hor[i+1]-hor[i]+hor[i-1]-hor[i-2]);
				else
					xans = max(xans, hor[i+1]-hor[i]+hor[i-1]);
			}
			else
			{
				if (i-2 >= 0)
					xans = max(xans, X-hor[i]+hor[i-1]-hor[i-2]);
				else
					xans = max(xans, X-hor[i]+hor[i-1]);
			}
		}
	}
	yans = ver[0] + Y - ver.back();
	for (int i = 1; i < ver.size(); i++)
	{
		yans = max(yans, ver[i] - ver[i-1]);	
		if (verM.count(make_pair(ver[i], ver[i-1])))
		{
			if (i+1 < ver.size())
			{
				if (i-2 >= 0)
					yans = max(yans, ver[i+1]-ver[i]+ver[i-1]-ver[i-2]);
				else
					yans = max(yans, ver[i+1]-ver[i]+ver[i-1]);
			}
			else
			{
				if (i-2 >= 0)
					yans = max(yans, X-ver[i]+ver[i-1]-ver[i-2]);
				else
					yans = max(yans, X-ver[i]+ver[i-1]);
			}
		}
	}	
	
	cout << (long long) xans * (long long) yans << '\n';
}