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
//
//  main.cpp
//  ter
//
//  Created by Mikołaj Korulczyk on 12/12/2019.
//  Copyright © 2019 Mikołaj Korulczyk. All rights reserved.
//

#include <bits/stdc++.h>

using namespace std;

int tab[1001][1001];

int n, X, Y;
int x_1, x_2;
int y_1, y_2;

struct coordinates {
    int a1;
    int b1;
    int a2;
    int b2;
};

coordinates crds[1001];

int current_max;
int best_res;

//inner X
//inner Y
void mode1(int x1, int y1, int x2, int y2, int val) {
    int X1 = min(x1, x2);
    int X2 = max(x1, x2);
    int Y1 = min(y1, y2);
    int Y2 = max(y1, y2);
    
    for(int i = X1; i < X2; i++) {
        for(int j = Y1; j < Y2; j++) {
            tab[i][j] += val;
            current_max = max(current_max, tab[i][j]);
            //cout << i << " " << j << endl;
        }
    }
    
}

//outerX
//outerY
void mode2(int x1, int y1, int x2, int y2, int val) {
    int X1 = min(x1, x2);
    int X2 = max(x1, x2);
    int Y1 = min(y1, y2);
    int Y2 = max(y1, y2);
    
    for(int i = X2; i%X != X1; i++) {
        for(int j = Y2; j%Y != Y1; j++) {
            tab[i%X][j%Y] += val;
            current_max = max(current_max, tab[i%X][j%Y]);
        }
    }
    
}

//innerX
//outerY
void mode3(int x1, int y1, int x2, int y2, int val) {
    int X1 = min(x1, x2);
    int X2 = max(x1, x2);
    int Y1 = min(y1, y2);
    int Y2 = max(y1, y2);
    
    for(int i = X1; i < X2; i++) {
        for(int j = Y2; j%Y != Y1; j++) {
            tab[i][j%Y] += val;
            current_max = max(current_max, tab[i][j%Y]);
            //cout << i%X << " " << j%Y << endl;
        }
    }
    
}

//outerX
//innerY
void mode4(int x1, int y1, int x2, int y2, int val) {
    int X1 = min(x1, x2);
    int X2 = max(x1, x2);
    int Y1 = min(y1, y2);
    int Y2 = max(y1, y2);
    
    for(int i = X2; i%X != X1; i++) {
        for(int j = Y1; j < Y2; j++) {
            tab[i%X][j] += val;
            current_max = max(current_max, tab[i%X][j]);
        }
    }
    
}

void rec(int d) {
    if(d) {
        mode1(crds[d].a1, crds[d].b1, crds[d].a2, crds[d].b2, 1);
        rec(d-1);
        mode1(crds[d].a1, crds[d].b1, crds[d].a2, crds[d].b2, -1);
        
        mode2(crds[d].a1, crds[d].b1, crds[d].a2, crds[d].b2, 1);
        rec(d-1);
        mode2(crds[d].a1, crds[d].b1, crds[d].a2, crds[d].b2, -1);
        
        mode3(crds[d].a1, crds[d].b1, crds[d].a2, crds[d].b2, 1);
        rec(d-1);
        mode3(crds[d].a1, crds[d].b1, crds[d].a2, crds[d].b2, -1);
        
        mode4(crds[d].a1, crds[d].b1, crds[d].a2, crds[d].b2, 1);
        rec(d-1);
        mode4(crds[d].a1, crds[d].b1, crds[d].a2, crds[d].b2, -1);
    } else {
        int sum = 0;
        for(int i = 0; i < X; i++) {
            for(int j = 0; j < Y; j++) {
                //cout << tab[i][j] << " ";
                if(tab[i][j] == n) {
                    sum += 1;
                }
            }
           //cout << endl;
        }
        best_res = max(best_res, sum);
        //cout << "----------" << endl;
    }
}

int main() {
    //cin >> n >> X >> Y;
    scanf("%i%i%i", &n, &X, &Y);
    
    for(int i = 1; i <= n; i++) {
        //cin >> crds[i].a1 >> crds[i].b1 >> crds[i].a2 >> crds[i].b2;
        scanf("%i%i%i%i", &crds[i].a1, &crds[i].b1, &crds[i].a2, &crds[i].b2);
    }
    
    
    //for(int i = 1; i <= n; i++) {
    //    cout << crds[i].a1 << " " << crds[i].b1 << " " << crds[i].a2 << " " << crds[i].b2 << endl;
    //}
    //cout << endl;
    
    best_res = -1;
    current_max = -1;
    rec(n);
    
    //cout << best_res << endl;
    printf("%i\n", best_res);
    return 0;
}