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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include<cstdio>
#include<set>
#include<utility>
#include<vector>
#include<map>
#include<iostream>

int p1 = 1000001531;
int p2 = 1000003051;

int n, X, Y;
typedef std::pair<int, int> hash;
typedef std::pair<int, int> point;
typedef std::pair<point, point> rect;
typedef std::map<int, int> mii;
typedef std::set<int> si;
typedef std::map<hash, int> mhi;
std::vector<rect> rects;
std::set<int> Xs;
std::set<int> Ys;
mhi M;

int max(int a, int b) {
  return a >= b ? a : b;
}

int min(int a, int b) {
  return a <= b ? a : b;
}

hash init_hash(int n) {
  return std::make_pair(n, n);
}
hash zero_hash = init_hash(0);

struct node {
  hash h;
  int low;
  int high;
  node * left;
  node * right;
};

node * build_tree(std::vector<int> * x, int i, int j) {
  //printf("%d %d\n", i, j);
  node * n = new node;
  n->h = zero_hash;
  n->low = (*x)[i];
  n->high = (*x)[j];
  n->left = NULL;
  n->right = NULL;

  if (i + 1 != j) {
    node * left = build_tree(x, i, (j + i) / 2);
    node * right = build_tree(x, (j + i) / 2, j);
    n->left = left;
    n->right = right;
  }
  return n;
}

node * build_tree(std::set<int> & x) {
  std::vector<int> v = std::vector<int>(x.begin(), x.end());
  return build_tree(&v, 0, x.size() - 1);
}

void input() {
  scanf("%d %d %d", &n, &X, &Y);
  Xs.insert(0);
  Xs.insert(X);
  Ys.insert(0);
  Ys.insert(Y);
  int x1, y1, x2, y2;
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    point p1 = std::make_pair(x1, y1);
    point p2 = std::make_pair(x2, y2);
    rects.push_back(std::make_pair(p1, p2));
    Xs.insert(x1);
    Xs.insert(x2);
    Ys.insert(y1);
    Ys.insert(y2);
  }
}

void print(point p) {
  printf("(%d %d)", p.first, p.second);
}

void print(rect r) {
  printf("(");
  print(r.first);
  printf(",");
  print(r.second);
  printf(")");
}

void print(std::vector<rect> & v) {
  for (std::vector<rect>::iterator i = v.begin(); i != v.end(); i++) {
    print(*i);
    printf("\n");
  }
}

void print(std::set<int> & s) {
  for (std::set<int>::iterator i = s.begin(); i != s.end(); i++) {
    printf("%d ", *i);
  }
  printf("\n");
}

hash add(hash h, hash p) {
  return std::make_pair((h.first + p.first) % p1, (h.second + p.second) % p2);
}

hash next_hash(hash p) {
  return add(p, p);
}

void print_tree(node * n, int i) {
  for (int j = 0; j < i; j++) {
    printf(" ");
  }
  printf("low=%d high=%d hash=(%d %d)\n", n->low, n->high, n->h.first, n->h.second);
  if (n->left != NULL) {
    print_tree(n->left, i + 1);
  }
  if (n->right != NULL) {
    print_tree(n->right, i + 1);
  }
}

void push_hash(node * tree) {
  if (tree -> left != NULL) {
    tree -> left -> h = add(tree -> left -> h, tree -> h);
    push_hash(tree -> left);
  }
  if (tree -> right != NULL) {
    tree -> right -> h = add(tree -> right -> h, tree -> h);
    push_hash(tree -> right);
  }
  if (tree -> left == NULL && tree -> right == NULL) {
    M[tree -> h] += tree -> high - tree -> low;
  }
}

int best2(node * tree) {
  M.clear();
  push_hash(tree);
  // printf("with hash\n");
  // print_tree(tree, 0);
  int b = 0;
  for (mhi::iterator it = M.begin(); it != M.end(); it++) {
    b = max(b, it -> second);
  }
  return b;
}

bool contains(int low, int high, int v1, int v2) {
  if (low < v1) {
    return high >= v1;
  } else {
    return low < v2;
  }
}

void add2(node * tree, int v1, int v2, hash p) {
  int low = tree -> low;
  int high = tree -> high;
  //printf("add low=%d high=%d v1=%d v2=%d\n", low, high, v1, v2);
  if (low >= v1 && high <= v2) {
    tree -> h = add(tree -> h, p);
  } else {
    if (tree -> left != NULL && contains(tree -> left -> low, tree -> left -> high, v1, v2)) {
      add2(tree -> left, v1, v2, p);
    }
    if (tree -> right != NULL && contains(tree -> right -> low, tree -> right -> high, v1, v2)) {
      add2(tree -> right, v1, v2, p);
    }
  }
}

void free_tree(node * tree) {
  if (tree -> left != NULL) {
    free_tree(tree -> left);
  }
  if (tree -> right != NULL) {
    free_tree(tree -> right);
  }
  delete tree;
}

int solve2x() {
  node * tree = build_tree(Xs);
  //print_tree(tree, 0);
  hash p = init_hash(1);
  for (int i = 0; i < n; i++) {
    int x1 = rects[i].first.first;
    int x2 = rects[i].second.first;
    add2(tree, min(x1, x2), max(x1, x2), p);
    p = next_hash(p);
    // print_tree(tree, 0);
  }
  int res = best2(tree);
  free_tree(tree);
  return res;
}

int solve2y() {
  // printf("y\n");
  Xs.clear();
  node * tree = build_tree(Ys);
  //print_tree(tree, 0);
  hash p = init_hash(1);
  for (int i = 0; i < n; i++) {
    int y1 = rects[i].first.second;
    int y2 = rects[i].second.second;
    add2(tree, min(y1, y2), max(y1, y2), p);
    p = next_hash(p);
    // print_tree(tree, 0);
  }
  rects.clear();
  return best2(tree);
}

long long solve2() {
  return (long long)(solve2x()) * solve2y();
}

int main() {
  input();
  printf("%lld\n", solve2());
  return 0;
}