output_description: Print `YES` if the objective is achievable; print `NO` otherwise.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      R C N
      x_{1,1} y_{1,1} x_{1,2} y_{1,2}
      :
      x_{N,1} y_{N,1} x_{N,2} y_{N,2}
attempt: #include "bits/stdc++.h"
  #define _overload3(_1,_2,_3,name,...) name
  #define _rep(i,n) repi(i,0,n)
  #define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
  #define BUGAVOID(x) x
  #define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
  #define sz(c) (int)(c.size())
  #define all(c) c.begin(),c.end()
  #define mp make_pair
  #define write(x) cout<<(x)<<"\n"
  using namespace std; typedef long long ll;
  typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
  template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
  template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
  template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
  template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
  constexpr int INF = 1 << 28, MAX = 1e5 + 5, MOD = 1e9 + 7;
  constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
  constexpr int dy[4] = { 0,1,0,-1 }, dx[4] = { 1,0,-1,0 };
  struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;
  
  int R, C, N;
  vi X1, X2, Y1, Y2;
  
  int main() {
      cin >> R >> C >> N;
      X1.resize(N);
      X2.resize(N);
      Y1.resize(N);
      Y2.resize(N);
      rep(i, N) {
          cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
      }
  
      // 両端が辺に乗ってるもののみ
      // 左上0反時計回りに座標振る
      vp<int, int> sepa;
      rep(i, N) {
          if ((X1[i] % C && Y1[i] % R) || (X2[i] % C && Y2[i] % R)) continue;
  
          int crd1 = Y1[i] == 0 ? X1[i] :
              (X1[i] == C ? C + Y1[i] :
              (Y1[i] == R ? R + C + C - X1[i] :
                  R + 2 * C + R - Y1[i]));
          int crd2 = Y2[i] == 0 ? X2[i] :
              (X2[i] == C ? C + Y2[i] :
              (Y2[i] == R ? R + C + C - X2[i] :
                  R + 2 * C + R - Y2[i]));
          if (crd1 > crd2) swap(crd1, crd2);
  
          sepa.emplace_back(crd1, crd2);
      }
      sort(all(sepa));
  
      bool ans = true;
      if (!sepa.empty()) {
          int i = 0;
          while (i < sepa.size()) {
              int border = sepa[i].second;
              int j = i + 1;
              for (; j < sepa.size(); ++j) {
                  if (sepa[j].first > border) break;
                  else if (sepa[j].second > sepa[j - 1].second) {
                      ans = false;
                  }
              }
              i = j;
          }
      }
  
      write(ans ? "YES" : "NO");
  }
problem_description: Statement
  
  Snuke is playing a puzzle game. In this game, you are given a rectangular
  board of dimensions R × C, filled with numbers. Each integer i from 1 through
  N is written twice, at the coordinates (x_{i,1},y_{i,1}) and
  (x_{i,2},y_{i,2}).
  
  The objective is to draw a curve connecting the pair of points where the same
  integer is written, for every integer from 1 through N. Here, the curves may
  not go outside the board or cross each other.
  
  Determine whether this is possible.
samples: [{"input": "4 2 3\n    0 1 3 1\n    1 1 4 1\n    2 0 2 2", "output": "YES\n    \n\n![](https://atcoder.jp/img/arc076/hogehogehoge.png)\n\nThe above figure shows a possible solution.\n\n* * *"}, {"input": "2 2 4\n    0 0 2 2\n    2 0 0 1\n    0 2 1 2\n    1 1 2 1", "output": "NO\n    \n\n* * *"}, {"input": "5 5 7\n    0 0 2 4\n    2 3 4 5\n    3 5 5 2\n    5 5 5 4\n    0 3 5 1\n    2 2 4 4\n    0 5 4 1", "output": "YES\n    \n\n* * *"}, {"input": "1 1 2\n    0 0 1 1\n    1 0 0 1", "output": "NO"}]