Polycarp is a great fan of television.

He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment l_{i} and ends at moment r_{i}.

Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV.

Polycarp wants to check out all n shows. Are two TVs enough to do so?


-----Input-----

The first line contains one integer n (1 ≤ n ≤ 2·10^5) — the number of shows.

Each of the next n lines contains two integers l_{i} and r_{i} (0 ≤ l_{i} < r_{i} ≤ 10^9) — starting and ending time of i-th show.


-----Output-----

If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).


-----Examples-----
Input
3
1 2
2 3
4 5

Output
YES

Input
4
1 2
2 3
2 3
1 2

Output
NO

Source: codeforces | Difficulty: MEDIUM
Tags: Sorting

Data structures

Greedy algorithms


Solutions:
n = int(input())
shows = []
MAX_TVS = 2
for i in range(n):
	show_info = [int(x) for x in input().split()]
	shows.append(show_info)
shows.sort(key=lambda x: x[0])
tvs = []
i = 0
while len(tvs) <= MAX_TVS and i < n:
	if len(tvs) == MAX_TVS:
		if shows[i][0] > tvs[0][1]:
			tvs.pop(0)
		elif shows[i][0] > tvs[1][1]:
			tvs.pop(1)
	tvs.append(shows[i])
	i += 1
result = 'YES'
if len(tvs) > MAX_TVS:
	result = 'NO'
print(result)


def main():
	(l, c) = ([], 0)
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		l.append(a * 2)
		l.append(b * 2 + 1)
	l.sort()
	for a in l:
		if a & 1:
			c -= 1
		else:
			c += 1
			if c > 2:
				print('NO')
				break
	else:
		print('YES')
main()


shows = int(input())
array = []
for _ in range(shows):
	(start, end) = input().split()
	(start, end) = (int(start), int(end))
	array.append((start, 1))
	array.append((end + 1, -1))
array.sort()
count = 0
poss = True
for item in array:
	count += item[1]
	if count >= 3:
		poss = False
		break
if poss:
	print('YES')
else:
	print('NO')


n = int(input())
shows = [list(map(int, input().split())) for _ in range(n)]
shows.sort(key=lambda x: x[0])
tv1 = [-1, -1]
tv2 = [-1, -1]
output = 'YES'
for show in shows:
	if show[0] > tv1[1]:
		tv1 = show
	elif show[0] > tv2[1]:
		tv2 = show
	else:
		output = 'NO'
		break
print(output)


def main():
	n = int(input())
	events = []
	for _ in range(n):
		(l, r) = (int(x) for x in input().split())
		events.append((l, 1))
		events.append((r + 1, -1))
	cur = 0
	for (_, event) in sorted(events):
		cur += event
		if cur > 2:
			print('NO')
			break
	else:
		print('YES')
main()


n = int(input())
pair = list()
pair1 = list()
pair2 = list()
for i in range(n):
	(x, y) = map(int, input().split())
	pair.append((x, y))
pair.sort()
f = True
for i in range(n):
	x = pair[i][0]
	y = pair[i][1]
	len1 = len(pair1)
	len2 = len(pair2)
	if len1 == 0 or x > pair1[len1 - 1][1]:
		pair1.append((x, y))
	elif len2 == 0 or x > pair2[len2 - 1][1]:
		pair2.append((x, y))
	else:
		f = False
		break
if f:
	print('YES')
else:
	print('NO')


n = int(input())
shows = []
for i in range(n):
	(start, end) = [int(c) for c in input().split(' ')]
	shows.append((start, end))
shows.sort(key=lambda tup: tup[0])
last_show_tv1 = None
last_show_tv2 = None
can_watch = True
for show in shows:
	if last_show_tv1 == None:
		last_show_tv1 = show
	elif last_show_tv2 == None:
		last_show_tv2 = show
	elif not show[0] <= last_show_tv1[1]:
		last_show_tv1 = show
	elif not show[0] <= last_show_tv2[1]:
		last_show_tv2 = show
	else:
		can_watch = False
		break
if can_watch:
	print('YES')
else:
	print('NO')


n = int(input())
v = []
for i in range(n):
	s = input()
	s = [int(x) for x in s.split()]
	v.append(s)
v.sort()
w = []
last = -1
for i in range(n):
	if v[i][0] <= last:
		w.append(v[i])
	else:
		last = v[i][1]
last = -1
f = 1
for i in range(len(w)):
	if w[i][0] <= last:
		f = 0
		break
	else:
		last = w[i][1]
if f:
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for i in range(n):
	aa = list(map(int, input().split()))
	a.append(aa)
a = sorted(a)
if n > 2:
	tv1 = a[0][1]
	tv2 = a[1][1]
	t = True
	for i in range(2, n):
		if a[i][0] > tv1:
			tv1 = a[i][1]
		elif a[i][0] > tv2:
			tv2 = a[i][1]
		else:
			t = False
			break
	if t:
		print('YES')
	else:
		print('NO')
else:
	print('YES')


n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
a.sort()
p = -1
q = -1
f = 0
for (l, r) in a:
	if l > p:
		p = r
	elif l > q:
		q = r
	else:
		f = 1
		break
if f:
	print('NO')
else:
	print('YES')


n = int(input())
t = []
flag = True
for i in range(n):
	t.append(list(map(int, input().split(' '))))
t.sort()
(l1, l2) = (-1, -1)
for i in range(n):
	if t[i][0] > l1 and t[i][0] > l2:
		if l1 > l2:
			l1 = t[i][1]
		else:
			l2 = t[i][1]
	elif t[i][0] > l1:
		l1 = t[i][1]
	elif t[i][0] > l2:
		l2 = t[i][1]
	else:
		print('NO')
		flag = False
		break
if flag:
	print('YES')


n = int(input())
shows = []
for _ in range(n):
	shows.append(tuple(map(int, input().split())))
