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
#include <bits/stdc++.h>
using namespace std;
struct xy{
int xl,yl,xp,yp;
};
int n;
vector <vector <int> > wyn;
void rekur (vector <int> a){
if (a.size()==n){
    wyn.push_back(a);
}else{
    for (int i=0; i<4;i++){
        a.push_back(i);
        rekur(a);
        a.pop_back();
    }
}
}
int main(){
int x,y;
cin >> n >> x >> y;
int x1[n],y1[n],x2[n],y2[n];
for (int i=0; i<n;i++){
    cin >> x1[i]>>y1[i]>>x2[i]>>y2[i];
}
vector <int> a;
rekur (a);
long long wynik=0;
for (int j=0; j<wyn.size();j++){
    vector <vector <xy> > p;
    for (int i=0; i<wyn[j].size();i++){
        if (wyn[j][i]==0){
            xy tmp;
            tmp.xl=x1[i];
            tmp.yl=y1[i];
            tmp.xp=x2[i];
            tmp.yp=y2[i];
            vector <xy> pp;
            pp.push_back(tmp);
            p.push_back(pp);
        }
        if (wyn[j][i]==1){
            xy tmp1;
            tmp1.xl=x1[i];
            tmp1.yl=max(y2[i],y1[i]);
            tmp1.xp=x2[i];
            tmp1.yp=y;
            xy tmp2;
            tmp2.xl=x1[i];
            tmp2.yl=min(y2[i],y1[i]);
            tmp2.xp=x2[i];
            tmp2.yp=0;
            vector <xy> pp;
            pp.push_back(tmp1);
            pp.push_back(tmp2);
            p.push_back(pp);
        }
        if (wyn[j][i]==2){
            xy tmp1;
            tmp1.xl=max(x2[i],x1[i]);
            tmp1.yl=y1[i];
            tmp1.xp=x;
            tmp1.yp=y2[i];
            xy tmp2;
            tmp2.xl=0;
            tmp2.yl=y2[i];
            tmp2.xp=min(x2[i],x1[i]);
            tmp2.yp=y1[i];
            vector <xy> pp;
            pp.push_back(tmp1);
            pp.push_back(tmp2);
            p.push_back(pp);
        }
        if (wyn[j][i]==3){
            xy tmp1;
            tmp1.xp=min(x1[i],x2[i]);
            tmp1.yp=min(y1[i],y2[i]);
            tmp1.xl=0;
            tmp1.yl=0;
            xy tmp2;
            tmp2.xp=min(x1[i],x2[i]);
            tmp2.yp=max(y1[i],y2[i]);
            tmp2.xl=0;
            tmp2.yl=y;
            xy tmp3;
            tmp3.xp=max(x1[i],x2[i]);
            tmp3.yp=min(y1[i],y2[i]);
            tmp3.xl=x;
            tmp3.yl=0;
            xy tmp4;
            tmp4.xp=max(x1[i],x2[i]);
            tmp4.yp=max(y1[i],y2[i]);
            tmp4.xl=x;
            tmp4.yl=y;
            vector <xy> pp;
            pp.push_back(tmp1);
            pp.push_back(tmp2);
            pp.push_back(tmp3);
            pp.push_back(tmp4);
            p.push_back(pp);
        }
    }
    for (int i=0; i<n;i++){
        for (int j=0; j<p[i].size();j++){
            if (p[i][j].xl>p[i][j].xp){
                swap(p[i][j].xl,p[i][j].xp);
            }
            if (p[i][j].yl>p[i][j].yp){
                swap(p[i][j].yl,p[i][j].yp);
            }
        }
    }
    vector <xy> prost;
    xy tmp;
    tmp.xl=0;
    tmp.yl=0;
    tmp.yp=y;
    tmp.xp=x;
    prost.push_back(tmp);
    for (int i=0; i<n;i++){
        vector <xy> wsp;
        for (int j=0; j<p[i].size();j++){
            for (int k=0; k<prost.size();k++){
                int xl=max(prost[k].xl,p[i][j].xl);
                int xp=min(prost[k].xp,p[i][j].xp);
                int yl=max(prost[k].yl,p[i][j].yl);
                int yp=min(prost[k].yp,p[i][j].yp);
                if (xl<xp && yl<yp){
                    xy tmp;
                    tmp.xl=xl;
                    tmp.yl=yl;
                    tmp.xp=xp;
                    tmp.yp=yp;
                    wsp.push_back(tmp);
                }
            }
        }
        prost=wsp;
    }
    long long pole=0;
    for (int i=0; i<prost.size();i++){
        pole+=(long long)abs(((long long)prost[i].xp-(long long)prost[i].xl))*(long long)abs(((long long)prost[i].yp-(long long)prost[i].yl));
    }
    wynik=max(pole,wynik);
}
cout << wynik<<endl;
}