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
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define REP(i,n) for(int _n=(n), i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define TRACE(x) cerr << "TRACE(" #x ")" << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << endl;
typedef long long LL; typedef unsigned long long ULL;

class Input {
 public:
  Input() { bufpos = bufend = buffer; eof = false; }
  bool Eof() { return eof; }
  char Peek() { if(bufpos == bufend) Grab(); return *bufpos; }
  unsigned char UPeek() { return static_cast<unsigned char>(Peek()); }
  void SkipWS();
  template<class T> T Get();
  void operator()() {}
  template<class Arg, class... Args> void operator()(Arg &arg, Args &... args) {
    arg = Get<Arg>();
    operator()(args...);
  }
 private:
  static const int BUFSIZE = 1<<16;
  char buffer[BUFSIZE];
  char *bufpos;
  char *bufend;
  bool eof;
  void Grab();
};

void Input::Grab() {
  if(eof) return;
  bufpos = buffer;
  bufend = buffer + read(0, buffer, BUFSIZE);
  if(bufend==bufpos) { eof=true; *bufpos=0; }
}

template<> inline char Input::Get<char>() {
  char res = Peek();
  ++bufpos;
  return res;
}

void Input::SkipWS() {
  while(isspace(UPeek())) Get<char>();
}

template<> unsigned Input::Get<unsigned>() {
  SkipWS();
  unsigned x = 0;
  while(isdigit(UPeek())) {
    x = 10u * x + (Get<char>()-'0');
  }
  return x;
}

template<> int Input::Get<int>() {
  SkipWS();
  bool neg = false;
  if(Peek()=='-') { neg=true; Get<char>(); }
  unsigned x = Get<unsigned>();
  if (neg) x = -x;
  return static_cast<int>(x);
}

template<> ULL Input::Get<ULL>() {
  SkipWS();
  ULL x = 0;
  while(isdigit(UPeek())) {
    x = 10ULL * x + (Get<char>()-'0');
  }
  return x;
}

template<> LL Input::Get<LL>() {
  SkipWS();
  bool neg = false;
  if(Peek()=='-') { neg=true; Get<char>(); }
  ULL x = Get<ULL>();
  if (neg) x = -x;
  return static_cast<LL>(x);
}

template<> string Input::Get<string>() {
  SkipWS();
  string s;
  while(!Eof() && !isspace(UPeek())) s += Get<char>();
  return s;
}


Input IN;

struct Problem {
  int length;
  vector<array<int,2>> segments;

  int solve();
};

Problem problems[2];

void read_input() {
  int n; IN(n);
  REP(p,2) IN(problems[p].length);
  REP(p,2) problems[p].segments.resize(n);
  REP(i,n) {
    int x1,y1,x2,y2; IN(x1,y1,x2,y2);
    if (x1>x2) swap(x1,x2);
    if (y1>y2) swap(y1,y2);
    problems[0].segments[i] = {x1,x2};
    problems[1].segments[i] = {y1,y2};
  }
}

vector<ULL> zobrist;

void generate_zobrist() {
  zobrist.resize(problems[0].segments.size());
  mt19937 rng(3475445064u);
  for (ULL &z : zobrist) {
    z = ULL(rng()) | (ULL(rng()) << 32);
  }
}

struct Endpoint {
  int x;
  int idx; // segment idx
};

inline bool operator<(const Endpoint &a, const Endpoint &b) {
  return a.x < b.x;
}

struct HashedLen {
  ULL h;
  int len;
};

bool operator<(const HashedLen &a, const HashedLen &b) {
  return a.h < b.h;
}

int Problem::solve() {
  int nsegments = segments.size();

  // calc endpoints
  vector<Endpoint> endpoints;
  endpoints.reserve(2 * nsegments + 2); // 1m * 8b = 8 MB
  endpoints.push_back(Endpoint{0,-1});
  for (int i=0;i<nsegments;++i) {
    endpoints.push_back(Endpoint{segments[i][0], i});
    endpoints.push_back(Endpoint{segments[i][1], i});
  }
  endpoints.push_back(Endpoint{length,-1});
  sort(endpoints.begin()+1, endpoints.end()-1);

  vector<HashedLen> hashed_lens;
  hashed_lens.reserve(2*nsegments+1);

  ULL h = 0;
  hashed_lens.push_back(HashedLen{h, endpoints[1].x-endpoints[0].x});

  for (int i=1;i<=2*nsegments;++i) {
    const int idx = endpoints[i].idx;
    h ^= zobrist[idx];
    hashed_lens.push_back(HashedLen{h, endpoints[i+1].x-endpoints[i].x});
  }

  sort(hashed_lens.begin(), hashed_lens.end());

  int len = 0;
  h = 0;
  int best_len = 0;
  for (const HashedLen &hl : hashed_lens) {
    if (hl.h != h) {
      h = hl.h;
      len=0;
    }
    len += hl.len;
    best_len = max(best_len, len);
  }

  return best_len;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  read_input();
  generate_zobrist();
  LL res = LL(problems[0].solve()) * LL(problems[1].solve());
  cout << res << "\n";
}