#include<bits/stdc++.h>
    using namespace std;
     
    #define maxn 211111
    typedef pair<int, int> pii;
    pii a[maxn][2], b[maxn];
    int val[maxn], sval[maxn];
    int d[maxn][2];
    int m;
    int n, r, c;
     
    void addpoint(pii x)
    {
        b[++m] = x;
    }
     
    bool onborder(pii x)
    {
        return x.first == 0 || x.first == c || x.second == 0 || x.second == r;
    }
     
    int getid(pii x)
    {
        if (x.first == 0)
        {
            return 1;
        }
        if (x.second == r)
        {
            return 2;
        }
        if (x.first == c)
        {
            return 3;
        }
        if (x.second == 0)
        {
            return 4;
        }
    }
     
    int cmp(pii x, pii y)
    {
        int lid1 = getid(x);
        int lid2 = getid(y);
        if (lid1 != lid2)
        {
            return lid1 < lid2;
        }
        if (lid1 == 1)
        {
            return x.second < y.second;
        }
        if (lid1 == 2)
        {
            return x.first < y.first;
        }
        if (lid1 == 3)
        {
            return x.second > y.second;
        }
        if (lid1 == 4)
        {
            return x.first > y.first;
        }
    }
     
    int main()
    {
        cin >> c >> r >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i][0].first >> a[i][0].second;
            cin >> a[i][1].first >> a[i][1].second;
     
            if (onborder(a[i][0]))
            {
                addpoint(a[i][0]);
            }
            if (onborder(a[i][1]))
            {
                addpoint(a[i][1]);
            }
     
        }
     
        set<pii> st;
        for (int i = 1; i <= m; i++)
        {
            st.insert(b[i]);
        }
        m = 0;
        for (auto x : st)
        {
            b[++m] = x;
        }
     
        sort(b + 1, b + 1 + m, cmp);
     
        map<pii, int> pos;
        for (int i = 1; i <= m; i++)
        {
            pos[b[i]] = i;
        }
     
        for (int i = 1; i <= n; i++)
        {
            if (!onborder(a[i][0]))
            {
                continue;
            }
            if (!onborder(a[i][1]))
            {
                continue;
            }
            d[i][0] = pos[a[i][0]];
            d[i][1] = pos[a[i][1]];
            if (d[i][0] > d[i][1])
            {
                swap(d[i][0], d[i][1]);
            }
            if (d[i][0] + 1 == d[i][1])
            {
                continue;
            }
        }
     
        for (int i = 1; i <= n; i++)
        {
            if (d[i][0] + 1 == d[i][1])
            {
                continue;
            }
            if (!d[i][0])
            {
                continue;
            }
            val[d[i][0]]++;
            val[d[i][1]]--;
        }
     
        for (int i = 1; i <= m; i++)
        {
            sval[i] = sval[i - 1] + val[i];
        }
     
        for (int i = 1; i <= n; i++)
        {
            int x = d[i][0] + 1;
            int y = d[i][1] - 1;
            if (sval[y] - sval[x - 1])
            {
                cout << "NO" << endl;
                return 0;
            }
        }
     
        cout << "YES" << endl;
        return 0;
    }

Measured memory_bytes: 29440