shows.sort()
end_1 = -1
end_2 = -1
for show in shows:
	if show[0] > end_1:
		end_1 = show[1]
		continue
	if show[0] > end_2:
		end_2 = show[1]
		continue
	else:
		print('NO')
		break
else:
	print('YES')


d = []
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	d.append([a, -1])
	d.append([b, 1])
d.sort()
t = 0
for i in d:
	t -= i[1]
	if t > 2:
		print('NO')
		exit(0)
print('YES')


from collections import Counter
import string
import math
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))

def printDivisors(n):
	divisors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				divisors.append(i)
			else:
				divisors.extend((i, n // i))
		i = i + 1
	return divisors

def countTotalBits(num):
	binary = bin(num)[2:]
	return len(binary)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
n = vary(1)
arr = []
comp = lambda x: x[1]
for i in range(n):
	(l, r) = vary(2)
	arr.append([1, l])
	arr.append([2, r])
arr.sort()
arr.sort(key=comp)
count = 0
for i in arr:
	if count > 2:
		print('NO')
		break
	if i[0] == 1:
		count += 1
	else:
		count -= 1
else:
	print('YES')


from math import inf
n = int(input())
a = []
for _ in range(n):
	b = list(map(int, input().split()))
	a.append(b)
a.sort()

def f(a):
	i = a[0]
	j = a[1]
	q = 2
	k = 0
	while 1:
		if a[q][0] == k:
			return 'NO'
		if i[1] == k:
			i = a[q]
			q += 1
		if len(a) == q:
			return 'YES'
		if j[1] == k:
			j = a[q]
			q += 1
		if len(a) == q:
			return 'YES'
		k = min(i[1], j[1], a[q][0])
if n <= 2:
	print('YES')
else:
	print(f(a))


import io, os
import sys
from atexit import register
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda : os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0

def nextStr():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = input().split()
		tokens_next = 0
	tokens_next += 1
	if type(tokens[tokens_next - 1]) == str:
		return tokens[tokens_next - 1]
	return tokens[tokens_next - 1].decode()

def nextInt():
	return int(nextStr())

def nextIntArr(n):
	return [nextInt() for i in range(n)]

def print(s, end='\n'):
	sys.stdout.write((str(s) + end).encode())

def solve(shows):
	tv1 = None
	tv2 = None
	for cur in sorted(shows):
		if not tv1 or tv1[1] < cur[0]:
			tv1 = cur
			continue
		elif not tv2 or tv2[1] < cur[0]:
			tv2 = cur
			continue
		return 'NO'
	return 'YES'
n = nextInt()
shows = [(nextInt(), nextInt()) for _ in range(n)]
print(solve(shows))


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
n = int(input())
a = []
for i in range(n):
	(x, y) = mapi()
	a.append([x, -1])
	a.append([y, 1])
a.sort()
f = 1
cnt = 0
for (i, v) in enumerate(a):
	if v[1] == -1:
		cnt += 1
	else:
		cnt -= 1
	if cnt > 2:
		f = 0
		break
if f:
	print('YES')
else:
	print('NO')


num_shows = int(input())
showtimes = []
for i in range(num_shows):
	showtime = [int(i) for i in input().split(' ')]
	showtimes.append((showtime[0], showtime[1]))
showtimes = sorted(showtimes)

class TV:

	def __init__(self):
		self.endtime = -1
tv1 = TV()
tv2 = TV()
start_time = min((st[0] for st in showtimes))
end_time = max((st[1] for st in showtimes))
fail_signal = False
for st in showtimes:
	start_time = st[0]
	end_time = st[1]
	if start_time <= tv1.endtime and start_time <= tv2.endtime:
		fail_signal = True
		break
	elif start_time > tv1.endtime:
		tv1.endtime = end_time
	else:
		tv2.endtime = end_time
if fail_signal:
	print('NO')
else:
	print('YES')


import sys
N = int(input())
C = []
X = []
inside = {}
ctr = 0
for n in range(N):
	(l, r) = map(int, input().split())
	C += [(l, r)]
C.sort(key=lambda k: (k[0], k[1]))
i = 0
for (l, r) in C:
	X += [(l, i), (r, i)]
	i += 1
X.sort(key=lambda k: (k[0], -k[1]))
for (x, i) in X:
	if not inside.get(i):
		inside[i] = True
		ctr += 1
		if ctr > 2:
			print('NO')
			sys.exit()
	else:
		inside[i] = None
		ctr -= 1
print('YES')


n = int(input())
shows = []
for i in range(n):
	shows.append(list(map(lambda s: int(s), input().split())))
shows = sorted(shows)
t = [-1, -1]
violate = False
for s in shows:
	if s[0] > t[0]:
		t[0] = s[1]
	elif s[0] > t[1]:
		t[1] = s[1]
	else:
		violate = True
		break
if not violate:
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for i in range(n):
	b = list(map(int, input().split()))
	a.append([b[0], -1])
	a.append([b[1], 1])
a.sort()
cur = 0
for i in a:
	cur += i[1]
	if cur <= -3:
		print('NO')
		break
else:
	print('YES')


tv1 = -1
tv2 = -1
shows = []
n = int(input())
for i in range(n):
	(l, r) = map(int, input().split())
	shows.append((l, r))
shows.sort()
for (l, r) in shows:
	if tv1 < l:
		tv1 = r
	elif tv2 < l:
		tv2 = r
	else:
		print('NO')
		break
else:
	print('YES')


from operator import itemgetter
n = int(input())
A = []
for i in range(n):
	A.append([int(i) for i in input().split()])
A = sorted(A, key=itemgetter(0))
first_tv = []
second_tv = []
first_end = -1
second_end = -1
for i in range(n):
	if A[i][0] > first_end:
		first_end = A[i][1]
	elif A[i][0] > second_end:
		second_end = A[i][1]
	else:
		print('NO')
		break
else:
	print('YES')


from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys
n = sys.stdin.readline()
a = []
n = int(n)
for i in range(n):
	(u, v) = map(int, input().split())
	a.append((u, 1))
	a.append((v, -1))
a.sort(key=lambda x: (x[0], -1 * x[1]))
cnt = 0
for i in a:
	if i[1] == 1:
		cnt += 1
	else:
		cnt -= 1
	if cnt > 2:
		print('NO')
		exit()
print('YES')


n = int(input())
l = []
for i in range(0, n):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	l.append([a, 0])
	l.append([b, 1])
l.sort(key=lambda x: (x[0], x[1]))
TV = 0
r = 0
ans = 'YES'
for x in l:
	if x[1] == 0:
		TV += 1
	else:
		TV -= 1
	if TV > 2:
		ans = 'NO'
		break
print(ans)


n = int(input())
tv1 = []
tv2 = []
shows = []
for i in range(n):
	temp = list(map(int, input().split()))
	shows.append(temp)
shows.sort(key=lambda x: x[0])
ok = 'YES'
for e in shows:
	if len(tv1) == 0:
		tv1.append(e)
	elif len(tv2) == 0:
		tv2.append(e)
	elif tv1[-1][1] < e[0]:
		tv1.append(e)
	elif tv2[-1][1] < e[0]:
		tv2.append(e)
	else:
		ok = 'NO'
		break
print(ok)


from collections import namedtuple
n = int(input())
Show = namedtuple('Show', 'time sign')
shows = []
for _ in range(n):
	(time1, time2) = map(int, input().split())
	shows.append(Show(time1, '+'))
	shows.append(Show(time2, '-'))
tv = 0
for show in sorted(shows):
	if show.sign == '+':
		tv += 1
	else:
		tv -= 1
	if tv > 2:
		print('NO')
		exit(0)
print('YES')


n = int(input())
tv1 = -1
tv2 = -1
a = []
drop = False
for _ in range(n):
	a.append(tuple((int(x) for x in input().split())))
a.sort()
for (s, f) in a:
	if tv1 < s:
		tv1 = f
	elif tv2 < s:
		tv2 = f
	else:
		drop = True
print('YNEOS'[drop::2])


import sys
n = int(input())
x = []
z = []
for i in range(n):
	(a, b) = map(int, input().split())
	x.append(a)
	z.append(b + 1)
x.sort()
z.sort()
s = ''
sc = 0
k = 0
j = 0
while len(x) != k and len(z) != j:
	if x[k] > z[j]:
		s += ')'
		j += 1
	elif x[k] < z[j]:
		s += '('
		k += 1
	else:
		k += 1
		j += 1
if len(z) - j > 0:
	s += ')' * (len(z) - j)
for i in range(len(s)):
	if sc > 2:
		print('NO')
		sys.exit()
	if s[i] == '(':
		sc += 1
	else:
		sc -= 1
print('YES')


l = []
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l.append((n, m))
l.sort()
(le, ri) = (-1, -1)
for i in range(t):
	if l[i][0] > le:
		le = l[i][1]
	elif l[i][0] > ri:
		ri = l[i][1]
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
shows = []
for i in range(n):
	temp = [int(j) for j in input().split(' ')]
	temp[1] += 1
	shows.append(temp[:])
shows.sort()
if n > 1:
	tv1 = shows[0][1]
	tv2 = shows[1][1]
	(flag1, flag2) = (0, 0)
	c = 0
	shows.append([1000000001, 1000000001])
	for i in range(2, n, 1):
		if tv1 <= shows[i][0] and flag1 == 0:
			tv1 = shows[i][1]
			if shows[i + 1][0] >= tv1:
				flag1 = 0
			else:
				flag1 = 1
			if shows[i + 1][0] >= tv2:
				flag2 = 0
			else:
				flag2 = 1
		elif tv2 <= shows[i][0] and flag2 == 0:
			tv2 = shows[i][1]
			if shows[i + 1][0] >= tv1:
				flag1 = 0
			else:
				flag1 = 1
			if shows[i + 1][0] >= tv2:
				flag2 = 0
			else:
				flag2 = 1
		else:
			c = -1
	if c == 0:
		print('YES')
	else:
		print('NO')
else:
	print('YES')


def main():
	n = int(input())
	L = [None] * n
	for i in range(n):
		L[i] = [int(x) for x in input().split()]
	print(solver(n, L))

def solver(n, L):
	momentList = [None] * (2 * n)
	index = 0
	for (l, r) in L:
		momentList[index] = (l, 0)
		momentList[index + 1] = (r, 1)
		index += 2
	momentList.sort(key=lambda x: (x[0], x[1]))
	showsAtOnce = 0
	for (time, typ) in momentList:
		if typ == 0:
			showsAtOnce += 1
			if showsAtOnce > 2:
				return 'NO'
		elif typ == 1:
			showsAtOnce -= 1
	return 'YES'
main()


n = int(input())
events = []
for i in range(n):
	(l, r) = map(int, input().split())
	events.append((l, -1))
	events.append((r, 1))
events = sorted(events)
bal = 0
result = True
for item in events:
	bal += item[1] * -1
	if bal > 2:
		result = False
		print('NO')
		break
if result:
	print('YES')


n = int(input())
show = [list(map(int, input().split())) for _ in range(n)]
show.sort(key=lambda x: x[0])
tv1 = tv2 = -1
ans = True
for i in range(n):
	if show[i][0] > tv1:
		tv1 = show[i][1]
	elif show[i][0] > tv2:
		tv2 = show[i][1]
	else:
		ans = False
		break
print('YES' if ans else 'NO')


n = int(input())
d = {}
s = []
for i in range(n):
	a = list(map(int, input().split(' ')))
	if a[0] in d:
		d[a[0]][0] += 1
	else:
		d[a[0]] = [1, 0]
		s.append(a[0])
	if a[1] in d:
		d[a[1]][1] += 1
	else:
		d[a[1]] = [0, 1]
		s.append(a[1])
s.sort()
t = 0
r = 0
for i in s:
	t += d[i][0]
	if t > 2:
		r = 1
		break
	t -= d[i][1]
if r == 1:
	print('NO')
else:
	print('YES')


def main():
	arrl = []
	arrr = []
	n = int(input())
	for t in range(n):
		(a, b) = map(int, input().split())
		arrl.append(a)
		arrr.append(b)
	arrl.sort()
	arrr.sort()
	l = 0
	r = 0
	cnt = 0
	while l < n and r < n:
		if arrl[l] <= arrr[r]:
			cnt += 1
			l += 1
		else:
			cnt -= 1
			r += 1
		if cnt > 2:
			print('NO')
			return
	print('YES')
	return
main()


s = [tuple(map(int, input().split())) for i in range(int(input()))]
s.sort(key=lambda q: q[0])
a = b = -1
q = 'YES'
for (l, r) in s:
	if a >= l:
		q = 'NO'
		break
	a = r
	if b < a:
		(a, b) = (b, a)
print(q)


n = int(input())
times = []
for i in range(n):
	(l, r) = map(int, input().split())
	times.append((l, 1))
	times.append((r, -1))
times.sort(key=lambda x: (x[0], -x[1]))
s = 0
ans = 'YES'
for x in times:
	s += x[1]
	if s == 3:
		ans = 'NO'
		break
print(ans)


n = int(input())
data = []
k = 0
for i in range(n):
	data.append(list(map(int, input().split())))
data.sort()
if n < 2:
	print('YES')
else:
	a = data[0]
	b = data[1]
	for i in range(2, n):
		if a[1] < data[i][0]:
			a = data[i]
		elif b[1] < data[i][0]:
			b = data[i]
		else:
			print('NO')
			k = 1
			break
	if k == 0:
		print('YES')


n = int(input())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
a.sort()
b = a[0][1]
c = -1
e = 0
for i in range(1, n):
	if a[i][0] > b:
		b = a[i][1]
	elif a[i][0] > c:
		c = a[i][1]
	else:
		e = 1
		break
if e == 1:
	print('NO')
else:
	print('YES')


n = int(input())
segment = []
for _ in range(n):
	segment.append(list(map(int, input().split())))
segment.sort(key=lambda x: x[0])
start1 = 0
end1 = -float('inf')
start2 = 0
end2 = -float('inf')
for x in segment:
	start = x[0]
	end = x[1]
	if start > end1:
		start1 = start
		end1 = end
	elif start > end2:
		start2 = start
		end2 = end
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
events = []
for i in range(n):
	(a, b) = map(int, input().split())
	events.append((a, +1))
	events.append((b, -1))
events = sorted(events, key=lambda x: (x[0], -x[1]))
max_shows = 0
cur_shows = 0
for (_, e) in events:
	cur_shows += e
	max_shows = max(max_shows, cur_shows)
if max_shows > 2:
	print('NO')
else:
	print('YES')


n = int(input())
shows = []
for i in range(n):
	shows.append(tuple(map(int, input().split())))
shows.sort(key=lambda x: x[0])
tv1 = shows[0]
conflict = False
if n > 1:
	tv2 = shows[1]
	for i in range(2, n):
		show = shows[i]
		if show[0] > tv1[1]:
			tv1 = show
		elif show[0] > tv2[1]:
			tv2 = show
		else:
			conflict = True
			break
if conflict:
	print('NO')
else:
	print('YES')


n = int(input())
m = []
for i in range(0, n):
	(a, b) = map(int, input().split())
	m.append((a, b))
m.sort()
a1 = -1
a2 = -1
flag = 'YES'
for i in range(n):
	if m[i][0] > a1:
		a1 = m[i][1]
	elif m[i][0] > a2:
		a2 = m[i][1]
	else:
		flag = 'NO'
print(flag)


import itertools

def srtf(elem: list):
	return elem[0]

def solve():
	n = int(input())
	a = []
	for i in range(0, n):
		rx = list(map(lambda x: int(x), input().split()))
		a.append([rx[0], rx[1]])
	a.sort(key=srtf)
	tv = [-1, -1]
	for i in range(0, n):
		if tv[0] < a[i][0]:
			tv[0] = -1
		if tv[1] < a[i][0]:
			tv[1] = -1
		if tv[0] == -1:
			tv[0] = a[i][1]
		elif tv[1] == -1:
			tv[1] = a[i][1]
		else:
			print('NO')
			return
	print('YES')
solve()


n = int(input())
arr = list()
for i in range(n):
	(l, r) = map(int, input().split())
	arr.append((l, r))
(e1, e2) = (-1, -1)
arr.sort()
ans = 'YES'
for i in arr:
	if i[0] > e1:
		e1 = i[1]
	elif i[0] > e2:
		e2 = i[1]
	else:
		ans = 'NO'
print(ans)


n = int(input())
s = []
for _ in range(n):
	(x, y) = map(int, input().split())
	s.append((x, y))
s.sort()
a = [s[0]]
b = [(0, -10)]
for x in range(1, len(s)):
	if s[x][0] > a[-1][1]:
		a.append(s[x])
	elif s[x][0] > b[-1][1]:
		b.append(s[x])
if len(a) + len(b) - 1 == len(s):
	print('YES')
else:
	print('NO')


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start = time.time()
from collections import deque
shows = []
for i in range(int(input())):
	shows.append([int(i) for i in input().split()])
shows.sort()
shows = deque(shows)
workers = [-1, -1]
enough_tvs = True
while shows and enough_tvs:
	show = shows.popleft()
	if workers[0] < show[0]:
		workers[0] = show[1]
		if workers[1] < show[0]:
			workers[1] = -1
	elif workers[1] < show[0]:
		workers[1] = show[1]
	else:
		enough_tvs = False
if enough_tvs:
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append((x, y))
f = True
a.sort()
(t1, t2) = (-1, -1)
for i in range(n):
	(x, y) = a[i]
	if x > t1:
		t1 = y
	elif x > t2:
		t2 = y
	else:
		f = False
if f:
	print('YES')
else:
	print('NO')


def main():
	n = int(input())
	lst = list()
	for i in range(n):
		line = input()
		(l, r) = map(int, line.split())
		lst.append((l, r))
	lst.sort()
	tv1 = [(-1, -1)]
	tv2 = [(-1, -1)]
	for i in range(n):
		if lst[i][0] > tv1[-1][1]:
			tv1.append(lst[i])
		elif lst[i][0] > tv2[-1][1]:
			tv2.append(lst[i])
	tv1.remove(tv1[0])
	tv2.remove(tv2[0])
	tv = tv1 + tv2
	tv.sort()
	if lst != tv:
		return 'NO'
	else:
		return 'YES'
rs = main()
print(rs)


n = int(input())
d = []
for i in range(n):
	(l, r) = map(int, input().split())
	d.append((l, 1))
	d.append((r + 1, -1))
d.sort()
res = 0
a = True
for i in d:
	res = res + i[1]
	if res > 2:
		print('NO')
		a = False
		break
if a:
	print('YES')


n = int(input().strip())
schedule = []
for i in range(n):
	(l, r) = list(map(int, input().strip().split()))
	schedule.append((l, -1))
	schedule.append((r, 1))
schedule.sort()
layer = 0
is_possible = True
for (_, dx) in schedule:
	layer += dx
	if layer < -2:
		is_possible = False
		break
if is_possible:
	print('YES')
else:
	print('NO')


num_shows = int(input())
showtimes = []
for i in range(num_shows):
	showtime = [int(i) for i in input().split(' ')]
	showtimes.append((showtime[0], showtime[1]))
showtimes = sorted(showtimes)
tv1 = -1
tv2 = -1
start_time = min((st[0] for st in showtimes))
end_time = max((st[1] for st in showtimes))
fail_signal = False
for st in showtimes:
	start_time = st[0]
	end_time = st[1]
	if start_time <= tv1 and start_time <= tv2:
		fail_signal = True
		break
	elif start_time > tv1:
		tv1 = end_time
	else:
		tv2 = end_time
if fail_signal:
	print('NO')
else:
	print('YES')


li = []
n = int(input())
for _ in range(n):
	(l, r) = map(int, input().split())
	li.append((l, r))
li.sort()
(a, b) = (-1, -1)
f = True
for i in range(n):
	if a < li[i][0]:
		a = li[i][1]
	elif b < li[i][0]:
		b = li[i][1]
	else:
		f = False
if f:
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	shows = []
	for show in range(n):
		(l, r) = [int(x) for x in input().split(' ')]
		shows.append((l, -1))
		shows.append((r, 1))
	shows.sort()
	conc = 0
	for s in shows:
		conc += s[1]
		if conc < -2:
			return 'NO'
	return 'YES'
print(solve())


n = int(input())
(a, b) = ([], [])
for i in range(n):
	t = [int(i) for i in input().split()]
	a.append(t[0])
	b.append(t[1])
a.sort()
b.sort()
i = j = 0
ans = 0
while ans <= 2 and i < n and (j < n):
	if a[i] <= b[j]:
		ans += 1
		i += 1
	else:
		ans -= 1
		j += 1
if ans > 2:
	print('NO')
else:
	print('YES')


from collections import deque
n = int(input())
a = []
for i in range(n):
	(l, r) = map(int, input().split())
	a.append((l, r))
a = deque(sorted(a))
b = deque()
c = deque()
while len(a):
	show = a.popleft()
	if len(b) and len(c):
		if show[0] > b[0][1]:
			b.pop()
			b.append(show)
		elif show[0] > c[0][1]:
			c.pop()
			c.append(show)
		else:
			print('NO')
			break
	elif not len(b):
		b.append(show)
	else:
		c.append(show)
else:
	print('YES')


n = int(input())
tv1 = (-1, -1)
tv2 = (-1, -1)
tgr = True
a = []
for i in range(n):
	a.append(tuple((int(x) for x in input().split())))
a.sort()
for (l, r) in a:
	if tv1[1] < l:
		tv1 = (l, r)
	elif tv2[1] < l:
		tv2 = (l, r)
	else:
		tgr = False
if tgr is True:
	print('YES')
else:
	print('NO')


n = int(input())
t = [0] * n
t1 = -1
t2 = -1
ff = True
for i in range(n):
	(a, b) = list(map(int, input().split()))
	t[i] = (a, b)
t.sort()
for i in range(n):
	bl = False
	if t[i][0] > t1:
		t1 = t[i][1]
		bl = True
	if not bl and t[i][0] > t2:
		t2 = t[i][1]
		bl = True
	if not bl:
		ff = False
		break
if ff:
	print('YES')
else:
	print('NO')


from sys import stdin
input = stdin.readline
q = []
counter = 0
n = int(input())
for i in range(n):
	(s, e) = map(int, input().split())
	q.append([s, True])
	q.append([e + 1, False])
q.sort()
for i in range(len(q)):
	if q[i][1]:
		counter += 1
	else:
		counter -= 1
	if counter >= 3:
		print('NO')
		exit()
print('YES')


h = int(input())
programas = []
tvs = [-1, -1]
for i in range(h):
	programas.append(list(map(int, input().split())))
programas.sort()
teste = True
for i in programas:
	horario = min(tvs)
	if i[0] <= horario:
		print('NO')
		teste = False
		break
	else:
		tvs[tvs.index(horario)] = i[1]
if teste:
	print('YES')


k = int(input())
nacalo = []
konec = []
s = 0
for gh in range(k):
	(x, y) = map(int, input().split())
	nacalo.append(x)
	konec.append(y)
nacalo.sort()
konec.sort()
i_nach = 0
i_kon = 0
while i_nach < k and i_kon < k:
	tek = min(nacalo[i_nach], konec[i_kon])
	while i_nach < k and nacalo[i_nach] == tek:
		s += 1
		if s >= 3:
			print('NO')
			exit(0)
		i_nach += 1
	while i_kon < k and konec[i_kon] == tek:
		s -= 1
		i_kon += 1
print('YES')


import sys
n = int(input())
a = []
tv1 = -1
tv2 = -1
for _ in range(n):
	a += [tuple(map(int, sys.stdin.readline().split()))]
a.sort()
for i in range(n):
	(s, e) = a[i]
	if s > tv1:
		tv1 = e
	elif s > tv2:
		tv2 = e
	else:
		break
else:
	print('YES')
	exit()
print('NO')


n = int(input())
c = []
for i in range(n):
	a = list(map(int, input().strip().split(' ')))
	c.append(a)
c.sort()
if n <= 2:
	print('YES')
else:
	u = 0
	tv1 = []
	tv2 = []
	tv1.append(c[0])
	tv2.append(c[1])
	for i in range(2, n):
		if c[i][0] > tv1[0][1]:
			tv1[0] = c[i]
		elif c[i][0] > tv2[0][1]:
			tv2[0] = c[i]
		else:
			u = 1
			break
	if u == 0:
		print('YES')
	else:
		print('NO')


read = lambda : map(int, input().split())
n = int(input())
ev = []
for i in range(n):
	(l, r) = read()
	r += 1
	ev.append((l, 1))
	ev.append((r, -1))
ev.sort()
bal = 0
flag = 1
for (x, t) in ev:
	bal += t
	if bal > 2:
		flag = 0
		break
print('YES' if flag else 'NO')


n = int(input())
l = []
for _ in range(n):
	l.append(tuple(map(int, input().split())))
l.sort()
t1 = -1
t2 = -1
for i in l:
	if i[0] > t1:
		t1 = i[1]
	elif i[0] > t2:
		t2 = i[1]
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
d = []
for i in range(n):
	(lb, rb) = list(map(int, input().split()))
	d.append([lb, -1])
	d.append([rb, 1])
d.sort()
cnt = 0
for i in d:
	cnt -= i[1]
	if cnt >= 3:
		print('NO')
		exit(0)
print('YES')


from sys import stdin
n = int(stdin.readline().strip())
s = [tuple(map(int, stdin.readline().strip().split())) for i in range(n)]
s.sort()
t1 = (-1, -1)
t2 = (-1, -1)
for i in s:
	if i[0] > t1[1]:
		t1 = i
	elif i[0] > t2[1]:
		t2 = i
	else:
		print('NO')
		exit(0)
print('YES')


import bisect
from itertools import accumulate, count
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime

def primefactors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return sorted(fac)

def factors(n):
	fac = set()
	fac.add(1)
	fac.add(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
n = int(input())
d = []
for i in range(n):
	(lb, rb) = list(map(int, input().split()))
	d.append([lb, -1])
	d.append([rb, 1])
d.sort()
cnt = 0
for i in d:
	cnt -= i[1]
	if cnt >= 3:
		print('NO')
		exit(0)
print('YES')


n = int(input())
horarios = [tuple(map(int, input().split())) for i in range(n)]
horarios.sort()
aux = []
flag = True
for i in range(n):
	if len(aux) < 2:
		aux.append(horarios[i])
		continue
	if horarios[i][0] > aux[0][1]:
		aux[0] = horarios[i]
	elif horarios[i][0] > aux[1][1]:
		aux[1] = horarios[i]
	else:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


import sys
from heapq import heappush, heappop
n = int(sys.stdin.buffer.readline().decode('utf-8'))
a = sorted((list(map(int, line.decode('utf-8').split())) for line in sys.stdin.buffer))
hq = []
for (l, r) in a:
	while hq and hq[0] < l:
		heappop(hq)
	heappush(hq, r)
	if len(hq) > 2:
		print('NO')
		exit()
print('YES')


n = int(input())
r = [tuple(map(int, input().strip().split())) for i in range(n)]
r.sort()
if n <= 2:
	print('YES')
else:
	(v1, v2) = (r[0][1], r[1][1])
	flag = True
	for i in range(2, n):
		if r[i][0] > v1:
			v1 = r[i][1]
		elif r[i][0] > v2:
			v2 = r[i][1]
		else:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


q = []
counter = 0
n = int(input())
for i in range(n):
	(s, e) = map(int, input().split())
	q.append([s, True])
	q.append([e + 1, False])
q.sort()
for i in range(len(q)):
	if q[i][1]:
		counter += 1
	else:
		counter -= 1
	if counter >= 3:
		print('NO')
		exit()
print('YES')


n = int(input())
shows = []
for i in range(n):
	shows.append([int(x) for x in input().split()])
shows = sorted(shows, key=lambda tup: tup[0])

def fit(show, tv):
	if show[1] < tv[0] or show[0] > tv[1]:
		return True
	return False

def main():
	if n < 2:
		print('YES')
		return
	tv1 = shows[0]
	tv2 = shows[1]
	for show in shows[2:]:
		if fit(show, tv1):
			tv1 = show
		elif fit(show, tv2):
			tv2 = show
		else:
			print('NO')
			return
	print('YES')
	return
main()


from sys import *
input = stdin.readline
n = int(input())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
l.sort()
f = 0
(x, y) = (-1, -1)
for i in range(n):
	if l[i][0] > x:
		x = l[i][1]
	elif l[i][0] > y:
		y = l[i][1]
	else:
		f = 1
		break
if f == 1:
	print('NO')
else:
	print('YES')


n = int(input())
line = list()
for i in range(n):
	line.append(list(map(int, input().split())))
line.sort()
tv_1 = [-1, -1]
tv_2 = [-1, -1]
b = True
for elem in line:
	if tv_1[1] < elem[0]:
		tv_1 = elem
	elif tv_2[1] < elem[0]:
		tv_2 = elem
	else:
		b = False
		break
print('YES' if b else 'NO')


def lol(a):
	c = 0
	for x in a:
		if x[1] == 1:
			c += 1
		else:
			c -= 1
		if c >= 3:
			return 0
	return 1
n = int(input())
a = []
for _ in range(n):
	(x, y) = map(int, input().split())
	a.append([x, 1])
	a.append([y, 2])
a = sorted(a)
print('YES' if lol(a) else 'NO')


import sys
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
a = sorted(a)
count = 0
c1 = c2 = -1
for i in a:
	if i[0] > c1:
		c1 = i[1]
	elif i[0] > c2:
		c2 = i[1]
	else:
		print('NO')
		sys.exit()
print('YES')


n = int(input())
x = []
for i in range(n):
	(l, r) = map(int, input().split())
	x.append((l, 1))
	x.append((r, -1))
x.sort(key=lambda x: (x[0], -x[1]))
s = 0
for i in range(len(x)):
	s += x[i][1]
	if s == 3:
		print('NO')
		exit()
print('YES')


from collections import defaultdict
n = int(input())
times = defaultdict(lambda : 0)
for _ in range(n):
	(start, end) = map(int, input().split(' '))
	times[start] += 1
	times[end + 1] -= 1
cur_time = 0
for time in sorted(times.keys()):
	cur_time += times[time]
	if cur_time > 2:
		print('NO')
		break
else:
	print('YES')


n = int(input())
shows = []
for i in range(n):
	show = list(map(int, input().split()))
	shows.append(show)
shows = sorted(shows)
t = [-1, -1]
ok = True
for show in shows:
	if show[0] > t[0]:
		t[0] = show[1]
	elif show[0] > t[1]:
		t[1] = show[1]
	else:
		ok = False
		break
if ok:
	print('YES')
else:
	print('NO')


n = int(input())

def conflicts(a, b):
	return a[1] >= b[0]
shows = []
for i in range(n):
	(x, y) = map(int, input().split())
	shows.append((x, y))
shows.sort(key=lambda x: x[0])
ok = True
tv1 = [(-1, -1)]
tv2 = [(-1, -1)]
for s in shows:
	if not conflicts(tv1[-1], s):
		tv1.append(s)
	elif not conflicts(tv2[-1], s):
		tv2.append(s)
	else:
		ok = False
		break
if ok:
	print('YES')
else:
	print('NO')


n = int(input())
pr = []
flag = True
for i in range(n):
	pr.append(tuple(map(int, input().split())))
pr.sort()
(tel1, tel2) = (-1, -1)
flag = True
for i in range(n):
	if tel1 < pr[i][0]:
		tel1 = pr[i][1]
	elif tel2 < pr[i][0]:
		tel2 = pr[i][1]
	else:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


import sys
n = int(input())
shows = []
for i in range(n):
	lis = list(map(int, input().split()))
	shows.append(lis)
if n > 2:
	tv1 = []
	tv2 = []
	shows.sort()
	tv1.append(shows[0])
	tv2.append(shows[1])
	i = 2
	while i < n:
		if shows[i][0] > tv1[len(tv1) - 1][1]:
			tv1.append(shows[i])
		elif shows[i][0] > tv2[len(tv2) - 1][1]:
			tv2.append(shows[i])
		else:
			print('NO')
			sys.exit()
		i += 1
	print('YES')
else:
	print('YES')


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list()
for i in range(n):
	(l, r) = map(int, input().split())
	a.append((l, r))
a.sort()
tv1 = -1
tv2 = -1
ch = 1
for i in range(n):
	if a[i][0] > tv1:
		tv1 = a[i][1]
	elif a[i][0] > tv2:
		tv2 = a[i][1]
	else:
		ch = 0
		break
if ch == 1:
	print('YES')
else:
	print('NO')


n = int(input())
vec = []
for _ in range(n):
	(a, b) = [int(x) for x in input().split()]
	vec.append([a, b])
vec.sort()
f1 = f2 = 0
flag1 = flag2 = True
flag = 'YES'
for item in vec:
	if f1 <= f2:
		if flag1:
			f1 = item[1]
			flag1 = False
		elif item[0] > f1:
			f1 = item[1]
		else:
			flag = 'NO'
			break
	elif flag2:
		f2 = item[1]
		flag2 = False
	elif item[0] > f2:
		f2 = item[1]
	else:
		flag = 'NO'
		break
print(flag)


n = int(input())
shows = []
for i in range(n):
	(l, r) = map(int, input().split())
	shows.append((l, r))
shows.sort()
(a_endtime, b_endtime) = (-1, -1)
for show in shows:
	if show[0] <= a_endtime:
		print('NO')
		break
	else:
		a_endtime = show[1]
		if a_endtime > b_endtime:
			(a_endtime, b_endtime) = (b_endtime, a_endtime)
else:
	print('YES')


import sys
input = sys.stdin.readline
n = int(input())
lr = [tuple(map(int, input().split())) for _ in range(n)]
lr.sort(key=lambda k: k[0])
(t1, t2) = (-1, -1)
for (l, r) in lr:
	if t1 < l:
		t1 = r
	elif t2 < l:
		t2 = r
	else:
		print('NO')
		exit()
print('YES')


import sys
count = 0
lesson_list = []
for line in sys.stdin:
	if count == 0:
		num = int(line.strip())
		count += 1
		continue
	start = int(line.strip().split(' ')[0])
	end = int(line.strip().split(' ')[1])
	lesson_list.append((start, end))
lesson_list.sort()
a_status = True
b_status = True
a_time = 0
b_time = 0
flag = 0
for tmp in lesson_list:
	start = tmp[0]
	end = tmp[1]
	if start < a_time and start < b_time:
		flag = -1
		break
	if start >= a_time:
		a_time = end + 1
		continue
	b_time = end + 1
if flag < 0:
	print('NO')
else:
	print('YES')


n = int(input())
tv1 = (-5, -5)
tv2 = (-5, -5)
flag = True
a = []
for i in range(n):
	a.append([int(x) for x in input().split()])
a.sort()
for (l, r) in a:
	if tv1[1] < l:
		tv1 = (l, r)
	elif tv2[1] < l:
		tv2 = (l, r)
	else:
		flag = False
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append((x, y))
a.sort()
tv1 = -1
tv2 = -1
f = 1
for i in range(n):
	if tv1 < a[i][0]:
		tv1 = a[i][1]
	elif tv2 < a[i][0]:
		tv2 = a[i][1]
	else:
		f = 0
		break
if f:
	print('YES')
else:
	print('NO')


from collections import defaultdict
from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
n = int(input())
p = defaultdict(int)
for i in range(n):
	(a, b) = rint()
	p[a] += 1
	p[b + 1] -= 1
pl = []
for k in p.keys():
	pl.append((k, p[k]))
pl.sort()
sum = 0
for i in range(len(pl)):
	sum += pl[i][1]
	if sum > 2:
		print('NO')
		exit()
print('YES')


n = int(input())
tv1 = -1
tv2 = -1
a = []
d = False
for _ in range(n):
	a.append(tuple((int(x) for x in input().split())))
a.sort()
for (b, c) in a:
	if tv1 < b:
		tv1 = c
	elif tv2 < b:
		tv2 = c
	else:
		d = True
if d == False:
	print('YES')
else:
	print('NO')


n = int(input())
arr = []
for i in range(n):
	(a, b) = map(int, input().split())
	arr.append((a, 1))
	arr.append((b + 1, -1))
arr.sort()
sum = 0
for (a, b) in arr:
	sum += b
	if sum > 2:
		print('NO')
		exit(0)
print('YES')


def main(d, t):
	for i in d:
		t += i[1]
		if t < -2:
			return 'NO'
	return 'YES'
d = []
n = int(input())
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	d.append([a, -1])
	d.append([b, 1])
d.sort()
t = 0
ans = main(d, t)
print(ans)


n = int(input())
shows = [tuple(map(int, input().split())) for _ in range(n)]
shows = sorted(shows, key=lambda t: t[1])
shows = sorted(shows, key=lambda t: t[0])
(first, second) = (-1, -1)
for (l, r) in shows:
	if l > first:
		first = r
	elif l > second:
		second = r
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
shows = []
for i in range(n):
	(l, r) = map(int, input().split())
	shows.append((l, r))
shows = sorted(shows)
fst_tv = []
snd_tv = []
printed = False
for s in shows:
	if fst_tv == []:
		fst_tv.append(s)
	elif snd_tv == []:
		snd_tv.append(s)
	elif s[0] > fst_tv[-1][1] and s[0] > snd_tv[-1][1]:
		fst_tv.append(s)
	elif s[0] <= fst_tv[-1][1] and s[0] > snd_tv[-1][1]:
		snd_tv.append(s)
	elif s[0] <= snd_tv[-1][1] and s[0] > fst_tv[-1][1]:
		fst_tv.append(s)
	else:
		print('NO')
		printed = True
		break
if not printed:
	print('YES')


count = int(input())
shows = []
impossible = False
showing = 0
for i in range(count):
	show = input().split(' ')
	shows.append([int(show[0]), 1])
	shows.append([int(show[1]) + 1, -1])
shows.sort(key=lambda iterableShow: iterableShow[0] * 3 + iterableShow[1])
for i in range(count * 2):
	showing += shows[i][1]
	if showing > 2:
		print('NO')
		impossible = True
		break
if not impossible:
	print('YES')


def Main():
	timesheet = {}
	n = int(input())
	while n > 0:
		p = list(map(int, input().split()))
		if timesheet.get(p[0], -1) == -1:
			timesheet[p[0]] = [p[1]]
		else:
			timesheet[p[0]].append(p[1])
		n -= 1
	times = sorted(list(timesheet.keys()))
	(t1, t2, res) = (0, 0, 'YES')
	for t in times:
		timeline = timesheet.get(t)
		for tl in timeline:
			if t1 < t or t1 == 0:
				t1 = tl
			elif t2 < t or t2 == 0:
				t2 = tl
			else:
				res = 'NO'
				break
		if res == 'NO':
			break
	print(res)
Main()


tv1 = -1
tv2 = -1
shows = []
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	shows.append((l, r))
shows.sort(key=lambda x: x[0])
for (l, r) in shows:
	if tv1 < l:
		tv1 = r
	elif tv2 < l:
		tv2 = r
	else:
		print('NO')
		break
else:
	print('YES')


shows = int(input())
tv1 = []
tv2 = []
horarios = []
for i in range(shows):
	horario = [*map(int, input().split())]
	horarios.append(horario)
horarios.sort(key=lambda x: x[0])
possible = 'YES'
for horario in horarios:
	if len(tv1) == 0:
		tv1.append(horario)
	elif len(tv2) == 0:
		tv2.append(horario)
	elif tv1[-1][1] < horario[0]:
		tv1.append(horario)
	elif tv2[-1][1] < horario[0]:
		tv2.append(horario)
	else:
		possible = 'NO'
		break
print(possible)


n = int(input())
D = []
for i in range(n):
	(l, r) = map(int, input().split())
	D.append((l, -1))
	D.append((r, 1))
D.sort()
ans = 0
uu = True
for (o, t) in D:
	ans += t
	if ans < -2:
		print('NO')
		uu = False
		break
if uu == True:
	print('YES')