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
// TEMPLATE START

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll, ll> pii;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

const int MOD = 1000000007;
const int INF = 2147483647;
const ll LINF = 1e18;
const ld PI = 4*atan((ld)1);

#define rep(i,a,b) for (int i=(a); i<(b); ++i)
#define repd(i,a,b) for (int i=((int)(a)); i>=(b); --i)
#define trav(a,x)  for (auto& a : x)
#define all(u) begin(u), end(u)
#define sz(x) (int)x.size()
#define xsort(v, m) rep(i, 0, v.size()) m[i] = i; sort(all(m), [=](int i, int j) {return v[i] < v[j];}); sort(v);

#define pb push_back
#define X first
#define Y second

#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PREC(n) cout<<fixed<<setprecision(n);

#define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl;
#define dbv(v) cerr << __LINE__ << ": " << #v << "\n" << v.size() << "\n" << v << "\n";


template <class T, class S> ostream& operator << (ostream& os, const pair<T, S>& p) {
    os << p.X << " " << p.Y;
    return os;
}

template <class T, class S> istream& operator >> (istream& is,  pair<T, S>& p) {
    is >> p.X >> p.Y;
    return is;
}

template <class T> ostream& operator << (ostream& os, const vector<T>& v) {
    rep(i, 0, v.size())
        os << v[i] << " \n" [i == v.size() - 1];
    return os;
}

template <class T> istream& operator >> (istream& is,  vector<T>& v) {
    rep(i, 0, v.size())
        is >> v[i];
    return is;
}


// TEMPLATE END


// SOLUTION START

const int OUT = 0, IN = 1, HOR = 2, VER = 3;

void swap(int& x, int& y) {
    int tmp = x;
    x = y;
    y = tmp;
}

long long inter(pair<pii, pii>& r1, pair<pii, pii>& r2, pair<pii, pii>& p) {
    p.X.X = max(r1.X.X, r2.X.X);
    p.X.Y = max(r1.X.Y, r2.X.Y);
    p.Y.X = min(r1.Y.X, r2.Y.X);
    p.Y.Y = min(r1.Y.Y, r2.Y.Y);
    return p.X.X < p.Y.X && p.X.Y < p.Y.Y ? (p.Y.X - p.X.X) * (p.Y.Y - p.X.Y) : 0;
}

long long rec(vector<vector<vector<pair<pii, pii>>>> &v, vector<pair<pii, pii>> cur, int pos, int which, long long& best) {
    vector<pair<pii, pii>> ne;
    long long r = 0;
    for(auto& rect1 : v[pos][which]) {
        for(auto& rect2 : cur) {
            pair<pii, pii> p;
            long long k = inter(rect1, rect2, p);
            if(k > 0) {
                r += k;
                ne.pb(p);
            }
        }
    }
    if(r > best) {
        if(pos == v.size() - 1) {
            best = r;
            return r;
        }
        else {
            long long c = 0;
            rep(i, 0, 4)
                c = max(c, rec(v, ne, pos + 1, i, best));
            return c;
        }
    }
    else
        return 0;
}

long long solve(vector<vector<vector<pair<pii, pii>>>> &v, ll x, ll y) {
    long long r = 1;
    vector<pair<pii, pii>> u({{{0, 0}, {x, y}}});
    for (int i = 0; i < 4; i++)
        r = max(r, rec(v, u, 0, i, r));
    return r;

}

int main() {
    FAST_IO
    ll n, x, y, x1, x2, y1, y2;
    cin >> n >> x >> y;
    vector<vector<vector<pair<pii, pii>>>> v(n, vector<vector<pair<pii, pii>>>(4));
    rep(i, 0, n) {
        cin >> x1 >> y1 >> x2 >> y2;
        if(x1 > x2)
            swap(x1, x2);
        if(y1 > y2)
            swap(y1, y2);
        if(x1 != 0 || y1 != 0)
            v[i][OUT].pb({{0, 0}, {x1, y1}});
        v[i][OUT].pb({{0, y2}, {x1, y}});
        v[i][OUT].pb({{x2, 0}, {x, y1}});
        v[i][OUT].pb({{x2, y2}, {x, y}});
        v[i][IN].pb({{x1, y1}, {x2, y2}});
        if(y1 != 0)
            v[i][HOR].pb({{x1, 0}, {x2, y1}});
        v[i][HOR].pb({{x1, y2}, {x2, y}});
        if(x1 != 0)
            v[i][VER].pb({{0, y1}, {x1, y2}});
        v[i][VER].pb({{x2, y1}, {x, y2}});

    }
    cout << solve(v, x, y) << "\n";
    return 0;
}

// SOLUTION END