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
// Artur Kraska, II UWr

#include <bits/stdc++.h>

#define forr(i, n)                  for(int i=0; i<n; i++)
#define FOREACH(iter, coll)         for(auto iter = coll.begin(); iter != coll.end(); ++iter)
#define FOREACHR(iter, coll)        for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter)
#define lbound(P,R,PRED)            ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;})
#define testy()                     int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests)
#define CLEAR(tab)                  memset(tab, 0, sizeof(tab))
#define CONTAIN(el, coll)           (coll.find(el) != coll.end())
#define FOR(i, a, b)                for(int i=a; i<=b; i++)
#define FORD(i, a, b)               for(int i=a; i>=b; i--)
#define MP                          make_pair
#define PB                          push_back
#define deb(X)                      X;

#define M 1000000007
#define INF 1000000007

using namespace std;

int n, x, y, d[2200007], S;
int wyn[1000007], gdzie[1000007], ile_mn[1000007];
vector <pair<pair<int, int>, pair<int, int>>> v;

struct prost
{
    int x1, x2, y1, y2;
    int pocz, kon;
};
prost tab[1000007];

void wkladaj(int nr, int ile)
{
    nr += S;
    while(nr > 0)
    {
        d[nr] += ile;
        nr >>= 1;
    }
}

int suma_lewo(int nr)
{
    nr += S;
    int res = 0;
    while(nr > 0)
    {
        if((nr&1) == 1)
            res += d[nr-1];
        nr >>= 1;
    }
    return res;
}

int suma_prawo(int nr)
{
    nr += S;
    int res = 0;
    while(nr > 0)
    {
        if((nr&1) == 0)
            res += d[nr+1];
        nr >>= 1;
    }
    return res;
}

int ostatni()
{
    int nr = 1;
    while(nr < S)
    {
        if(d[nr*2+1] > 0)
            nr = nr*2+1;
        else
            nr = nr*2;
    }
    return nr-S;
}

long long licz(vector <pair<pair<int, int>, pair<int, int>>> v)
{
    CLEAR(d);
    CLEAR(wyn);
    CLEAR(gdzie);
    CLEAR(ile_mn);

    sort(v.begin(), v.end());

    int czas = 1;
    FOREACH(it, v)
    {
        int stan = it->first.second;
        int nr = it->second.second;

        if(stan == 1)
        {
            gdzie[nr] = czas;
            czas++;
            it->second.first = czas;
        }
        else // stan == -1
        {
            it->second.first = -gdzie[nr];
        }
    }


 //   sort(v.begin(), v.end());


    int res = 0;
    //stack <pair<int, int>> stos;
    int last = 0;
    for(auto el : v)
    {
        int dl = el.first.first - last;
        last = el.first.first;
        int stan = el.first.second;
        int nr = el.second.second;


        int poz = ostatni();
        if(suma_lewo(poz) == ile_mn[poz] && suma_prawo(poz) == 0)
        {
//            cout << "   dodaje ->";
            wyn[poz] += dl;
        }
        else
        {
//            cout << "   ustawia nowy ->";
            wyn[poz] = dl;
        }
        ile_mn[poz] = suma_lewo(poz);

//        cout << " nowy wynik[" << poz << "] = " << wyn[poz]  << endl;

        res = max(res, wyn[poz]);


        if(stan == 1)
        {
//            cout << "doklada " << nr << " na pozycji " << last << " w czasie " << gdzie[nr] << ", dl = " << dl
//                << ", ile_mn = " << suma_lewo(gdzie[nr]) << endl;
            wkladaj(gdzie[nr], 1);

            wyn[gdzie[nr]] = 0;
        }
        else // stan == -1
        {
            wkladaj(gdzie[nr], -1);

//            cout << "zdejmuje " << nr << " na pozycji " << last << ", szczyt stosu na pozycji " << poz << ", dl = " << dl
//                << ", na lewo = " << suma_lewo(poz) << ", na prawo = " << suma_prawo(poz) << endl;

        }
    }

    return res;
}

int main()
{
    scanf("%d %d %d", &n, &x, &y);
    S = 1;
    while(S <= n+3)
        S *= 2;
    forr(i, n)
    {
        scanf("%d %d %d %d", &tab[i].x1, &tab[i].y1, &tab[i].x2, &tab[i].y2);
        if(tab[i].x1 > tab[i].x2)
            swap(tab[i].x1, tab[i].x2);
        if(tab[i].y1 > tab[i].y2)
            swap(tab[i].y1, tab[i].y2);
    }

    v.clear();
    forr(i, n)
    {
        v.PB(MP(MP(tab[i].x1, 1), MP(7, i+1)));
        v.PB(MP(MP(tab[i].x2, -1), MP(7, i+1)));
        tab[i].pocz = tab[i].x1;
        tab[i].kon = tab[i].x2;
    }
    v.PB(MP(MP(0, 1), MP(7, 0)));
    v.PB(MP(MP(x, -1), MP(7, 0)));
    long long res = licz(v);

    v.clear();
    forr(i, n)
    {
        v.PB(MP(MP(tab[i].y1, 1), MP(7, i+1)));
        v.PB(MP(MP(tab[i].y2, -1), MP(7, i+1)));
        tab[i].pocz = tab[i].y1;
        tab[i].kon = tab[i].y2;
    }
    v.PB(MP(MP(0, 1), MP(7, 0)));
    v.PB(MP(MP(y, -1), MP(7, 0)));
    res *= licz(v);

    printf("%lld\n", res);

    return 0;
}