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
#include <bits/stdc++.h>
#ifdef LOC
#include "debuglib.h"
#else
#define deb(...)
#define DBP(...)
#endif
using namespace std;
using   ll         = long long;
using   Vi         = vector<int>;
using   Pii        = pair<int, int>;
#define pb           push_back
#define mp           make_pair
#define x            first
#define y            second
#define rep(i, b, e) for (int i = (b); i < (e); i++)
#define each(a, x)   for (auto& a : (x))
#define all(x)       (x).begin(), (x).end()
#define sz(x)        int((x).size())

//#define GEN_TEST

mt19937_64 rnd(1337);
int r(int b, int e) { return int(b + rnd() % (e-b+1)); }

struct SegTree {
	Vi tMax, tCnt, tAdd;
	int len;

	SegTree(Vi& orig) {
		for (len = 1; len < sz(orig); len *= 2);
		tMax.resize(len*2);
		tCnt.resize(len*2);
		tAdd.resize(len*2);

		rep(i, 0, sz(orig)-1) {
			tCnt[i+len] = orig[i+1] - orig[i];
		}

		for (int i = len-1; i > 0; i--) {
			tCnt[i] = tCnt[i*2] + tCnt[i*2+1];
		}
	}

	int getMax()    const { return tMax[1]; }
	int getMaxCnt() const { return tCnt[1]; }

	void add(int vb, int ve, int val, int i = 1, int b = 0, int e = -1) {
		if (e < 0) e = len;
		if (vb >= e || b >= ve) return;

		if (b >= vb && e <= ve) {
			tMax[i] += val;
			tAdd[i] += val;
			return;
		}

		int m = (b+e) / 2;
		add(vb, ve, val, i*2, b, m);
		add(vb, ve, val, i*2+1, m, e);

		tMax[i] = max(tMax[i*2], tMax[i*2+1]);
		tCnt[i] = 0;
		if (tMax[i] == tMax[i*2]) tCnt[i] += tCnt[i*2];
		if (tMax[i] == tMax[i*2+1]) tCnt[i] += tCnt[i*2+1];
		tMax[i] += tAdd[i];
	}
};

Vi compressVec(vector<int*>& vec) {
	sort(all(vec), [](int* l, int* r) { return *l < *r; });
	Vi old;
	each(e, vec) {
		if (old.empty() || old.back() != *e) old.pb(*e);
		*e = sz(old)-1;
	}
	return old;
}

int solve(vector<Pii>& inters, int len) {
	vector<int*> toCompress;
	int zero = 0;
	toCompress.pb(&zero);
	toCompress.pb(&len);

	each(e, inters) {
		if (e.x > e.y) swap(e.x, e.y);
		toCompress.pb(&e.x);
		toCompress.pb(&e.y);
	}

	Vi orig = compressVec(toCompress);
	SegTree tree(orig);
	vector<vector<Pii>> events(sz(orig));

	rep(i, 0, sz(inters)) {
		auto& e = inters[i];
		tree.add(0, tree.len, 1);
		tree.add(e.x, e.y, -1);
		events[e.x].pb({i, 1});
		events[e.y].pb({i, -1});
	}

	int ans = 0;

	rep(i, 0, sz(orig)) {
		each(evt, events[i]) {
			auto& e = inters[evt.x];
			tree.add(0, tree.len, -evt.y);
			tree.add(e.x, e.y, evt.y*2);
		}

		if (tree.getMax() == sz(inters)) {
			ans = max(ans, tree.getMaxCnt());
		}
	}

	return ans;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cout << fixed << setprecision(18);

	int n, X, Y;

#ifdef GEN_TEST
	n = 5e5;
	X = 1e9;
	Y = 1e9;
#else
	cin >> n >> X >> Y;
#endif

	vector<Pii> intersX(n), intersY(n);

	rep(i, 0, n) {
		int x1, y1, x2, y2;
#ifdef GEN_TEST
		x1 = r(0, X-1); y1 = r(0, Y-1);
		x2 = r(0, X-1); y2 = r(0, Y-1);
#else
		cin >> x1 >> y1 >> x2 >> y2;
#endif
		intersX[i] = {x1, x2};
		intersY[i] = {y1, y2};
	}

	ll ans = ll(solve(intersX, X)) * solve(intersY, Y);
	cout << ans << '\n';
	return 0;
}