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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#include <iostream>
#include <cstdint>
#include <vector>
#include <utility>
#include <algorithm>
#include <bitset>
#include <limits>


using namespace std;

class vertex {
public:
    int exc;
    int weight;
    int start;
    int stop;
    vertex():exc(-100),start(-100),stop(-100) {}
    vertex(int e,int st, int sp):exc(e),start(st),stop(sp) {}
};


typedef pair<uint32_t, uint32_t> point;

void cout_point(point p){
    cout<<p.first<<" "<<p.second<<endl;
}

class tree{
public:
    vector<vector<vertex>> data;
    vector <uint32_t> nodes;

    point root(){
        return make_pair(data.size()-1,0);
    }
//    point sen(){//wartownik
//        return make_pair(data.size()-1,1);
//    }


    void init(point p){
        V(p).exc=0;
        if (leaf(p)) {
            V(p).weight=nodes[p.second+1] - nodes[p.second];
            V(p).start=nodes[p.second];
            V(p).stop=nodes[p.second+1];
        }else{
            auto a=left(p);
            auto b=right(p);
            init(a);
//            cout_point(p);
            if (exist(b)){
                init(b);
                V(p).weight = V(a).weight+V(b).weight;
                V(p).start=V(a).start;
                V(p).stop=V(b).stop;
            }else{
                V(p).weight = V(a).weight;
                V(p).start=V(a).start;
                V(p).stop=V(a).stop;
            }
        }


    }



    vertex& V(point p){
        return data[p.first][p.second];
    }

    bool exist( const point p){
        return (p.first<data.size()  && p.second < data[p.first].size());
    }
    point left( const point p ){
        return make_pair( p.first-1, p.second*2 );
    }
    point right( const point p ){
        return make_pair( p.first-1, p.second*2+1 );
    }
    bool leaf(const point p){
        return p.first==0;
    }

    void zabron(uint32_t start, uint32_t stop){
        if (start==stop)
            return;
         zabron( root(), start, stop);
    }
    void pozwol(uint32_t start, uint32_t stop){
        if (start==stop)
            return;
         pozwol(root(), start, stop);
    }

    void zabron(point p, uint32_t start, uint32_t stop){
        auto a=left(p);
        auto b=right(p);
        if ( (start <= V(p).start) && (V(p).stop <=stop) ){ //wierzchołek drzewa w czałosci w przedziale
            V(p).exc++;
            V(p).weight=0;
        }else{
            if (start < V(a).stop)
                zabron(a,start,stop);
            if ( exist(b) && (V(b).start < stop)  )
                zabron(b,start,stop);
        }
        if (V(p).exc>0)
            V(p).weight=0;
        else if (!leaf(p)){
            if (exist(b)){
                V(p).weight = V(a).weight+V(b).weight;
            }else{
                V(p).weight = V(a).weight;
            }
        }else{
            V(p).weight=nodes[p.second+1] - nodes[p.second];
        }
    }

    void pozwol(point p, uint32_t start, uint32_t stop){
        auto a=left(p);
        auto b=right(p);
        if ( (start <= V(p).start) && (V(p).stop <=stop) ){ //wierzchołek drzewa w czałosci w przedziale
            V(p).exc--;
        }else{
            if (leaf(p))
                cout<<"wielblad"<<endl;
            if (start < V(a).stop)
                pozwol(a,start,stop);
            if ( exist(b) && (V(b).start < stop)  )
                pozwol(b,start,stop);
        }

        if (V(p).exc>0)
            V(p).weight=0;
        else if (!leaf(p)){
            if (exist(b)){
                V(p).weight = V(a).weight+V(b).weight;
            }else{
                V(p).weight = V(a).weight;
            }
        }else{
            V(p).weight=nodes[p.second+1] - nodes[p.second];
        }
    }


    tree(const vector<uint32_t>& nodes_){
        //nodes.reserve(nodes.size());

        /*nodes.push_back(0);
        for (auto x:w )
            nodes.push_back(x);
        nodes.push_back(X);
        auto last = unique(begin(nodes), end(nodes));
        nodes.erase(last, end(nodes));*/

        nodes = nodes_; //swap
        size_t siz = nodes.size()-1;
        data.push_back( vector<vertex>(siz,vertex()));
        while (siz>1){
            siz=(siz+1)/2;
            data.push_back( vector<vertex>(siz,vertex()));
        }
  //      data.back().push_back(vertex(0,X,X));
        init(root());
    }

    uint32_t surface () {
        return data.back()[0].weight;
    }

};




uint32_t max_segment( vector <pair<uint32_t,uint32_t>> pairs , uint32_t limit){

    vector<uint32_t> nodes;
    nodes.reserve(pairs.size()+3);
    for (auto p : pairs){
        nodes.push_back( p.first );
        nodes.push_back( p.second );
    }
    nodes.push_back(0);
    nodes.push_back(limit);
    sort (begin(nodes), end(nodes));
    auto last = unique(begin(nodes), end(nodes));
    nodes.erase(last, end(nodes));

    tree tr(nodes);
    for ( auto para : pairs ){
        tr.zabron(para.first,para.second);
    }
    sort (begin(pairs), end(pairs));

    vector <pair<uint32_t,uint32_t>> konce;
    copy(pairs.begin(), pairs.end(), back_inserter(konce));

    sort (begin(konce), end(konce),
          []( const pair<uint32_t,uint32_t> lhs, const pair<uint32_t,uint32_t> rhs )
               { return lhs.second<rhs.second|| (!(rhs.second<lhs.second) && lhs.first<rhs.first); }  );

    uint32_t maxx = tr.surface();

    auto it_pocz = begin(pairs);
    auto it_konc = begin(konce);
    for (auto nod = begin(nodes); nod!=end(nodes); nod++){
        while ( (it_pocz!=end(pairs)) &&  it_pocz->first== *nod  ){
            tr.pozwol(it_pocz->first,it_pocz->second);
            tr.zabron(0,it_pocz->first);
            tr.zabron(it_pocz->second, limit);
            it_pocz++;
        }
        while ( (it_konc!=end(konce)) &&  it_konc->second== *nod  ){
            tr.zabron(it_konc->first,it_konc->second);
            tr.pozwol(0,it_konc->first);
            tr.pozwol(it_konc->second, limit);
            it_konc++;
        }
        maxx = max(maxx,tr.surface());
    }

    return maxx;

}

int main(){
    //tradycja
    ios_base::sync_with_stdio(0);
    cin.tie(0);


//    vector  <int> tmp;
//    for (int i=0; i<10; i++){
//        tmp.push_back(i*i);
//    }
//    tree tr(tmp);


//    tr.zabron(tr.root(),1,16);
//    tr.zabron(tr.root(),4,36);
//    tr.zabron(tr.root(),49,64);

//    tr.pozwol(tr.root(),1,16);
//    tr.pozwol(tr.root(),4,36);
//    tr.pozwol(tr.root(),49,64);


    unsigned int n, X, Y;
    vector <pair<uint32_t,uint32_t>> xx,yy;
    cin>>n>>X>>Y;

    xx.reserve(2*n);
    yy.reserve(2*n);

    for (size_t i=0; i<n;i++){
        uint32_t x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        xx.push_back(minmax(x1,x2));
        yy.push_back(minmax(y1,y2));
    }

    cout<< max_segment(xx,X)*(uint64_t)max_segment(yy,Y)<<endl;


    return 0;



}