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

struct Node {
    int max_value;
    int many_max;
    int prop_value;
 
    Node (int  _max_value, int _prop_value, int _many_max) {
        max_value = _max_value;
        prop_value = _prop_value;
        many_max = _many_max;
    }
};
 
struct Aint {
    int n;
    int target;
    vector<Node> tree;
 
    Aint(int _n, int _target) {
        n = _n;
        target = _target;
        tree = vector<Node> (4 * (n + 1), Node(0, 0, 0));
    }
 
    void propagate(int idx) {
        if (tree[idx].prop_value == 0)
            return;
        tree[idx].max_value += tree[idx].prop_value;
        for (int d = 0; d < 2; d += 1)
            if (2 * idx + d < (int) tree.size())
                tree[2 * idx + d].prop_value += tree[idx].prop_value;
        tree[idx].prop_value = 0;
    };
 
    int countGood() {
        if (tree[1].max_value == target)
            return tree[1].many_max;
        return 0;
    }
 
    void add(int node, int st, int dr, int left, int right, int delta) {
        if (st >= left and dr <= right) {
            tree[node].prop_value += delta;
            propagate(node);
            return;
        }
        
        int mid = (st + dr) / 2;
        propagate(node);
 
        if (left <= mid)
            add(2 * node, st, mid, left, right, delta);
        if (right > mid)
            add(2 * node + 1, mid + 1, dr, left, right, delta);
 
        propagate(2 * node);
        propagate(2 * node + 1);

        tree[node].max_value = max(tree[2 * node].max_value, tree[2 * node + 1].max_value);
        tree[node].many_max = (tree[2 * node].max_value == tree[node].max_value) * tree[2 * node].many_max + 
                              (tree[2 * node + 1].max_value == tree[node].max_value) * tree[2 * node + 1].many_max;
    }
 
    void init(int node, int st, int dr, int poz, int value, int weight) {
        if (st == dr) {
            tree[node].max_value = value;
            tree[node].many_max = weight;
            return;
        }
        
        int mid = (st + dr) / 2;
        if (poz <= mid)
            init(2 * node, st, mid, poz, value, weight);
        if (poz > mid)
            init(2 * node + 1, mid + 1, dr, poz, value, weight);
        
        tree[node].max_value = max(tree[2 * node].max_value, tree[2 * node + 1].max_value);
        tree[node].many_max = (tree[2 * node].max_value == tree[node].max_value) * tree[2 * node].many_max + 
                              (tree[2 * node + 1].max_value == tree[node].max_value) * tree[2 * node + 1].many_max;
    }
    
    int get(int node, int st, int dr, int poz) {
        propagate(node);
        if (st == dr)
            return tree[node].max_value;
        int mid = (st + dr) / 2;
        if (poz <= mid)
            return get(2 * node, st, mid, poz);
        return get(2 * node + 1, mid + 1, dr, poz);
    }
};

int solve(vector<pair<int, int>> segments, int m) {
    int n = segments.size();

    vector<int> v;
    v.push_back(0);

    for (const auto& segment : segments) {
        v.push_back(segment.first);
        v.push_back(segment.second);
    }

    v.push_back(m);
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    
    vector<pair<int, int>> interesting;

    for (int i = 0; i < int(v.size()) - 1; i += 1) {
        interesting.push_back(make_pair(v[i], v[i + 1] - v[i]));
    }

    sort(interesting.begin(), interesting.end());
    interesting.resize(unique(interesting.begin(), interesting.end()) - interesting.begin());
        
    auto norm = [&] (int x) -> int {
        return lower_bound(interesting.begin(), interesting.end(), make_pair(x, -1)) - interesting.begin();
    };

    for (auto& segment : segments) {
        segment.first = norm(segment.first);
        segment.second = norm(segment.second);
    }

    int k = interesting.size();

    vector<vector<int>> open(k + 1), closed(k + 1);

    for (int i = 0; i < n; i += 1) {
        open[segments[i].first].push_back(i);
        closed[segments[i].second - 1].push_back(i);
    }
    
    Aint tree(k, n);
    
    for (int i = 0; i < k; i += 1)
        tree.init(1, 0, k - 1, i, 0, interesting[i].second);

    for (const auto& segment : segments) {
        if (segment.first > 0) {
            if (segment.first - 1 >= 0)
                tree.add(1, 0, k - 1, 0, segment.first - 1, 1);
            tree.add(1, 0, k - 1, segment.second, k - 1, 1);
        } else {
            tree.add(1, 0, k - 1, segment.first, segment.second - 1, 1);
        }
    }

    int ans = tree.countGood();
        for (int old_stuff : closed[0]) {
            auto segment = segments[old_stuff];
            tree.add(1, 0, k - 1, segment.first, segment.second - 1, -1);

            if (segment.first - 1 >= 0)
                tree.add(1, 0, k - 1, 0, segment.first - 1, 1);
            tree.add(1, 0, k - 1, segment.second , k - 1, 1);
        }    


    for (int i = 1; i < k; i += 1) {
        for (int new_stuff : open[i]) {
            auto segment = segments[new_stuff];
            if (segment.first - 1 >= 0)
                tree.add(1, 0, k - 1, 0, segment.first - 1, -1);
            tree.add(1, 0, k - 1, segment.second, k - 1, -1);
            tree.add(1, 0, k - 1, segment.first, segment.second - 1, 1);
        }
            
        ans = max(ans, tree.countGood());

        for (int old_stuff : closed[i]) {
            auto segment = segments[old_stuff];
            tree.add(1, 0, k - 1, segment.first, segment.second - 1, -1);

            if (segment.first - 1 >= 0)
                tree.add(1, 0, k - 1, 0, segment.first - 1, 1);
            tree.add(1, 0, k - 1, segment.second , k - 1, 1);
        }
    }

    return ans;
}

int main() {
    //ifstream cin("ter.in");
    //ofstream cout("ter.out");

    ios_base :: sync_with_stdio(false);
    int n, X, Y; cin >> n >> X >> Y;
    
    vector<pair<int, int>> x, y;

    for (int i = 0; i < n; i += 1) {
        int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
        x.push_back(make_pair(min(x1, x2), max(x1, x2)));
        y.push_back(make_pair(min(y1, y2), max(y1, y2)));
    }

    int x_solution = solve(x, X);
    int y_solution = solve(y, Y);

    int64_t ans = 1LL * x_solution * y_solution;
    cout << ans << "\n";
}