#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

template<typename T, typename U>
struct LazySegmentTree{
private:
    int n, N;
    vector<T> node;
    vector<U> lazy;
    function<T(T, T)> F;
    T E;
    function<T(T, U)> G;
    function<U(U, U)> H;
    U I;
public:
    void init(int _n, function<T(T, T)> f, T e, function<T(T, U)> g, function<U(U, U)> h, U i){
        F = f; E = e;
        G = g; H = h; I = i;
        n = _n; N = 1;
        while(N < n) N = (N<<1);
        node.assign(2*N-1, E);
        lazy.assign(2*N-1, I);
    }
    void init(vector<T> v, function<T(T, T)> f, T e, function<T(T, U)> g, function<U(U, U)> h, U i){
        F = f; E = e;
        G = g; H = h; I = i;
        n = v.size(); N = 1;
        while(N < n) N = (N<<1);
        node.assign(2*N-1, E);
        lazy.assign(2*N-1, I);
        for(int i=0; i<n; i++) node[N-1+i] = v[i];
        for(int i=N-2; i>=0; i--) node[i] = F(node[(i<<1)+1], node[(i<<1)+2]);
    }
    int length(){
        return N;
    }
    T operator [](int a){
        return query(a, a+1);
    }
    void eval(int k){
        node[k] = G(node[k], lazy[k]);
        if(k < N-1){
            lazy[(k<<1)+1] = H(lazy[(k<<1)+1], lazy[k]);
            lazy[(k<<1)+2] = H(lazy[(k<<1)+2], lazy[k]);
        }
        lazy[k] = I;
    }
    void apply(int a, int b, U x, int k=0, int l=0, int r=-1){
        if(r == -1) r = N;
        eval(k);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b){
            lazy[k] = H(lazy[k], x);
            eval(k);
        }
        else{
            apply(a, b, H(I, x), (k<<1)+1, l, (l+r)>>1);
            apply(a, b, H(I, x), (k<<1)+2, (l+r)>>1, r);
            node[k] = F(node[(k<<1)+1], node[(k<<1)+2]);
        }
    }
    T query(int a, int b, int k=0, int l=0, int r=-1){
        if(r == -1) r = N;
        if(b <= l || r <= a) return E;
        eval(k);
        if(a <= l && r <= b) return node[k];
        return F(query(a, b, (k<<1)+1, l, (l+r)>>1), query(a, b, (k<<1)+2, (l+r)>>1, r));
    }
    int find_right(function<bool(T)> g, int a){
        if(!g(E)) return -1;
        T t = E;
        return min(find_right(g, a, 0, 0, N, t), n);
    }
    int find_right(function<bool(T)> g, int a, int k, int l, int r, T& t){
        eval(k);
        if(r-l == 1){
            t = F(t, node[k]);
            return g(t) ? r : a;
        }
        int m = (l + r) >> 1;
        if(m <= a) return find_right(g, a, (k<<1)+2, m, r, t);
        if(a <= l && g(F(t, node[k]))){
            t = F(t, node[k]);
            return r;
        }
        int L = find_right(g, a, (k<<1)+1, l, m, t);
        if(L < m) return L;
        int R = find_right(g, a, (k<<1)+2, m, r, t);
        return max(L, R);
    }
    int find_left(function<bool(T)> g, int b){
        if(!g(E)) return n + 1;
        T t = E;
        return find_left(g, b, 0, 0, N, t);
    }
    int find_left(function<bool(T)> g, int b, int k, int l, int r, T t){
        eval(k);
        if(r-l == 1){
            t = F(node[k], t);
            return g(t) ? l : b;
        }
        int m = (l + r) >> 1;
        if(b <= m) return find_left(g, b, (k<<1)+1, l, m, t);
        if(r <= b && g(F(node[k], t))){
            t = F(node[k], t);
            return l;
        }
        int R = find_left(g, b, (k<<1)+2, m, r, t);
        if(m < R) return R;
        int L = find_left(g, b, (k<<1)+1, l, m, t);
        return min(L, R);
    }
};

int W, H, N;

int calc(int x, int y){
    if(y == 0) return x;
    if(x == W) return W + y;
    if(y == H) return W + H + (W-x);
    if(x == 0) return W + H + W + (H-y);
}

vector<pair<int, int>> v;
vector<int> z;

LazySegmentTree<ll,ll> st;

signed main(){
    cin >> W >> H >> N;
    rep(i, N){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if((x1 == 0 || x1 == W || y1 == 0 || y1 == H) &&
            (x2 == 0 || x2 == W || y2 == 0 || y2 == H)){
            int a = calc(x1, y1);
            int b = calc(x2, y2);
            if(a > b) swap(a, b);
            v.pb({ a,b });
            z.pb(a);
            z.pb(b);
        }
    }

    sort(all(z));
    z.erase(unique(all(z)), z.end());
    rep(i, v.size()){
        v[i].first = lower_bound(all(z), v[i].first) - z.begin();
        v[i].second = lower_bound(all(z), v[i].second) - z.begin();
    }

    sort(all(v));
    st.init(z.size(), [](ll l, ll r){ return l+r; }, 0LL,
        [](ll m, ll f){ return m+f; }, [](ll o, ll n){ return o+n/2; }, 0LL);
    for(int i=v.size()-1; i>=0; i--){
        if(st[v[i].second] > 0){
            cout << "NO" << endl;
            return 0;
        }
        st.apply(v[i].first+1, v[i].second, 2*st.length());
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 13288