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
#include <iostream>
#include <vector>

using namespace std;

struct rect {
    int x1, y1, x2, y2;
};

int n, X, Y;
struct rect A[15];
long long maximum = 0;

void com(vector<struct rect>& V, vector<struct rect>& W1, vector<struct rect>& W2) {
    int lenv = V.size();
    int lenw = W1.size();
    
    for (int j=0; j<lenv; j++) {
        for (int k=0; k<lenw; k++) {
            struct rect tmp;
            tmp.x1 = max(V[j].x1, W1[k].x1);
            tmp.y1 = max(V[j].y1, W1[k].y1);
            tmp.x2 = min(V[j].x2, W1[k].x2);
            tmp.y2 = min(V[j].y2, W1[k].y2);
            
            if (tmp.x1 < tmp.x2 && tmp.y1 < tmp.y2) {
                W2.push_back(tmp);
            }
        }
    }
}

void rec(int i, vector<struct rect>& V) {
    int lenv = V.size();
    
    if (i == n) {
        long long area = 0;
        
        for (int j=0; j<lenv; j++) {
            area += (long long)(V[j].x2 - V[j].x1) * (long long)(V[j].y2 - V[j].y1);
        }
        
        if (area > maximum) {
            maximum = area;
        }
    } else {
        vector<struct rect> W1;
        vector<struct rect> W2;
        int lenw;
        
        // middle
        W1.push_back(A[i]);
        
        com(V, W1, W2);
        rec(i+1, W2);
        
        W1.clear();
        W2.clear();
        
        // horizontally
        struct rect tmp1 = {0, A[i].y1, A[i].x1, A[i].y2};
        W1.push_back(tmp1);
        struct rect tmp2 = {A[i].x2, A[i].y1, X, A[i].y2};
        W1.push_back(tmp2);

        com(V, W1, W2);
        rec(i+1, W2);
        
        W1.clear();
        W2.clear();
        
        // perpendicularly
        struct rect tmp3 = {A[i].x1, 0, A[i].x2, A[i].y1};
        W1.push_back(tmp3);
        struct rect tmp4 = {A[i].x1, A[i].y2, A[i].x2, Y};
        W1.push_back(tmp4);
        
        com(V, W1, W2);
        rec(i+1, W2);
        
        W1.clear();
        W2.clear();
        
        // rest
        struct rect tmp5 = {0, 0, A[i].x1, A[i].y1};
        W1.push_back(tmp5);
        struct rect tmp6 = {0, A[i].y2, A[i].x1, Y};
        W1.push_back(tmp6);
        struct rect tmp7 = {A[i].x2, A[i].y2, X, Y};
        W1.push_back(tmp7);
        struct rect tmp8 = {A[i].x2, 0, X, A[i].y1};
        W1.push_back(tmp8);
        
        com(V, W1, W2);
        rec(i+1, W2);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> X >> Y;
    
    for (int i=0; i<n; i++) {
        cin >> A[i].x1 >> A[i].y1 >> A[i].x2 >> A[i].y2;
        
        if (A[i].x1 > A[i].x2) {
            swap(A[i].x1, A[i].x2);
        }
        
        if (A[i].y1 > A[i].y2) {
            swap(A[i].y1, A[i].y2);
        }
    }
    
    vector<struct rect> V;
    
    struct rect tmp = {0, 0, X, Y};
    V.push_back(tmp);
    
    rec(0, V);
    
    cout << maximum << '\n';
    
    return 0;
}