Problem:
Score : 700 points

Problem 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.

Constraints

1 ≤ R,C ≤ 10^8

1 ≤ N ≤ 10^5

0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)

0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)

All given points are distinct.

All input values are integers.

Input

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}

Output

Print YES if the objective is achievable; print NO otherwise.

Sample Input 1

4 2 3
0 1 3 1
1 1 4 1
2 0 2 2

Sample Output 1

YES

The above figure shows a possible solution.

Sample Input 2

2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1

Sample Output 2

NO

Sample Input 3

5 5 7
0 0 2 4
2 3 4 5
3 5 5 2
5 5 5 4
0 3 5 1
2 2 4 4
0 5 4 1

Sample Output 3

YES

Sample Input 4

1 1 2
0 0 1 1
1 0 0 1

Sample Output 4

NO

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

LL R,C,N;
inline bool is_edge(LL X,LL Y){
	if( (0==X) || (R==X) || (0==Y) || (C==Y) ){
		return true;
	}
	return false;
}
void solve(){
	
	cin >> R >> C >> N;
	vector< vector<LL> > Top,Right,Down,Left;
	vector< vector<LL> > pos(2,vector<LL>(2));
	for(int i=0;i<N;++i){
		for(int j=0;j<2;++j){
			cin >> pos[j][0] >> pos[j][1];
		}

		if( is_edge(pos[0][0],pos[0][1]) &&
			is_edge(pos[1][0],pos[1][1]) ){
			for(int j=0;j<2;++j){
				vector<LL> temp(3);
				temp[0] = pos[j][0];
				temp[1] = pos[j][1];
				temp[2] = i;
				if( temp[0] == 0 ){
					Left.push_back( temp );
				}else if( temp[0] == R ){
					Right.push_back( temp );
				}else if( temp[1] == 0 ){
					Down.push_back( temp );
				}else if( temp[1] == C ){
					Top.push_back( temp );
				}
			}
		}
	}
	sort(Down.begin(), Down.end() );
	sort( Right.begin(), Right.end() );
	sort( Top.begin(), Top.end() );
	sort( Left.begin(), Left.end() );
	stack<LL> visit;
	int size = Down.size();
	for(int i=0;i<size;++i){//Down[i]
		int v = Down[i][2];
		if( !visit.empty() && v == visit.top() ){
			visit.pop();//取り出す。
		}else{
			visit.push( v );
		}
	}
	size = Right.size();
	for(int i=0;i<size;++i){
		//Right[i]
		int v = Right[i][2];
		if( !visit.empty() && v == visit.top()){
			visit.pop();
		}else{
			visit.push( v );
		}
	}

	size = Top.size();
	for(int i=size-1;i>=0;--i){//Top
		int v = Top[i][2];
		if( !visit.empty() && v == visit.top()){
			visit.pop();
		}else{
			visit.push( v );
		}
	}

	size = Left.size();
	for(int i=size-1;i>=0;--i){
		int v = Left[i][2];
		if( !visit.empty() && v == visit.top() ){
			visit.pop();
		}else{
			visit.push( v );
		}
	}
	
	if( visit.size() ){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()