#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define NFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); --i)
#define endl "\n"
#define mp make_pair
#define X first
#define Y second
#define inf 1e9
#define mod 1000000007
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()
#define sz(x) int(x.size())
// #define lli int
typedef long long int lli;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef pair<lli,lli> pll;
typedef vector<lli> vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef complex <long double> complex_t;
const long double PI = acos((long double)-1.0);

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

ll r, c;
vector<pair<pair<ll,ll>,ll>> pos;
vector<pair<ll,ll>> arr[4];

bool isBorderPos(ll x1, ll y1, ll r, ll c) {
    if (x1 == 0 || y1 == 0 || x1 == r || y1 == c) return true;
    return false;
}

int getPointType(pair<ll,ll> point) {
    if (point.second == 0) {
        return 0;
    }
    if (point.first == r) {
        return 1;
    }
    if (point.second == c) {
        return 2;
    }
    if (point.first == 0) {
        return 3;
    }
    assert(false);
}

void insertPoint(ll x1, ll y1, ll r, ll c, int index1) {
    if (y1 == 0) {
        arr[0].pb(mp(x1, index1));
    } else if (x1 == r) {
        arr[1].pb(mp(y1, index1));
    } else if (y1 == c) {
        arr[2].pb(mp(-x1, index1));
    } else if (x1 == 0) {
        arr[3].pb(mp(-y1, index1));
    }
}

int main() {
    cin >> r >> c;
    int n; cin >> n;
    FOR(i, 0, n-1) {
        ll x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if (isBorderPos(x1, y1, r, c) && isBorderPos(x2, y2, r, c)) {
            insertPoint(x1, y1, r, c, i), insertPoint(x2, y2, r, c, i);
        }
    }
    for (int i = 0; i < 4; i++) sort(all(arr[i]));
    stack<int> s1;
    for (int i = 0; i < 4; i++) {
        for (auto v : arr[i]) {
            if (s1.empty()) {
                s1.push(v.second);
            } else {
                if (s1.top() == v.second) {
                    s1.pop();
                } else {
                    s1.push(v.second);
                }
            }
        }
    }

    if (s1.empty()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
return 0;}

Measured memory_bytes: 4840