local mfl, mce, mmi = math.floor, math.ceil, math.min
local mma = math.max
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    for j = 1, self.cnt[i] do
      self.stage[i][j] = self.func(self.stage[i + 1][j * 2 - 1], self.stage[i + 1][j * 2])
    end
  end
end
SegTree.create = function(self, n, func, emptyvalue)
  self.func, self.emptyvalue = func, emptyvalue
  local stagenum, mul = 1, 1
  self.cnt, self.stage, self.size = {1}, {{}}, {}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.cnt[stagenum], self.stage[stagenum] = mul, {}
  end
  for i = 1, stagenum do self.size[i] = self.cnt[stagenum + 1 - i] end
  self.stagenum = stagenum
  -- for i = 1, #ary do self.stage[stagenum][i] = ary[i] end
  -- for i = #ary + 1, mul do self.stage[stagenum][i] = emptyvalue end
  for i = 1, mul do self.stage[stagenum][i] = emptyvalue end
  self:updateAll()
end
SegTree.getRange = function(self, left, right)
  if left == right then return self.stage[self.stagenum][left] end
  local start_stage = 1
  while right - left + 1 < self.size[start_stage] do
    start_stage = start_stage + 1
  end
  local ret = self.emptyvalue
  local t1, t2, t3 = {start_stage}, {left}, {right}
  while 0 < #t1 do
    local stage, l, r = t1[#t1], t2[#t1], t3[#t1]
    table.remove(t1) table.remove(t2) table.remove(t3)
    local sz = self.size[stage]
    if (l - 1) % sz ~= 0 then
      local newr = mmi(r, mce((l - 1) / sz) * sz)
      table.insert(t1, stage + 1) table.insert(t2, l) table.insert(t3, newr)
      l = newr + 1
    end
    if sz <= r + 1 - l then
      ret = self.func(ret, self.stage[stage][mce(l / sz)])
      l = l + sz
    end
    if l <= r then
      table.insert(t1, stage + 1) table.insert(t2, l) table.insert(t3, r)
    end
  end
  return ret
end
SegTree.setValue = function(self, idx, value, silent)
  self.stage[self.stagenum][idx] = value
  if not silent then
    for i = self.stagenum - 1, 1, -1 do
      local dst = mce(idx / 2)
      local rem = dst * 4 - 1 - idx
      self.stage[i][dst] = self.func(self.stage[i + 1][idx], self.stage[i + 1][rem])
      idx = dst
    end
  end
end
SegTree.new = function(n, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func, emptyvalue)
  return obj
end

local r, c = io.read("*n", "*n")
local n = io.read("*n")
local t = {}

local function getidx(x, y)
  if x == 0 and y < c then
    return y
  elseif y == c and x < r then
    return c + x
  elseif x == r and 0 < c then
    return r + c + c - y
  else
    return c + c + r + r - x
  end
end

local lines = {}
for i = 1, n do
  local x1, y1 = io.read("*n", "*n")
  local x2, y2 = io.read("*n", "*n")
  if (x1 % r == 0 or y1 % c == 0) and (x2 % r == 0 or y2 % c == 0) then
    local idx1 = getidx(x1, y1)
    local idx2 = getidx(x2, y2)
    idx1, idx2 = mmi(idx1, idx2), mma(idx1, idx2)
    table.insert(t, idx1)
    table.insert(t, idx2)
    table.insert(lines, {idx1, idx2})
  end
end
table.sort(t)
table.sort(lines, function(a, b) return a[1] < b[1] end)
local tmap = {}
for i = 1, #t do
  tmap[t[i]] = i
end
local st = SegTree.new(#t, function(x, y) return x or y end, false)
local isok = true
for i = 1, #lines do
  local src, dst = tmap[lines[i][1]], tmap[lines[i][2]]
  if 1 < dst - src then
    local has = st:getRange(src + 1, dst - 1)
    if has then
      isok = false
      break
    end
  end
  st:setValue(dst, true)
end
print(isok and "YES" or "NO")


Measured memory_bytes: 33296