There are $n$ rectangles in a row. You can either turn each rectangle by $90$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.

Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such). 


-----Input-----

The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of rectangles.

Each of the next $n$ lines contains two integers $w_i$ and $h_i$ ($1 \leq w_i, h_i \leq 10^9$) — the width and the height of the $i$-th rectangle.


-----Output-----

Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO".

You can print each letter in any case (upper or lower).


-----Examples-----
Input
3
3 4
4 6
3 5

Output
YES

Input
2
3 4
5 5

Output
NO



-----Note-----

In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].

In the second test, there is no way the second rectangle will be not higher than the first one.

Difficulty: EASY
Tags: Sorting

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
n = int(input())
st = input()
q = 1
x = max(int(st.split()[0]), int(st.split()[1]))
for i in range(n - 1):
	st = input()
	if int(st.split()[0]) <= x or int(st.split()[1]) <= x:
		q += 1
		if max(int(st.split()[0]), int(st.split()[1])) <= x:
			x = max(int(st.split()[0]), int(st.split()[1]))
		else:
			x = min(int(st.split()[0]), int(st.split()[1]))
	else:
		print('NO')
		break
if q == n:
	print('YES')


n = int(input())
prev_num = max([int(x) for x in input().split(' ')])
br = False
for i in range(n - 1):
	this = [int(x) for x in input().split(' ')]
	if min(this) <= prev_num:
		if max(this) <= prev_num:
			prev_num = max(this)
		else:
			prev_num = min(this)
	else:
		br = True
		break
if br:
	print('NO')
else:
	print('Yes')


n = int(input())
last = float('inf')
flag = 1
for i in range(n):
	(w, h) = map(int, input().split())
	if flag and max(w, h) <= last:
		last = max(w, h)
	elif flag:
		if min(w, h) > last:
			flag = 0
		else:
			last = min(w, h)
if flag == 1:
	print('YES')
else:
	print('NO')


h = 10 ** 10
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b <= h:
		h = b
	elif a <= h:
		h = a
	else:
		print('NO')
		exit(0)
print('YES')


n = int(input())
prev = max(list(map(int, input().split())))
for i in range(n - 1):
	(a, b) = list(map(int, input().split()))
	if max(a, b) <= prev:
		prev = max(a, b)
	elif min(a, b) <= prev:
		prev = min(a, b)
	else:
		print('NO')
		break
else:
	print('YES')


s = int(input())
(a, b) = map(int, input().split())
if a > b:
	(a, b) = (b, a)
m = b
f = False
for i in range(s - 1):
	(a, b) = map(int, input().split())
	if a >= b:
		(a, b) = (b, a)
	if b <= m:
		m = b
		continue
	if a <= m:
		m = a
		continue
	f = True
if f:
	print('NO')
else:
	print('YES')


import math as ma
from sys import exit
from decimal import Decimal as dec

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())
n = nu()
a = 0
b = 0
flag = True
for i in range(n):
	(w, h) = num()
	if i == 0:
		a = max(h, w)
		b = min(h, w)
	elif max(h, w) <= a:
		a = max(h, w)
		b = min(h, w)
	elif min(h, w) <= a:
		b = max(h, w)
		a = min(h, w)
	else:
		flag = False
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
pre = 1 << 32
for i in range(n):
	a = list(map(int, input().split()))
	x = a[0]
	y = a[1]
	if max(x, y) <= pre:
		pre = max(x, y)
	elif min(x, y) <= pre:
		pre = min(x, y)
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
f = 1
m = 1000000001
for i in range(0, n):
	(w, h) = map(int, input().split(' '))
	m1 = max(w, h)
	m2 = min(w, h)
	if m1 <= m:
		m = m1
	elif m2 <= m:
		m = m2
	else:
		f = 0
		break
if f == 1:
	print('YES')
else:
	print('NO')


n = int(input())
m = 1000000001
for i in range(n):
	s = input()
	(a, b) = s.split(' ')
	a = int(a)
	b = int(b)
	ma = max(a, b)
	mb = min(a, b)
	if ma <= m:
		m = ma
		continue
	elif mb <= m:
		m = mb
		continue
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
dimensions = []
flag = 1
while n > 0:
	dimensions.append(list(map(int, input().split())))
	n -= 1
maximum = max(dimensions[0])
for i in range(1, len(dimensions)):
	if maximum >= max(dimensions[i]):
		maximum = max(dimensions[i])
		continue
	elif maximum >= min(dimensions[i]):
		maximum = min(dimensions[i])
		continue
	else:
		flag = 0
		break
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
prev = 999999999999
for i in range(n):
	x = list(map(int, input().split()))
	if max(x) <= prev:
		prev = max(x)
	elif min(x) <= prev:
		prev = min(x)
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
x = 10 ** 10
for i in range(n):
	(w, h) = sorted([int(x) for x in input().split()])
	if h <= x:
		x = h
	elif w <= x:
		x = w
	else:
		print('NO')
		exit()
print('YES')


from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from collections import defaultdict
import math
cin = stdin.readline

def cout(x):
	stdout.write(str(x) + '\n')

def nexint():
	return int(stdin.readline())

def readline():
	return map(int, stdin.readline().split())

def readlist():
	return list(map(int, stdin.readline().split()))

def sorted_indexes(arr):
	return sorted(range(len(arr)), key=arr.__getitem__)

def printr(arr):
	[stdout.write(str(x) + ' ') for x in arr]
	cout('')

def find_lt(a, x):
	i = bisect_left(a, x)
	if i:
		return a[i - 1]
	raise ValueError

def find_gt(a, x):
	i = bisect_right(a, x)
	if i != len(a):
		return a[i]
	raise ValueError
n = nexint()
a = [0] * n
for i in range(n):
	a[i] = readlist()
b = [0] * n
b[0] = max(a[0][0], a[0][1])
brk = False
for i in range(1, n):
	if a[i][0] > b[i - 1] and a[i][1] > b[i - 1]:
		brk = True
		break
	elif a[i][0] <= b[i - 1] and a[i][1] > b[i - 1]:
		b[i] = a[i][0]
	elif a[i][0] > b[i - 1] and a[i][1] <= b[i - 1]:
		b[i] = a[i][1]
	else:
		b[i] = max(a[i][0], a[i][1])
if brk:
	cout('NO')
else:
	cout('YES')


n = int(input())
x = 10 ** 9
for _ in [0] * n:
	(w, h) = sorted(map(int, input().split()))
	x = h if h <= x else w if w <= x else 0
print(('NO', 'YES')[x > 0])


def func():
	prev = 0
	for i in range(int(input())):
		a = list(map(int, input().split()))
		if i == 0:
			prev = max(a)
		elif max(a) <= prev:
			prev = max(a)
		elif min(a) <= prev:
			prev = min(a)
		else:
			print('NO')
			return
	print('YES')
func()


a = int(input())
b = [int(x) for x in input().split()]
c = max(b)
count = 1
for i in range(a - 1):
	d = [int(x) for x in input().split()]
	if min(d[0], d[1]) > c:
		print('NO')
		break
	elif d[0] > c:
		c = d[1]
	elif d[1] > c:
		c = d[0]
	elif d[0] <= c and d[1] <= c:
		c = max(d[0], d[1])
	count += 1
if count == a:
	print('YES')


import sys
import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base=3):
	newnumber = ''
	while number > 0:
		newnumber = str(number % base) + newnumber
		number //= base
	return newnumber
n = ii()
(w, h) = mi()
t = max(w, h)
for i in range(n - 1):
	(w, h) = mi()
	if t >= max(w, h):
		t = max(w, h)
	elif t >= min(w, h):
		t = min(w, h)
	else:
		exit(print('NO'))
print('YES')


n = int(input())
p = []
flag = True
q = []
for i in range(n):
	(x, y) = map(int, input().split())
	p.append((x, y))
q.append(max(p[0][0], p[0][1]))
for i in range(1, n):
	if q[i - 1] >= p[i][0] and q[i - 1] < p[i][1]:
		q.append(p[i][0])
	elif q[i - 1] < p[i][0] and q[i - 1] >= p[i][1]:
		q.append(p[i][1])
	elif q[i - 1] >= p[i][0] and q[i - 1] >= p[i][1]:
		q.append(max(p[i][1], p[i][0]))
	else:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
r = []
maxm = []
minm = []
flag = 1
for i in range(0, n):
	s = input()
	s = list(s.split(' '))
	mxm = max(int(s[0]), int(s[1]))
	mnm = min(int(s[0]), int(s[1]))
	maxm.append(mxm)
	minm.append(mnm)
for i in range(0, n - 1):
	if maxm[i] < maxm[i + 1]:
		maxm[i + 1] = minm[i + 1]
		if maxm[i] < maxm[i + 1]:
			flag = 0
			break
		else:
			continue
	else:
		continue
if flag == 0:
	print('NO')
else:
	print('YES')


n = int(input())
temp = n
(b, h) = input().split()
h1 = max(int(b), int(h))
while n > 1:
	(b, h) = input().split()
	(b, h) = (int(b), int(h))
	if b <= h1 and h <= h1:
		if h1 - b > h1 - h:
			h1 = h
		else:
			h1 = b
	elif b <= h1:
		h1 = b
	elif h <= h1:
		h1 = h
	else:
		print('NO')
		exit()
	n = n - 1
print('YES')


n = int(input())
check = True
wtf = max(map(int, input().split()))
for i in range(n - 1):
	(x, y) = map(int, input().split())
	if wtf < min(x, y):
		check = False
		break
	if max(x, y) <= wtf:
		wtf = max(x, y)
	else:
		wtf = min(x, y)
if check:
	print('Yes')
else:
	print('No')


n = int(input())
ans = 'YES'
a = int(1000000000.0)
for _ in range(n):
	(h, w) = map(int, input().split())
	if max(h, w) <= a:
		a = max(h, w)
	elif min(h, w) <= a:
		a = min(h, w)
	else:
		ans = 'NO'
print(ans)


n = int(input())
arr = []
for i in range(n):
	arr.append([int(i) for i in input().split()])
up = max(arr[0][1], arr[0][0])
flag = True
for i in range(1, n):
	(curmax, curmin) = [arr[i][0], arr[i][1]] if arr[i][0] >= arr[i][1] else [arr[i][1], arr[i][0]]
	if curmax <= up:
		up = curmax
	elif curmin <= up:
		up = curmin
	else:
		flag = False
if flag:
	print('YES')
else:
	print('NO')


import sys, collections
n = int(sys.stdin.readline())
now = 0
can = True
for i in range(n):
	(a, b) = map(int, sys.stdin.readline().split())
	if i == 0:
		now = max(a, b)
	elif max(a, b) <= now:
		now = max(a, b)
	elif min(a, b) <= now:
		now = min(a, b)
	else:
		can = False
		break
print('YES' if can else 'NO')


n = int(input())
rect = []
for i in range(n):
	w = [int(x) for x in input().split()]
	rect.append(w)
sequnc = []
sequnc.append(max(rect[0]))
for i in range(1, n):
	if max(rect[i]) <= sequnc[-1]:
		sequnc.append(max(rect[i]))
	elif min(rect[i]) <= sequnc[-1]:
		sequnc.append(min(rect[i]))
	else:
		break
if len(sequnc) != n:
	print('NO')
else:
	print('YES')


n = int(input())
tall = []
for i in range(n):
	(a, b) = map(int, input().split())
	tall.append([a, b])
check = True
now = max(tall[0])
for i in range(1, n):
	if tall[i][0] <= now and tall[i][1] <= now:
		now = max(tall[i])
	elif tall[i][0] <= now:
		now = tall[i][0]
	elif tall[i][1] <= now:
		now = tall[i][1]
	else:
		check = False
if check:
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for _ in range(n):
	(w, h) = map(int, input().split())
	if w < h:
		(w, h) = (h, w)
	a.append((w, h))
H = max(a[0])
valid = True
for i in range(1, n):
	if a[i][0] <= H:
		H = a[i][0]
	elif a[i][1] <= H:
		H = a[i][1]
	else:
		valid = False
		break
print('YES' if valid else 'NO')


n = int(input())
rects = []
for i in range(n):
	inp = list(map(int, input().split()))
	inp.sort()
	rects.append(inp)
prev = max(rects[0])
ans = 'YES'
for i in range(1, len(rects)):
	if rects[i][1] <= prev:
		prev = rects[i][1]
	elif rects[i][0] <= prev:
		prev = rects[i][0]
	else:
		ans = 'NO'
		break
print(ans)


n = int(input().strip())
width = []
height = []
ans = True
for i in range(n):
	(w, h) = map(int, input().strip().split())
	if ans:
		if i == 0:
			prev = max(w, h)
		else:
			mx = max(w, h)
			mn = w + h - mx
			if mx <= prev:
				prev = mx
			elif mx > prev and mn <= prev:
				prev = mn
			else:
				ans = False
if ans:
	print('YES')
else:
	print('NO')


n = int(input())
rectangles = []
(w1, h1) = map(int, input().split())
maxl = max(w1, h1)
res = True
for _ in range(n - 1):
	(w, h) = list(map(int, input().split()))
	if res:
		m = max(w, h)
		if m <= maxl:
			maxl = m
		else:
			m = min(w, h)
			if m <= maxl:
				maxl = m
			else:
				res = False
	else:
		del w
		del h
if res:
	print('YES')
else:
	print('NO')


n = int(input())
(h, w) = map(int, input().split())
hi = [max(h, w)]
for i in range(n - 1):
	(h, w) = map(int, input().split())
	if max(h, w) <= hi[i]:
		hi.append(max(h, w))
	else:
		hi.append(min(h, w))
print('YES' if sorted(hi, reverse=True) == hi else 'NO')


n = int(input())
W = []
H = []
temp = 0
flag = 0
for i in range(n):
	WH = input().split()
	(w, h) = (int(WH[0]), int(WH[1]))
	W.append(w)
	H.append(h)
if W[0] > H[0]:
	(H[0], W[0]) = (W[0], H[0])
for i in range(len(H) - 1):
	if i == 0:
		pass
	elif W[i] > H[i]:
		if H[i - 1] >= W[i]:
			(H[i], W[i]) = (W[i], H[i])
		else:
			pass
	if H[i] >= H[i + 1]:
		pass
	elif W[i + 1] < H[i + 1]:
		(H[i + 1], W[i + 1]) = (W[i + 1], H[i + 1])
	if H[i] >= H[i + 1]:
		pass
	else:
		flag = 1
		break
for i in range(len(H) - 1):
	if H[i] < H[i + 1]:
		flag = 1
		break
if flag == 0:
	print('YES')
else:
	print('NO')


import sys

def main():
	n = int(input().strip())
	rectangles = []
	for _ in range(n):
		string = input().strip()
		rectangles.append(tuple(map(int, string.split())))
	prev_height = max(rectangles[0])
	for i in range(1, len(rectangles)):
		if min(rectangles[i]) > prev_height:
			print('NO')
			return 0
		if max(rectangles[i]) <= prev_height:
			prev_height = max(rectangles[i])
		else:
			prev_height = min(rectangles[i])
	print('YES')
	return 0

def test(i):
	with open('test_{}.txt'.format(i)) as fin:
		sys.stdin = fin
		main()
sys.exit(main())


n = int(input())
(a, b) = input().split(' ')
(a, b) = (int(a), int(b))
m = max(a, b)
bol = True
for i in range(n - 1):
	(x, y) = input().split(' ')
	(x, y) = (int(x), int(y))
	if max(x, y) <= m:
		m = max(x, y)
	elif min(x, y) <= m:
		m = min(x, y)
	else:
		bol = False
if bol:
	print('YES')
else:
	print('NO')


n = int(input())
l = 10 ** 9
for _ in range(n):
	(w, h) = map(int, input().split())
	(t1, t2) = (min(w, h), max(w, h))
	if t2 <= l:
		l = t2
	elif t1 <= l:
		l = t1
	else:
		print('NO')
		exit()
print('YES')


n = input()
n = int(n)
curr = 1000000000
result = True
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if curr >= a and curr >= b:
		if a >= b:
			curr = a
		else:
			curr = b
	elif curr >= a:
		curr = a
	elif curr >= b:
		curr = b
	else:
		result = False
		break
if result == True:
	print('YES')
else:
	print('NO')


n = int(input())
val = 1000000001
ans = 1
i = 0
while i < n:
	(w, h) = input().split()
	w = int(w)
	h = int(h)
	if w <= val and h <= val:
		val = max(w, h)
	elif w <= val:
		val = w
	elif h <= val:
		val = h
	else:
		ans = 0
		break
	i += 1
if ans == 1:
	print('YES')
else:
	print('NO')


n = int(input())
arr = [list(map(int, input().split())) for i in range(n)]
curr = max(arr[0])
possible = True
for i in range(1, n):
	if max(arr[i]) <= curr:
		curr = max(arr[i])
	elif min(arr[i]) > curr:
		possible = False
		break
	else:
		curr = min(arr[i])
print('YES' if possible else 'NO')


tedad = int(input())
width = tedad * [0]
height = tedad * [0]
f = 'YES'
for i in range(tedad):
	(width[i], height[i]) = [int(i) for i in input().split()]
last_selected = max(height[0], width[0])
for i in range(1, tedad):
	if max(height[i], width[i]) <= last_selected:
		last_selected = max(height[i], width[i])
	elif min(height[i], width[i]) <= last_selected:
		last_selected = min(height[i], width[i])
	else:
		f = 'NO'
		break
print(f)


n = int(input())
s = []
(a, b) = map(int, input().split())
s.append(max(a, b))
for i in range(1, n):
	(a, b) = map(int, input().split())
	if max(a, b) <= s[i - 1]:
		s.append(max(b, a))
	elif min(a, b) <= s[i - 1]:
		s.append(min(a, b))
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
prev = 10 ** 9 + 1
ans = 'YES'
for _ in range(n):
	(w, h) = map(int, input().split())
	if w > h:
		(w, h) = (h, w)
	if h <= prev:
		prev = h
	elif w <= prev:
		prev = w
	else:
		ans = 'NO'
print(ans)


n = int(input())
m = -1
chk = True
for i in range(n):
	if i == 0:
		m = max(list(map(int, input().split())))
	else:
		l = list(map(int, input().split()))
		if not chk:
			break
		m1 = max(l)
		m2 = min(l)
		if m1 <= m:
			m = m1
		elif m2 <= m:
			m = m2
		else:
			chk = False
if chk:
	print('Yes')
else:
	print('No')


n = int(input())
a = []
for i in range(n):
	a.append([int(i) for i in input().split()])

def f(a):
	b = [100000000000]
	for i in a:
		if b[-1] >= max(i):
			b.append(max(i))
		elif b[-1] >= min(i):
			b.append(min(i))
		else:
			return 0
	return b[::-1] == sorted(b)
print(['NO', 'YES'][f(a)])


n = int(input())
check = True
for i in range(n):
	pair = list(map(int, input().split()))
	if i == 0:
		last = max(pair)
	elif max(pair) <= last:
		last = max(pair)
	elif min(pair) <= last:
		last = min(pair)
	else:
		print('NO')
		check = False
		break
if check:
	print('YES')


x = input()
x = int(x)
c = 0
m = 1
w = 0
k = 0
for i in range(x):
	a = list(map(int, input().split()))
	k += 1
	if k == 1:
		m = max(a)
	if max(a) <= m:
		m = max(a)
		c += 1
	elif min(a) <= m:
		m = min(a)
		c += 1
	else:
		break
if c == x:
	print('YES')
else:
	print('NO')


n = int(input())
a = [input().split() for i in range(n)]
res = 'YES'
prv = 1234567890
for x in a:
	mn = min(int(x[0]), int(x[1]))
	mx = max(int(x[0]), int(x[1]))
	if prv < mn:
		res = 'NO'
	prv = mx if mx <= prv else mn
print(res)


def do():
	t = int(input())
	a = [int(x) for x in input().split()]
	cmax = max(a)
	for _ in range(t - 1):
		a = [int(x) for x in input().split()]
		if cmax >= max(a):
			cmax = max(a)
		elif cmax >= min(a):
			cmax = min(a)
		else:
			print('NO')
			return
	print('YES')
do()


n = int(input())
(w, h) = map(int, input().split())
r = max(w, h)
t = True
for i in range(n - 1):
	(w, h) = map(int, input().split())
	c = max(w, h)
	d = min(w, h)
	if r >= c:
		r = max(w, h)
	elif r >= d:
		r = min(w, h)
	elif r < w and r < h:
		t = False
if t == False:
	print('NO')
else:
	print('YES')


def turning_rectangles(n, a):
	a = a[::-1]
	prev = 0
	for (w, h) in a:
		if min(w, h) >= prev:
			prev = min(w, h)
		elif max(w, h) >= prev:
			prev = max(w, h)
		else:
			return 'NO'
	return 'YES'
n = int(input())
a = []
for x in range(n):
	a.append(list(map(int, input().split())))
print(turning_rectangles(n, a))


max = 10 ** 10
n = int(input())
for _ in range(n):
	(w, h) = map(int, input().split())
	if w > h:
		(w, h) = (h, w)
	if h <= max:
		max = h
	elif w <= max:
		max = w
	else:
		print('NO')
		exit(0)
print('YES')


n = int(input())
f = 0
for i in range(n):
	if i == 0:
		(a, b) = map(int, input().split())
		mini = max(a, b)
	else:
		(a, b) = map(int, input().split())
		if a <= mini and b <= mini:
			mini = max(a, b)
		elif a <= mini:
			mini = a
		elif b <= mini:
			mini = b
		else:
			f = 1
if f == 1:
	print('NO')
else:
	print('YES')


n = int(input())
l = []
for i in range(n):
	(x, y) = [int(i) for i in input().split(' ')]
	l.append(sorted([x, y]))
m = [l[0][1]]
c = 1
for i in range(1, n):
	if l[i][1] <= m[-1]:
		m.append(l[i][1])
	elif l[i][0] <= m[-1]:
		m.append(l[i][0])
	else:
		print('NO')
		c = 0
		break
if c:
	print('YES')


n = int(input())
c = True
s = []
for i in range(n):
	(a, b) = sorted(map(int, input().split()))
	s.append((a, b))
for i in range(n - 1):
	if s[i][1] < s[i + 1][0]:
		c = False
		break
	elif s[i][1] < s[i + 1][1]:
		s[i + 1] = [s[i + 1][1], s[i + 1][0]]
if c:
	print('YES')
else:
	print('NO')


from sys import stdin, stdout
t = 1
for _ in range(t):
	n = int(input())
	vals = []
	for i in range(n):
		(a, b) = map(int, input().split())
		vals.append((a, b))
	ans = 'YES'
	s = max(vals[0][0], vals[0][1])
	for i in range(1, n):
		x = min(vals[i][0], vals[i][1])
		y = max(vals[i][0], vals[i][1])
		if x > s:
			ans = 'NO'
			break
		if y <= s:
			s = y
		else:
			s = x
	print(ans)


import math
from collections import defaultdict

def input_ints():
	return list(map(int, input().split()))

def solve():
	n = int(input())
	x = 10 ** 10
	for i in range(n):
		a = sorted(input_ints())
		if a[1] <= x:
			x = a[1]
		elif a[0] <= x:
			x = a[0]
		else:
			print('NO')
			return
	print('YES')
solve()


total = int(input())
first = map(int, input().split(' '))
prev = max(first)
for x in range(total - 1):
	curr = [int(x) for x in input().split(' ')]
	if curr[0] > curr[1]:
		(a, b) = (curr[0], curr[1])
	else:
		(a, b) = (curr[1], curr[0])
	if a <= prev:
		prev = a
	elif b <= prev:
		prev = b
	else:
		print('NO')
		break
else:
	print('YES')


from math import ceil
t = 1
for test in range(t):
	n = int(input())
	a = []
	x = 0
	y = 0
	for i in range(n):
		(x, y) = map(int, input().split())
		a.append((x, y))
	prev = 1000000001
	ans = 'YES'
	for i in a:
		if max(i) <= prev:
			prev = max(i)
		elif min(i) <= prev:
			prev = min(i)
		else:
			ans = 'NO'
			break
	print(ans)


n = int(input())
(x, y) = map(int, input().split())
z = max(x, y)
a = 1
for i in range(n - 1):
	(x, y) = map(int, input().split())
	b = max(x, y)
	if x == b:
		if z >= x:
			z = b
		elif z >= y:
			z = y
		else:
			a = 0
			break
	elif z >= y:
		z = b
	elif z >= x:
		z = x
	else:
		a = 0
		break
if a == 1:
	print('YES')
else:
	print('NO')


import sys

def Decision(a):
	h = max(a[0][0], a[0][1])
	w = min(a[0][0], a[0][1])
	a[0] = (w, h)
	Dec = 'YES'
	for i in range(1, len(a)):
		h = max(a[i][0], a[i][1])
		w = min(a[i][0], a[i][1])
		if h <= a[i - 1][1]:
			a[i] = (w, h)
		elif w <= a[i - 1][1]:
			a[i] = (h, w)
		else:
			Dec = 'NO'
			break
	return Dec
n = int(input())
a = []
for i in range(n):
	[w, h] = map(int, input().split())
	a.append((w, h))
print(Decision(a))


n = int(input())
ans = 'YES'
pre_h = 10 ** 10
for i in range(n):
	(w, h) = map(int, input().split())
	if h > pre_h:
		if w > pre_h:
			ans = 'NO'
		else:
			pre_h = w
	elif w <= pre_h:
		pre_h = max(w, h)
	else:
		pre_h = h
print(ans)


n = int(input())
(a, b) = map(int, input().split())
b = max(a, b)
k = 0
for i in range(0, n - 1):
	l = 0
	(c, d) = map(int, input().split())
	if max(c, d) <= b:
		d = max(c, d)
		k = k + 1
		l = l + 1
	elif min(c, d) <= b and l == 0:
		k = k + 1
		d = min(c, d)
	a = c
	b = d
if k == n - 1:
	print('YES')
else:
	print('NO')


(pocCis, vysledok) = (int(input()), 'YES')
l = []
for i in range(pocCis):
	l.append(list(map(int, input().split())))
poslMin = min(l[-1])
for i in range(pocCis - 1):
	if min(l[-(i + 2)]) >= poslMin:
		poslMin = min(l[-(i + 2)])
	elif max(l[-(i + 2)]) >= poslMin:
		poslMin = max(l[-(i + 2)])
	else:
		vysledok = 'NO'
		break
print(vysledok)


n = int(input())
for i in range(n):
	(w, h) = map(int, input().split())
	if i == 0:
		ma = max(w, h)
	else:
		m = max(w, h)
		if m <= ma:
			ma = m
			continue
		m = min(w, h)
		if m <= ma:
			ma = m
			continue
		print('NO')
		exit(0)
print('YES')


a = int(input())
(d, e) = map(int, input().split())
c = max(d, e)
for k in range(1, a):
	(x, y) = map(int, input().split())
	if max(x, y) <= c:
		c = max(x, y)
	elif min(x, y) <= c:
		c = min(x, y)
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
ans = 'YES'
num = 0
for i in range(n):
	(w, h) = map(int, input().split())
	if i == 0:
		num = max(w, h)
	elif max(w, h) <= num:
		num = max(w, h)
	elif min(w, h) <= num:
		num = min(w, h)
	else:
		ans = 'NO'
print(ans)


l = []
bool = True
for _ in range(int(input())):
	l.append(list(map(int, input().split())))
p = max(l[0])
for (x, y) in l[1:]:
	if x <= p and y <= p:
		p = max(x, y)
	elif x <= p:
		p = x
	elif y <= p:
		p = y
	else:
		bool = False
		break
print('YES' if bool else 'NO')


n = int(input())
numbers = [0] * n
(x, y) = map(int, input().split())
numbers[0] = [max(x, y), min(x, y)]
anterior = max(x, y)
ans = 'YES'
for i in range(1, n):
	(x, y) = map(int, input().split())
	if max(x, y) <= anterior:
		numbers[i] = [max(x, y), min(x, y)]
		anterior = max(x, y)
	elif min(x, y) <= anterior:
		numbers[i] = [min(x, y), max(x, y)]
		anterior = min(x, y)
	else:
		ans = 'NO'
print(ans)


n = int(input())
h = [0] * n
w = [0] * n
for i in range(n):
	(h[i], w[i]) = map(int, input().split())
if n == 1:
	print('YES')
	exit(0)
last = h[0]
flag = True
for i in range(1, n):
	if h[i] <= last and w[i] <= last:
		last = max(h[i], w[i])
	elif h[i] <= last:
		last = h[i]
	elif w[i] <= last:
		last = w[i]
	else:
		flag = False
if not flag:
	flag = True
	last = w[0]
	for i in range(1, n):
		if h[i] <= last and w[i] <= last:
			last = max(h[i], w[i])
		elif h[i] <= last:
			last = h[i]
		elif w[i] <= last:
			last = w[i]
		else:
			flag = False
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
top = 10000000000
flag = 1
for i in range(n):
	(x, y) = map(int, input().split())
	if x > y:
		(x, y) = (y, x)
	if x > top:
		flag = 0
	if y <= top:
		top = y
	elif x <= top:
		top = x
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
ph = 1000000010
valid = 'YES'
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	if max(a, b) <= ph:
		ph = max(a, b)
	elif min(a, b) <= ph:
		ph = min(a, b)
	else:
		valid = 'NO'
		break
print(valid)


n = int(input())
h1 = -1
tf = True
for _ in range(n):
	(w, h) = map(int, input().split())
	if h1 == -1:
		h1 = max(w, h)
	else:
		(a, b) = (max(w, h), min(w, h))
		if a <= h1:
			h1 = a
		elif b <= h1:
			h1 = b
		else:
			tf = False
if tf:
	print('YES')
else:
	print('NO')


n = int(input())
s = []
for i in range(n):
	s.append(list(map(int, input().split())))
x = max(s[0][0], s[0][1])
t = True
for i in range(1, n):
	if max(s[i][0], s[i][1]) <= x:
		x = max(s[i][0], s[i][1])
	elif min(s[i][0], s[i][1]) <= x:
		x = min(s[i][0], s[i][1])
	else:
		t = False
if t:
	print('YES')
else:
	print('NO')


flag = 0
for i in range(int(input())):
	(w, h) = [int(x) for x in input().split()]
	if i == 0:
		ht = max(w, h)
	elif (h <= ht or w <= ht) and i > 0:
		if h <= ht and w > ht:
			ht = h
		elif w <= ht and h > ht:
			ht = w
		elif h <= ht and w <= ht:
			ht = max(h, w)
	else:
		flag = 1
if flag:
	print('NO')
else:
	print('YES')


n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	a[i].sort()
cur = a[0][1]
f = True
for i in range(1, n):
	if a[i][1] <= cur:
		cur = a[i][1]
	elif a[i][0] <= cur:
		cur = a[i][0]
	else:
		f = False
		break
if f:
	print('YES')
else:
	print('NO')


n = int(input())
cur_h = 999999999999999999
for i in range(n):
	(h, w) = map(int, input().split())
	if h > cur_h and w > cur_h:
		print('NO')
		exit(0)
	if h > cur_h:
		cur_h = w
	elif w > cur_h:
		cur_h = h
	else:
		cur_h = max(h, w)
print('YES')


n = int(input())
prev = pow(10, 9)
f = 0
while n:
	n -= 1
	(a, b) = map(int, input().split())
	if max(a, b) <= prev:
		prev = max(a, b)
	elif min(a, b) <= prev:
		prev = min(a, b)
	else:
		f = 1
		break
if f:
	print('NO')
else:
	print('YES')


n = int(input())
m = max(map(int, input().split()))
n -= 1
while n:
	n -= 1
	(a, b) = map(int, input().split())
	if b > a:
		(a, b) = (b, a)
	if a <= m:
		m = a
	elif b <= m:
		m = b
	else:
		print('NO')
		quit()
print('YES')


import math
t = int(input())
c = 1001001001
while t > 0:
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b <= c:
		c = b
	elif a <= c:
		c = a
	else:
		print('NO')
		exit(0)
	t -= 1
print('YES')


n = int(input())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
m = max(a[0])
chk = False
for i in range(1, n):
	if max(a[i]) <= m:
		m = max(a[i])
	elif min(a[i]) <= m:
		m = min(a[i])
	else:
		chk = True
		break
if chk:
	print('No')
else:
	print('Yes')


n = int(input())
prev = 10 ** 10
for i in range(n):
	(a, b) = map(int, input().split())
	if max(a, b) <= prev:
		prev = max(a, b)
	elif min(a, b) <= prev:
		prev = min(a, b)
	else:
		print('NO')
		exit(0)
print('YES')


n = eval(input())
last = 10000000000
flag = True
for i in range(n):
	(w, h) = map(eval, input().split())
	if max(w, h) <= last:
		last = max(w, h)
	elif min(w, h) <= last:
		last = min(w, h)
	else:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


def check(l, temp1, temp2):
	temp3 = max(temp1, temp2)
	if l >= temp3:
		return temp3
	elif l >= temp1 + temp2 - temp3:
		return temp1 + temp2 - temp3
	else:
		return 0
n = int(input())
Matrix = [[0 for x in range(2)] for y in range(n)]
for i in range(n):
	(Matrix[i][0], Matrix[i][1]) = map(int, input().split())
l = max(Matrix[0][0], Matrix[0][1])
for i in range(n - 1):
	temp1 = Matrix[i + 1][0]
	temp2 = Matrix[i + 1][1]
	l = check(l, temp1, temp2)
	if l == 0:
		print('NO')
		exit()
print('YES')


numrects = int(input())
lastmax = -1
possible = False
hless = False
wless = False
for i in range(0, numrects):
	(w, h) = map(int, input().split())
	if lastmax == -1 or (h <= lastmax and w <= lastmax):
		possible = True
		if h > w:
			lastmax = h
		else:
			lastmax = w
	elif h <= lastmax and (not w <= lastmax):
		possible = True
		lastmax = h
	elif w <= lastmax and (not h <= lastmax):
		possible = True
		lastmax = w
	else:
		possible = False
		break
if possible:
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for i in range(n):
	(x, y) = [int(i) for i in input().split()]
	wk1 = max(x, y)
	if i != 0:
		if a[i - 1] < min(x, y):
			print('NO')
			quit()
		if wk1 > a[i - 1]:
			wk1 = min(x, y)
	a.append(wk1)
print('YES')


n = int(input())
arr = []
for i in range(n):
	(w, h) = map(int, input().split())
	arr.append([w, h])
if arr[0][1] < arr[0][0]:
	(arr[0][0], arr[0][1]) = (arr[0][1], arr[0][0])
flag = 0
for i in range(1, n):
	one = arr[i]
	two = arr[i - 1]
	if one[1] > two[1]:
		if one[0] <= two[1]:
			(arr[i][1], arr[i][0]) = (arr[i][0], arr[i][1])
		else:
			flag = 1
			break
	elif one[1] <= two[1] and one[0] <= two[1]:
		if one[0] > one[1]:
			(arr[i][0], arr[i][1]) = (arr[i][1], arr[i][0])
if flag == 0:
	print('YES')
else:
	print('NO')


n = int(input())
w = []
h = []
for i in range(n):
	(u, v) = map(int, input().split(' '))
	w.append(u)
	h.append(v)
l = 10000000000
p = 1
for i in range(n):
	if max(h[i], w[i]) <= l:
		l = max(h[i], w[i])
	elif min(h[i], w[i]) <= l:
		l = min(h[i], w[i])
	else:
		p = 0
if p == 0:
	print('NO')
else:
	print('YES')


n = int(input())
l = []
q = []
L = []
Q = []
Y = 0
for i in range(0, n):
	p = input().rstrip().split(' ')
	l.append(int(p[0]))
	q.append(int(p[1]))
	L.append(int(p[0]))
	Q.append(int(p[1]))
A = min(l[0], q[0])
B = max(l[0], q[0])
for i in range(0, len(q)):
	if i == 0:
		q[i] = A
	else:
		t = min(l[i], q[i])
		T = max(l[i], q[i])
		if T <= q[i - 1]:
			q[i] = T
		elif t <= q[i - 1]:
			q[i] = t
		else:
			Y = 1
			break
if Y == 1:
	Y = 0
	for i in range(0, len(Q)):
		if i == 0:
			Q[i] = B
		else:
			t = min(L[i], Q[i])
			T = max(L[i], Q[i])
			if T <= Q[i - 1]:
				Q[i] = T
			elif t <= Q[i - 1]:
				Q[i] = t
			else:
				Y = 1
				break
	if Y == 1:
		print('NO')
	else:
		print('YES')
else:
	print('YES')


import collections
from functools import cmp_to_key
import math
import sys

def getIntList():
	return list(map(int, input().split()))
import bisect
try:
	import numpy
	dprint = print
	dprint('debug mode')
except ModuleNotFoundError:

	def dprint(*args, **kwargs):
		pass

def makePair(z):
	return [(z[i], z[i + 1]) for i in range(0, len(z), 2)]

def memo(func):
	cache = {}

	def wrap(*args):
		if args not in cache:
			cache[args] = func(*args)
		return cache[args]
	return wrap

@memo
def comb(n, k):
	if k == 0:
		return 1
	if n == k:
		return 1
	return comb(n - 1, k - 1) + comb(n - 1, k)
(n,) = getIntList()
tt = 10 ** 20
for i in range(n):
	(a, b) = getIntList()
	m1 = max(a, b)
	m2 = min(a, b)
	if m1 <= tt:
		tt = m1
		continue
	if m2 <= tt:
		tt = m2
	else:
		print('NO')
		sys.exit()
print('YES')


n = int(input())
for i in range(n):
	(w, h) = map(int, input().split())
	if i == 0:
		max1 = max(w, h)
	else:
		max2 = max(w, h)
		if max2 <= max1:
			max1 = max2
			continue
		min1 = min(w, h)
		if min1 <= max1:
			max1 = min1
			continue
		print('NO')
		exit()
print('YES')


a = []
n = int(input())
a.append(max(list(map(int, input().split()))))
for i in range(1, n):
	s = list(map(int, input().split()))
	s.sort()
	a.append(s[1] if a[i - 1] >= s[1] else s[0])
b = sorted(a, reverse=True)
print('YES' if a == b else 'NO')


__author__ = 'Esfandiar'
M = float('inf')
for i in range(int(input())):
	(w, h) = map(int, input().split())
	m = max(w, h)
	if m <= M:
		M = m
	else:
		m = min(w, h)
		if m <= M:
			M = m
		else:
			print('NO')
			exit()
print('YES')


n = int(input())
a = [[0, 0] for x in range(n)]
for i in range(n):
	(a[i][0], a[i][1]) = (int(x) for x in input().split())
flag = 1
prev = min(a[n - 1])
for i in range(n - 2, -1, -1):
	if min(a[i]) >= prev:
		prev = min(a[i])
	elif max(a[i]) >= prev:
		prev = max(a[i])
	else:
		flag = 0
		break
if not flag:
	print('NO')
else:
	print('YES')


n = int(input())
prev_res = 10 ** 10
for _ in range(n):
	(wi, hi) = map(int, input().split())
	(mn, mx) = sorted((wi, hi))
	if mx <= prev_res:
		prev_res = mx
	elif mn <= prev_res:
		prev_res = mn
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
h = []
li = []
temp = 0
for i in range(n):
	a = input().split(' ')
	(a[0], a[1]) = (int(a[0]), int(a[1]))
	h.append(list(a))
if h[0][0] > h[0][1]:
	li.append(h[0][0])
else:
	li.append(h[0][1])
for i in range(len(h) - 1):
	if h[i + 1][0] > h[i + 1][1]:
		if li[i] >= h[i + 1][0]:
			li.append(h[i + 1][0])
		else:
			li.append(h[i + 1][1])
	elif li[i] >= h[i + 1][1]:
		li.append(h[i + 1][1])
	else:
		li.append(h[i + 1][0])
for i in range(len(li) - 1):
	if li[i + 1] > li[i]:
		print('NO')
		temp = 1
		break
if temp == 0:
	print('YES')


def main():
	n = int(input())
	tecmax = max(list(map(int, input().split())))
	for i in range(n - 1):
		(ma, mi) = map(int, input().split())
		if ma < mi:
			(ma, mi) = (mi, ma)
		if ma <= tecmax:
			tecmax = ma
		elif mi <= tecmax:
			tecmax = mi
		else:
			print('NO')
			return
	print('YES')
main()


n = int(input())
flag = False
prev = max(list(map(int, input().split())))
if n != 1:
	for i in range(n - 1):
		dim = list(map(int, input().split()))
		m_dim = max(dim)
		min_dim = min(dim)
		if m_dim <= prev:
			prev = m_dim
		elif min_dim <= prev:
			prev = min_dim
		else:
			print('NO')
			flag = True
			break
if not flag:
	print('YES')


n = int(input())
a = []
for i in range(n):
	(x, tmp) = map(int, input().split())
	a.append(x)
	a[-1] = max(tmp, x)
	if len(a) > 1:
		if a[-1] > a[-2]:
			a[-1] = min(x, tmp)
go = True
last = 12324635786
for i in a:
	if i > last:
		go = False
	last = i
if go:
	print('YES')
else:
	print('NO')


n = int(input())
l = []
for i in range(n):
	(w, h) = map(int, input().split())
	l.append([w, h])
mx = max(l[0])
for i in range(1, n):
	if max(l[i]) <= mx:
		mx = max(l[i])
	elif min(l[i]) <= mx:
		mx = min(l[i])
	else:
		print('NO')
		return
print('YES')


from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter

def read():
	return int(input())

def readmap():
	return map(int, input().split())

def readlist():
	return list(map(int, input().split()))
n = read()
W = []
H = []
for _ in range(n):
	(w, h) = readmap()
	W.append(w)
	H.append(h)
height = max(W[0], H[0])
for i in range(1, n):
	(w, h) = (W[i], H[i])
	if w > height and h > height:
		print('NO')
		quit()
	elif w > height:
		height = h
	elif h > height:
		height = w
	else:
		height = max(h, w)
print('YES')


import sys
from sys import stdin, stdout
from math import *
from collections import *
from itertools import *
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(int, stdin.readline().strip().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())

def solve(lis):
	val = max(lis[0][0], lis[0][1])
	for i in lis[1:]:
		(h, w) = (i[0], i[1])
		if max(h, w) <= val:
			val = max(h, w)
		elif min(h, w) <= val:
			val = min(h, w)
		else:
			print('NO')
			break
	else:
		print('YES')
lis = []
for _ in range(int(stdin.readline())):
	a = int_arr()
	lis.append(a)
solve(lis)


n = int(input())
rects = []
for _ in range(n):
	rects.append([int(x) for x in input().split()])
maxes = [max(rects[0])]
isOK = True
for i in range(1, n):
	if max(rects[i]) <= maxes[i - 1]:
		maxes.append(max(rects[i]))
	elif min(rects[i]) <= maxes[i - 1]:
		maxes.append(min(rects[i]))
	else:
		isOK = False
		break
if isOK:
	print('YES')
else:
	print('NO')


TN = 1

def solution():
	n = int(input())
	ws = []
	hs = []
	for i in range(n):
		(w, h) = map(int, input().split())
		ws.append(w)
		hs.append(h)
	ans = []
	cur = 0
	for i in range(n - 1, -1, -1):
		if ws[i] >= cur and hs[i] >= cur:
			ans.append(min(ws[i], hs[i]))
			cur = min(ws[i], hs[i])
		elif ws[i] >= cur:
			cur = ws[i]
			ans.append(ws[i])
		elif hs[i] >= cur:
			cur = hs[i]
			ans.append(hs[i])
		else:
			ans = 'NO'
			break
	else:
		ans = 'YES'
	print(ans)
while TN != 0:
	solution()
	TN -= 1


n = int(input())
w = []
h = []
for i in range(n):
	(a, b) = map(int, input().split())
	w.append(a)
	h.append(b)
if w[0] >= h[0]:
	high = w[0]
	low = h[0]
else:
	high = h[0]
	low = w[0]
a = [high]
code = 0
for i in range(1, n):
	if w[i] >= h[i]:
		high = w[i]
		low = h[i]
	else:
		high = h[i]
		low = w[i]
	temp = a[len(a) - 1]
	if high <= temp:
		a.append(high)
	elif low <= temp:
		a.append(low)
	else:
		code = 1
		break
if code == 1:
	print('NO')
elif code == 0:
	print('YES')


def problem_a():
	n = int(input())
	prev_height = None
	for _ in range(n):
		rectangle = str(input()).split()
		(width, height) = (int(rectangle[0]), int(rectangle[1]))
		if prev_height is None:
			prev_height = max(width, height)
		elif width > prev_height and height > prev_height:
			return 'NO'
		elif width > prev_height and height <= prev_height:
			prev_height = height
		elif width <= prev_height and height > prev_height:
			prev_height = width
		else:
			prev_height = max(width, height)
	return 'YES'
print(problem_a())


n = int(input())
l = []
for i in range(n):
	s = input()
	s = s.split()
	for j in range(len(s)):
		s[j] = int(s[j])
	l.append(s)
mina = max(l[0][0], l[0][1])
x = 0
for i in range(1, n):
	if l[i][0] <= mina and l[i][1] <= mina:
		mina = max(l[i][0], l[i][1])
		x = x + 1
	elif l[i][0] <= mina and l[i][1] > mina:
		mina = l[i][0]
		x = x + 1
	elif l[i][0] > mina and l[i][1] <= mina:
		mina = l[i][1]
		x = x + 1
	else:
		break
if x == n - 1:
	print('YES')
else:
	print('NO')


n = int(input())
(a, b) = list(map(int, input().split()))
t = True
if b > a:
	a = b
for i in range(n - 1):
	(x, y) = list(map(int, input().split()))
	if x < y:
		(x, y) = (y, x)
	if x <= a:
		a = x
	elif y <= a:
		a = y
	else:
		t = False
		break
if t:
	print('YES')
else:
	print('NO')


n = int(input())
l = list()
for i in range(n):
	l.append(list(map(int, input().split())))
a = list()
a.append(max(l[0]))
for i in range(1, n):
	h = max(l[i])
	if h <= a[i - 1]:
		a.append(h)
	else:
		h = min(l[i])
		if h <= a[i - 1]:
			a.append(h)
		else:
			print('NO')
			break
else:
	print('YES')


n = int(input())
(a, b) = map(int, input().split())
ans = max(a, b)
if n == 1:
	print('YES')
	exit()
for i in range(n - 1):
	(a, b) = map(int, input().split())
	if a > ans and b > ans:
		print('NO')
		exit()
	if a <= ans and b <= ans:
		ans = max(a, b)
	else:
		ans = min(a, b)
print('YES')


import time
n = int(input())
H = max((int(i) for i in input().split()))
start = time.time()
ans = 'YES'
for i in range(n - 1):
	(w, h) = (int(i) for i in input().split())
	if w > h:
		mx = w
		mn = h
	else:
		mx = h
		mn = w
	if mx <= H:
		H = mx
	elif mn <= H:
		H = mn
	else:
		ans = 'NO'
print(ans)
finish = time.time()


amount = int(input())
prev_min = 10 ** 10
for i in range(amount):
	(h1, h2) = (int(i) for i in input().split())
	(h1, h2) = (max(h1, h2), min(h1, h2))
	if h1 <= prev_min:
		prev_min = h1
	elif h2 <= prev_min:
		prev_min = h2
	else:
		print('NO')
		exit(0)
print('YES')


n = int(input())
(w1, h1) = (int(x) for x in input().split())
h = max(w1, h1)
flag = True
for i in range(1, n):
	(w1, h1) = (int(x) for x in input().split())
	if max(w1, h1) <= h:
		h = max(w1, h1)
	elif min(w1, h1) <= h:
		h = min(w1, h1)
	else:
		print('NO')
		flag = False
		break
if flag:
	print('YES')


n = int(input())
ns = [[None, None] for i in range(n)]
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	ns[i][0] = max(a, b)
	ns[i][1] = min(a, b)
last = max(ns[0])
for i in range(n):
	if ns[i][0] <= last:
		last = ns[i][0]
		continue
	if ns[i][1] <= last:
		last = ns[i][1]
		continue
	print('NO')
	quit()
print('YES')


z = []
k = int(input())
q = 1
for t in range(k):
	(a, b) = map(int, input().split())
	if t > 0:
		if max(a, b) <= z[t - 1]:
			z.append(max(a, b))
		elif min(a, b) <= z[t - 1]:
			z.append(min(a, b))
		elif min(a, b) > z[t - 1]:
			if t == k - 1:
				q = 0
				break
			elif min(a, b) < z[t - 1]:
				z.append(max(a, b))
			else:
				q = 0
				break
	else:
		z.append(max(a, b))
if q == 1:
	print('YES')
else:
	print('NO')


n = int(input())
rects = []
for i in range(n):
	(a, b) = map(int, input().split())
	rects.append([a, b])
ans = 0
mx = 10 ** 9 + 1
for rect in rects:
	mn_len = min(rect[0], rect[1])
	mx_len = max(rect[0], rect[1])
	if mx >= mx_len:
		mx = mx_len
	elif mx >= mn_len:
		mx = mn_len
	else:
		ans = 1
		break
if ans == 0:
	print('YES')
else:
	print('NO')


n = int(input())
m = 10000000000
f = 0
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	(h, w) = (max(a, b), min(a, b))
	if h > m and w > m:
		f = 1
		break
	if h <= m:
		m = h
	else:
		m = w
if f == 1:
	print('NO')
else:
	print('YES')


import sys
import os

def turnTheRectangles(rects):
	last = 10 ** 10
	for rect in rects:
		a = max(rect[0], rect[1])
		b = min(rect[0], rect[1])
		if a <= last:
			last = a
		elif b <= last:
			last = b
		else:
			return 'NO'
	return 'YES'

def main():
	n = int(input())
	rects = []
	for i in range(n):
		(w, h) = (int(x) for x in input().split())
		rects.append([w, h])
	print(turnTheRectangles(rects))

def __starting_point():
	main()
__starting_point()


n = int(input())
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
prev = 10000000000000000000000
for i in arr:
	m = max(i[0], i[1])
	n = min(i[0], i[1])
	if m <= prev:
		prev = m
	elif n <= prev:
		prev = n
	else:
		print('NO')
		break
else:
	print('YES')


from sys import stdin, stdout
input = lambda : stdin.readline().rstrip()
write = stdout.write

def main():
	N = int(input())
	WH = [tuple(map(int, input().split())) for _ in [0] * N]
	prev = float('inf')
	for wh in WH:
		if prev >= max(wh):
			prev = max(wh)
		elif prev >= min(wh):
			prev = min(wh)
		else:
			print('NO')
			break
	else:
		print('YES')
main()


rectangles = []
for _ in range(int(input().strip())):
	(w, h) = map(int, input().strip().split())
	rectangles.append((w, h))
rectangles = rectangles[::-1]
curr_min = -1
for rect in rectangles:
	if min(rect) >= curr_min:
		curr_min = min(rect)
	elif max(rect) >= curr_min:
		curr_min = max(rect)
	else:
		exit(print('NO'))
print('YES')


def Rectangles():
	curr_h = 10 ** 9 + 1
	for _ in range(int(input())):
		(w, h) = map(int, input().split())
		if min(w, h) <= curr_h:
			if max(w, h) <= curr_h:
				curr_h = max(w, h)
			else:
				curr_h = min(w, h)
		else:
			return 'NO'
	return 'YES'
print(Rectangles())


n = int(input())
ans = True
hmin = 10 ** 9
for i in range(n):
	(a, b) = map(int, input().split())
	h1 = max(a, b)
	h2 = min(a, b)
	if h1 <= hmin:
		hmin = h1
	elif h2 > hmin:
		ans = False
		break
	else:
		hmin = h2
if ans:
	print('YES')
else:
	print('NO')


n = int(input())
ans = 'YES'
oldh = 10 ** 9
for i in range(n):
	(w, h) = map(int, input().split())
	if w > h:
		if oldh >= w:
			oldh = w
			continue
		elif oldh >= h:
			oldh = h
			continue
		else:
			ans = 'NO'
			break
	elif oldh >= h:
		oldh = h
		continue
	elif oldh >= w:
		oldh = w
		continue
	else:
		ans = 'NO'
		break
print(ans)


N = int(input())
src = [tuple(map(int, input().split())) for i in range(N)]
prev = 10 ** 9 + 1
for (a, b) in src:
	if a > b:
		(a, b) = (b, a)
	if a > prev:
		print('NO')
		exit()
	if b <= prev:
		prev = b
	else:
		prev = a
print('YES')


from sys import stdin, stdout
from math import inf

def readline():
	return stdin.readline()

def writeline(s):
	stdout.write(s + '\n')
n = int(readline())
rs = [map(int, readline().split()) for _ in range(n)]
result = 'YES'
hprev = inf
for (w, h) in rs:
	(maxi, mini) = (max(w, h), min(w, h))
	if maxi <= hprev:
		hprev = maxi
	elif mini <= hprev:
		hprev = mini
	else:
		result = 'NO'
		break
writeline(result)


n = int(input())
l = 1000000000
for i in range(n):
	(x, y) = list(map(int, input().split()))
	if l >= max(x, y):
		l = max(x, y)
	elif l >= min(x, y):
		l = min(x, y)
	else:
		print('NO')
		exit(0)
print('YES')


t = 0
j = 0
for i in range(int(input())):
	a = list(map(int, input().split()))
	if i == 0:
		t = max(a)
	elif max(a) <= t:
		t = max(a)
	elif min(a) <= t:
		t = min(a)
	else:
		print('NO')
		j += 1
		break
if j == 0:
	print('YES')


n = int(input())
(a, b) = input().split()
ans = max(int(a), int(b))
flag = 0
for i in range(n - 1):
	(a, b) = map(int, input().split())
	if max(a, b) <= ans:
		ans = max(a, b)
	elif min(a, b) <= ans:
		ans = min(a, b)
	else:
		flag = 1
		break
if flag == 1:
	print('NO')
else:
	print('YES')


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

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 get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
n = int(input())
hh = 1000000000
ch = 1
while n:
	n -= 1
	(w, h) = map(int, input().split())
	if w > h:
		gh = w
		lh = h
	else:
		gh = h
		lh = w
	if gh > hh:
		if lh > hh:
			ch = 0
		else:
			hh = lh
	else:
		hh = gh
if ch:
	print('YES')
else:
	print('NO')


class pair:

	def __init__(self, w, h):
		self.w = w
		self.h = h
n = int(input())
a = [pair] * n
for i in range(n):
	(w, h) = map(int, input().split())
	a[i] = pair(w, h)
curr = min(a[n - 1].w, a[n - 1].h)
for i in range(n - 2, -1, -1):
	if max(a[i].w, a[i].h) < curr:
		print('NO')
		exit(0)
	if min(a[i].w, a[i].h) >= curr:
		curr = min(a[i].w, a[i].h)
	else:
		curr = max(a[i].w, a[i].h)
print('YES')


f = True
lh = None
for i in range(int(input())):
	(w, h) = map(int, input().split())
	if not lh:
		lh = max(w, h)
	elif min(w, h) > lh:
		f = False
		break
	elif max(w, h) <= lh:
		lh = max(w, h)
	else:
		lh = min(w, h)
if not f:
	print('NO')
else:
	print('YES')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	aa = [LI() for _ in range(n)]
	c = inf
	for (a, b) in aa:
		if a > b:
			(a, b) = (b, a)
		if c >= b:
			c = b
			continue
		if c >= a:
			c = a
			continue
		return 'NO'
	return 'YES'
print(main())


def solve(n):
	(prevS, prevV) = map(int, input().split())
	lastInSequence = max(prevV, prevS)
	for i in range(1, n):
		(s, v) = map(int, input().split())
		if s <= lastInSequence:
			if v <= lastInSequence:
				lastInSequence = max(s, v)
			else:
				lastInSequence = s
		elif v <= lastInSequence:
			lastInSequence = v
		else:
			return 'NO'
	return 'YES'
n = int(input())
print(solve(n))


n = int(input())
mas = []
for i in range(n):
	mas.append(list(map(int, input().split())))
cur = 10 ** 9 + 1
for i in range(n):
	if cur < min(mas[i]):
		print('NO')
		break
	elif cur < max(mas[i]):
		cur = min(mas[i])
	else:
		cur = max(mas[i])
else:
	print('YES')


n = int(input())
w = []
h = []
for _ in range(n):
	(tempW, tempH) = map(int, input().split())
	w.append(tempW)
	h.append(tempH)
h[0] = max(h[0], w[0])
flag = 0
for i in range(1, len(w)):
	if h[i] <= h[i - 1]:
		if w[i] <= h[i - 1]:
			h[i] = max(h[i], w[i])
	elif w[i] <= h[i - 1]:
		h[i] = w[i]
	else:
		flag = 1
		break
if flag == 0:
	print('YES')
else:
	print('NO')


n = int(input())
l = []
(a, b) = map(int, input().split())
l.append(max(a, b))
for i in range(n - 1):
	(a, b) = map(int, input().split())
	c = max(a, b)
	d = min(a, b)
	if l[i] >= c:
		l.append(c)
	else:
		l.append(d)
l1 = list(reversed(sorted(l)))
if l1 == l:
	print('YES')
else:
	print('NO')


n = int(input())
width = []
height = []
for i in range(n):
	(a, b) = input().split(' ')
	width.append(int(a))
	height.append(int(b))
flag = 0
h = max(width[0], height[0])
for i in range(1, n):
	if max(width[i], height[i]) <= h:
		h = max(width[i], height[i])
	elif min(width[i], height[i]) <= h:
		h = min(width[i], height[i])
	else:
		flag = 1
if flag is 1:
	print('NO')
else:
	print('YES')


from sys import stdin

def solve(tc):
	n = int(stdin.readline().strip())
	li = []
	for i in range(n):
		li.append(list(map(int, stdin.readline().split())))
	p = 10000000000.0
	for i in range(n):
		if p >= li[i][0]:
			cand1 = li[i][0]
		else:
			cand1 = 0
		if p >= li[i][1]:
			cand2 = li[i][1]
		else:
			cand2 = 0
		q = max(cand1, cand2)
		if q > 0 and p >= q:
			p = q
		else:
			print('NO')
			return
	print('YES')
	return
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip()) if LOCAL_TEST else 1
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


n = int(input())
(w, h) = map(int, input().split())
if w > h:
	(w, h) = (h, w)
flag = 'Yes'
for i in range(n - 1):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b <= h:
		h = b
	elif a <= h:
		h = a
	else:
		flag = 'No'
print(flag)


from sys import stdin
inp = lambda : stdin.readline()
insp = lambda : inp().split()
n = int(inp())
ho = 10 ** 9 + 1
for i in range(n):
	(h, w) = sorted(map(int, insp()))
	if ho >= w:
		ho = w
	elif ho >= h:
		ho = h
	else:
		print('NO')
		quit()
print('YES')


t = int(input(''))
arr = []
for i in range(t):
	arr.append(list(map(int, input().split())))
flag = 0
x = arr[0][0]
y = arr[0][1]
mini = max(x, y)
for i in range(1, t):
	mn = min(arr[i][0], arr[i][1])
	mx = max(arr[i][0], arr[i][1])
	if mx <= mini:
		mini = mx
	elif mn <= mini:
		mini = mn
	else:
		flag = 1
		break
if flag:
	print('NO')
else:
	print('YES')


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


n = int(input())
(width, height) = map(int, input().split(' '))
stack = [max(width, height)]
status = ''
for i in range(n - 1):
	(width, height) = map(int, input().split(' '))
	ma = max(width, height)
	mi = min(width, height)
	if ma <= stack[-1]:
		stack.append(ma)
	elif mi <= stack[-1]:
		stack.append(mi)
	else:
		status = 'NO'
if status == '':
	status = 'YES'
print(status)


n = int(input())
a = []
for i in range(n):
	a.append([int(j) for j in input().split()])
bad = 0
prev = max(a[0][0], a[0][1])
for i in range(1, len(a)):
	t = a[i]
	if prev < t[0] and prev < t[1]:
		bad = 1
		break
	if t[0] > t[1]:
		if t[0] <= prev:
			prev = t[0]
		else:
			prev = t[1]
	elif t[1] <= prev:
		prev = t[1]
	else:
		prev = t[0]
if bad:
	print('NO')
else:
	print('YES')


n = int(input())
r = []
for i in range(n):
	r += [list(map(int, input().split()))]

def swap(a):
	b = a[0]
	a[0] = a[1]
	a[1] = b
	return a
if r[0][0] > r[0][1]:
	r[0] = swap(r[0])
else:
	pass
for i in range(1, n):
	if r[i][0] > r[i - 1][1] and r[i][1] > r[i - 1][1]:
		print('NO')
		exit()
	if r[i][0] <= r[i - 1][1] and r[i][1] <= r[i - 1][1]:
		if r[i][0] > r[i][1]:
			r[i] = swap(r[i])
		else:
			pass
	elif r[i][1] > r[i - 1][1]:
		r[i] = swap(r[i])
print('YES')


def non_ascending_rect():
	total = int(input())
	rect = []
	for i in range(total):
		rect.append(list(map(int, input().split())))
		if rect[i][1] > rect[i][0]:
			(rect[i][1], rect[i][0]) = (rect[i][0], rect[i][1])
	if len(rect) == 1:
		return 'YES'
	for i in range(len(rect) - 1):
		if rect[i][0] >= rect[i + 1][0]:
			continue
		(rect[i + 1][0], rect[i + 1][1]) = (rect[i + 1][1], rect[i + 1][0])
		if rect[i][0] >= rect[i + 1][0]:
			continue
		else:
			return 'NO'
	return 'YES'
A = non_ascending_rect()
print(A)


n = int(input())
pr = 1000000000.0 + 1
for i in range(n):
	(a, b) = map(int, input().split())
	if max(a, b) <= pr:
		pr = max(a, b)
	elif min(a, b) <= pr:
		pr = min(a, b)
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
prev = 0
ans = True
for i in range(n):
	(w, h) = map(int, input().split())
	if i == 0:
		prev = max(w, h)
	else:
		if h < w:
			(w, h) = (h, w)
		if h <= prev:
			prev = h
		elif w <= prev:
			prev = w
		else:
			ans = False
			break
if ans:
	print('YES')
else:
	print('NO')


from sys import stdin, stdout
from collections import Counter
import math
I = lambda : map(int, stdin.readline().split())
I1 = stdin.readline()
n = int(I1)
v = 1000000001
f = 0
for i in range(n):
	(x, y) = I()
	if max(x, y) <= v:
		v = max(x, y)
	elif min(x, y) <= v:
		v = min(x, y)
	else:
		f = 1
		break
if f == 0:
	print('YES')
else:
	print('NO')


n = int(input())
(pa, pb) = map(int, input().split())
check = max(pa, pb)
pos = True
for i in range(n - 1):
	(w, h) = map(int, input().split())
	if w > check and h > check:
		pos = False
		break
	elif w <= check and h <= check:
		check = max(w, h)
	elif w <= check:
		check = w
	else:
		check = h
print('YES' if pos else 'NO')


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
n = int(input())
l = []
for i in range(n):
	(a, b) = map(int, input().split())
	l.append([a, b])
ans = -1
flag = 0
for i in range(n):
	if i == 0:
		(a, b) = l[i]
		ans = max(a, b)
	else:
		(a, b) = l[i]
		(a, b) = (min(a, b), max(a, b))
		if b <= ans:
			ans = b
		elif a <= ans:
			ans = a
		else:
			flag = 1
			break
if flag == 1:
	print('NO')
else:
	print('YES')


import functools
import time

def timer(func):

	@functools.wraps(func)
	def wrapper(*args, **kwargs):
		stime = time.perf_counter()
		res = func(*args, **kwargs)
		elapsed = time.perf_counter() - stime
		print(f'{func.__name__} in {elapsed:.4f} secs')
		return res
	return wrapper

class solver:

	def __init__(self):
		pass

	def __call__(self):
		n = int(input())
		p = 10 ** 9
		for _ in range(n):
			(w, h) = map(int, input().strip().split())
			a = max(w, h)
			b = min(w, h)
			if p >= a:
				p = a
			else:
				if p < b:
					print('NO')
					return
				p = b
		print('YES')
solver()()


def max(a, b):
	if a > b:
		return a
	else:
		return b

def min(a, b):
	if a < b:
		return a
	else:
		return b
n = int(input())
rect = []
yes = 1
for i in range(n):
	rect.append(list(map(int, input().split())))
next = max(rect[0][0], rect[0][1])
for i in range(1, n):
	if next >= max(rect[i][0], rect[i][1]):
		next = max(rect[i][0], rect[i][1])
	elif next >= min(rect[i][0], rect[i][1]):
		next = min(rect[i][0], rect[i][1])
	else:
		print('NO')
		yes = 0
		break
if yes > 0:
	print('YES')


n = int(input())
arr1 = []
arr2 = []
for i in range(n):
	(x, y) = map(int, input().split())
	arr1.append(max(x, y))
	arr2.append(min(x, y))
flag1 = 0
ans1 = arr1[0]
for i in range(1, n):
	if arr1[i] > ans1:
		if arr2[i] > ans1:
			flag1 = 1
			break
		else:
			ans1 = arr2[i]
	else:
		ans1 = arr1[i]
if flag1 == 0:
	print('YES')
else:
	print('NO')


n = int(input())
now_h = max(list(map(int, input().split())))
for i in range(n - 1):
	(w, h) = list(map(int, input().split()))
	if w > now_h and h > now_h:
		print('NO')
		exit()
	elif w <= now_h and h > now_h:
		now_h = w
	elif w > now_h:
		now_h = h
	else:
		now_h = max(w, h)
print('YES')


n = int(input())
(w1, h1) = map(int, input().split())
hm = max(w1, h1)
ans = 'YES'
for i in range(n - 1):
	(a, b) = map(int, input().split())
	if a > hm and b > hm:
		ans = 'NO'
	elif a <= hm and b > hm:
		hm = a
	elif b <= hm and a > hm:
		hm = b
	else:
		hm = max(a, b)
print(ans)


n = int(input())
row = []
for _ in range(n):
	(w, h) = map(int, input().split())
	row.append((w, h))
max_height = max(row[0][0], row[0][1])
for i in range(1, n + 1):
	if i == n:
		print('YES')
		break
	if min(row[i][0], row[i][1]) > max_height:
		print('NO')
		break
	elif max(row[i][0], row[i][1]) > max_height:
		max_height = min(row[i][0], row[i][1])
	else:
		max_height = max(row[i])


n = int(input())
mas = []
for i in range(n):
	a = list(map(int, input().split(' ')))
	mas.append(a)
maxelem = 100000000000
erre = False
for i in range(n):
	if maxelem >= max(mas[i][0], mas[i][1]):
		maxelem = max(mas[i][0], mas[i][1])
	elif maxelem >= min(mas[i][0], mas[i][1]):
		maxelem = min(mas[i][0], mas[i][1])
	else:
		erre = True
		break
if erre:
	print('NO')
else:
	print('YES')


h_w = []
N = int(input(''))
for x in range(0, int(N)):
	h_w.append(input('').split(' '))
max_height = max(int(h_w[0][0]), int(h_w[0][1]))
for n in range(0, N):
	if N == 1:
		print('YES')
		break
	n_min_height = min(int(h_w[n][0]), int(h_w[n][1]))
	n_max_height = max(int(h_w[n][0]), int(h_w[n][1]))
	if n_min_height > max_height:
		print('NO')
		break
	else:
		if n_max_height <= max_height:
			max_height = n_max_height
		else:
			max_height = n_min_height
		if n is N - 1:
			print('YES')


n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
m = max(a[0][0], a[0][1])
for i in range(n):
	new = a[i]
	if new[0] < new[1]:
		(new[0], new[1]) = (new[1], new[0])
	if new[0] > m and new[1] <= m:
		m = new[1]
	elif new[0] > m and new[1] > m:
		print('NO')
		exit()
	else:
		m = new[0]
print('YES')


R = lambda : map(int, input().split())
n = int(input())
logo = 'YES'
h = max(list(R()))
for _ in range(n - 1):
	(a, b) = list(R())
	if b < a:
		(a, b) = (b, a)
	if b <= h:
		h = b
	elif a <= h:
		h = a
	else:
		logo = 'NO'
print(logo)


n = int(input())
k = 1000000000
f = 0
for i in range(n):
	(w, h) = map(int, input().split())
	if k >= max(w, h):
		k = max(w, h)
	elif k < min(w, h):
		f = 1
		break
	else:
		k = min(w, h)
if f == 0:
	print('YES')
else:
	print('NO')


def go():
	n = int(input())
	maxx = float('inf')
	cracks = False
	for i in range(n):
		x = [int(i) for i in input().split(' ')]
		if max(x) <= maxx:
			maxx = max(x)
		elif min(x) <= maxx:
			maxx = min(x)
		else:
			cracks = True
	return 'NO' if cracks else 'YES'
print(go())


n = int(input())
l = []
for i in range(n):
	x = [int(x) for x in input().split()]
	l.append(x)
m = min(l[n - 1])
f = 0
for i in range(n - 2, -1, -1):
	if m <= min(l[i]):
		m = min(l[i])
	elif m <= max(l[i]):
		m = max(l[i])
	else:
		f = 1
if f == 0:
	print('YES')
else:
	print('NO')


n = int(input())
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
aux = max(arr[0][0], arr[0][1])
flag = True
for i in range(1, n):
	if max(arr[i][0], arr[i][1]) <= aux:
		aux = max(arr[i][0], arr[i][1])
	elif min(arr[i][0], arr[i][1]) <= aux:
		aux = min(arr[i][0], arr[i][1])
	else:
		flag = False
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
flag = 1
now = 1000000000.0
for i in range(0, n):
	a = list(map(int, input().split()))
	x = min(a[0], a[1])
	y = max(a[0], a[1])
	if y <= now:
		now = y
	elif x > now:
		flag = 0
	else:
		now = x
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
dims = []
fin_heights = []
for i in range(n):
	dims.append([int(j) for j in input().split()])
flag = 1
fin_heights.append(max(dims[0]))
for i in range(1, n):
	prev_height = fin_heights[i - 1]
	if min(dims[i]) > prev_height:
		flag = 0
		break
	elif max(dims[i]) <= prev_height:
		fin_heights.append(max(dims[i]))
	else:
		fin_heights.append(min(dims[i]))
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
(w, h) = [int(a) for a in input().split()]
temp = max(w, h)
for i in range(1, n):
	(w, h) = [int(a) for a in input().split()]
	if max(w, h) <= temp:
		temp = max(w, h)
	elif min(w, h) <= temp:
		temp = min(w, h)
	else:
		print('NO')
		exit()
print('YES')


f = True
t = 10 ** 9 + 1
for i in range(int(input())):
	l = input().split()
	l[0] = int(l[0])
	l[1] = int(l[1])
	if max(l) <= t:
		t = max(l)
	elif min(l) <= t:
		t = min(l)
	else:
		f = False
		print('NO')
		break
if f:
	print('YES')


class Rect:
	w = 0
	h = 0
n = int(input())
rects = []
Bad = False
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	r = Rect()
	if i == 0:
		r.w = min(a, b)
		r.h = max(a, b)
	else:
		if b > rects[i - 1].h or (b <= rects[i - 1].h and a <= rects[i - 1].h and (a > b)):
			r.w = b
			r.h = a
		else:
			r.w = a
			r.h = b
		if r.h > rects[i - 1].h:
			Bad = True
			break
	rects.append(r)
if Bad:
	print('NO')
else:
	print('YES')


from math import *
t = int(input())
last = inf
for i in range(t):
	(w, h) = map(int, input().split())
	cur = -inf
	if w <= last:
		cur = max(cur, w)
	if h <= last:
		cur = max(cur, h)
	last = cur
print('NO' if last < 0 else 'YES')


import sys
n = int(input())

def next(x, y, p):
	m = max(x, y)
	mn = min(x, y)
	if m <= p:
		return m
	else:
		return mn
(a, b) = map(int, input().split())
s = max(a, b)
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	n = next(a, b, s)
	if n > s:
		print('NO')
		sys.exit()
	else:
		s = n
print('YES')


def main():
	n = int(input())
	li = []
	for i in range(n):
		li.append(sorted(list(map(int, input().split()))))
	m = max(li[0])
	valid = True
	for i in range(1, n):
		if li[i][1] <= m:
			m = li[i][1]
		elif li[i][0] <= m:
			m = li[i][0]
		else:
			valid = False
			break
	if valid:
		print('YES')
	else:
		print('NO')
main()


prev = float('inf')
for i in range(int(input())):
	(w, h) = map(int, input().split())
	if w <= prev and h <= prev:
		prev = max(w, h)
	elif w > prev and h > prev:
		print('NO')
		break
	else:
		prev = w if w <= prev else h
else:
	print('YES')


mx = 10 ** 9 + 1
flag = 'YES'
for i in range(int(input())):
	arr = sorted(list(map(int, input().split())))
	if mx < arr[0] and mx < arr[1]:
		flag = 'NO'
		break
	elif mx >= arr[1]:
		mx = arr[1]
	else:
		mx = arr[0]
print(flag)


n = int(input())
ans = 'YES'
prev = float('inf')
for i in range(n):
	(mn, mx) = sorted(map(int, input().split()))
	if mx <= prev:
		prev = mx
	elif mn <= prev:
		prev = mn
	else:
		ans = 'NO'
		break
print(ans)


n = int(input())
(wl, hl) = map(int, input().split())
hl = max(wl, hl)
for i in range(n - 1):
	(w, h) = map(int, input().split())
	if max(w, h) <= hl:
		hl = max(w, h)
	elif max(w, h) > hl and min(w, h) <= hl:
		hl = min(w, h)
	elif min(w, h) > hl:
		exit(print('NO'))
print('YES')


n = int(input())
a = []
for i in range(0, n):
	(x, y) = map(int, input().split())
	a.append([x, y])
flag = True
ele = max(a[0])
for i in range(1, n):
	if ele >= max(a[i]):
		ele = max(a[i])
	elif ele >= min(a[i]):
		ele = min(a[i])
	else:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
X = []
for i in range(n):
	(w, h) = map(int, input().split())
	if not X:
		X.append(max(w, h))
	elif X[-1] < min(w, h):
		print('NO')
		exit()
	elif min(w, h) <= X[-1] < max(w, h):
		X.append(min(w, h))
	elif max(w, h) <= X[-1]:
		X.append(max(w, h))
print('YES')


A = lambda : map(int, input().split())
n = int(input())
(w1, h1) = A()
h = max(w1, h1)
i = 1
while i < n:
	(w2, h2) = A()
	if min(w2, h2) > h:
		break
	if max(w2, h2) <= h:
		h = max(w2, h2)
	else:
		h = min(w2, h2)
	i += 1
if i == n:
	print('YES')
else:
	print('NO')


n = int(input())
data = []
for i in range(n):
	(a, b) = map(int, input().split())
	data.append([a, b])
ans = True
prev = max(data[0])
for i in range(1, n):
	(a, b) = data[i]
	(a, b) = (min(a, b), max(a, b))
	if a > prev:
		ans = False
		break
	if a <= prev < b:
		prev = a
		continue
	if prev >= b:
		prev = b
if ans:
	print('YES')
else:
	print('NO')


n = int(input())
last = 10 ** 10
for i in range(n):
	(h, w) = map(int, input().split())
	cur = -10 ** 10
	if h <= last:
		cur = max(cur, h)
	if w <= last:
		cur = max(cur, w)
	last = cur
if last < 0:
	print('NO')
else:
	print('YES')


n = int(input())
width = []
height = []
for i in range(n):
	(w, h) = map(int, input().split(' '))
	width.append(w)
	height.append(h)
m = max(width[0], height[0])
b = True
for i in range(1, n):
	if max(width[i], height[i]) <= m:
		m = max(width[i], height[i])
	elif min(width[i], height[i]) <= m:
		m = min(width[i], height[i])
	else:
		b = False
		break
if b:
	print('YES')
else:
	print('NO')


n = int(input())
l = [[0 for i in range(2)] for j in range(n)]
l1 = [[0 for i in range(2)] for j in range(n)]
for u in range(n):
	(l1[u][0], l1[u][1]) = map(int, input().strip().split())
l[0][0] = 1
l[0][1] = 1
for y in range(1, n):
	if l[y - 1][0] == 1:
		if l1[y - 1][0] >= l1[y][0]:
			l[y][0] = 1
		if l1[y - 1][0] >= l1[y][1]:
			l[y][1] = 1
	if l[y - 1][1] == 1:
		if l1[y - 1][1] >= l1[y][0]:
			l[y][0] = 1
		if l1[y - 1][1] >= l1[y][1]:
			l[y][1] = 1
if l[n - 1][0] or l[y][1]:
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for i in range(n):
	a.append([int(x) for x in input().split()])

def shet(a):
	s = max(a[0][0], a[0][1])
	for i in range(1, n):
		k = 0
		s1 = max(a[i][0], a[i][1])
		if s1 <= s:
			s = s1
			k += 1
		elif min(a[i][0], a[i][1]) <= s:
			s = min(a[i][0], a[i][1])
			k += 1
		if k == 0:
			return 'NO'
	return 'YES'
print(shet(a))


n = int(input())
nn = [0] * n
for i in range(1, 100000):
	xxnxx = i
(a, b) = map(int, input().split())
ans = max(a, b)
if n == 1:
	print('YES')
	exit()
for i in range(n - 1):
	(a, b) = map(int, input().split())
	if a > ans and b > ans:
		print('NO')
		exit()
	if a <= ans and b <= ans:
		ans = max(a, b)
	else:
		ans = min(a, b)
print('YES')


n = int(input())
a = []
for i in range(n):
	list = [int(x) for x in input().split()]
	list.sort(reverse=True)
	a.append(list)
max = a[0][0]
flag = 0
for i in range(1, n):
	if a[i][0] > max:
		if a[i][1] > max:
			flag = 1
			break
		else:
			max = a[i][1]
	else:
		max = a[i][0]
if flag == 1:
	print('NO')
else:
	print('YES')


def is_sortable(figures):
	prev_h = max(figures[0])
	for (idx, f) in enumerate(figures):
		if idx == 0:
			continue
		cur_h = max(f)
		if cur_h <= prev_h:
			prev_h = cur_h
			continue
		cur_h = min(f)
		if cur_h <= prev_h:
			prev_h = cur_h
			continue
		return False
	return True

def main():
	figures = []
	for _ in range(int(input())):
		(w, h) = map(int, input().split())
		figures.append((w, h))
	print('YES' if is_sortable(figures) else 'NO')
main()


def main():
	n = int(input())
	maxHeight = 10000000000
	didExit = False
	for i in range(n):
		[a, b] = [int(x) for x in input().split()]
		_max = max(a, b)
		_min = min(a, b)
		if _max <= maxHeight:
			maxHeight = _max
		elif _min <= maxHeight:
			maxHeight = _min
		else:
			print('NO')
			didExit = True
			break
	if didExit == False:
		print('YES')
main()


n = int(input())
rects = []
for i in range(n):
	rects.append([int(x) for x in input().split()])
max_height = max(rects[0])
for i in range(1, n):
	if max(rects[i]) <= max_height:
		max_height = max(rects[i])
	elif min(rects[i]) <= max_height:
		max_height = min(rects[i])
	else:
		max_height = 0
print('NO' if max_height == 0 else 'YES')


n = int(input())
L = []
for i in range(n):
	L.append(list(map(int, input().split())))
p = max(L[0][0], L[0][1])
f = 1
for i in range(1, n):
	a = max(L[i][0], L[i][1])
	b = min(L[i][0], L[i][1])
	if p >= a:
		p = a
	elif p >= b:
		p = b
	else:
		f = 0
		break
if f == 0:
	print('NO')
elif f == 1:
	print('YES')


n = int(input())
last = 1000000000
for i in range(n):
	s = input().split(' ')
	rect = {int(s[0]), int(s[1])}
	num = max(rect)
	if num <= last:
		last = num
		continue
	else:
		num = min(rect)
		if num <= last:
			last = num
			continue
		else:
			print('NO')
			exit()
print('YES')


n = int(input())
a = []
temp = pow(10, 9) + 1
for i in range(n):
	t = [int(i) for i in input().split()]
	a.append(t)
c = False
for i in a:
	if temp >= max(i):
		temp = max(i)
		continue
	elif temp >= min(i):
		temp = min(i)
		continue
	else:
		print('NO')
		c = True
		break
if not c:
	print('YES')


fl = 0
for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	(min1, max1) = (min(a, b), max(a, b))
	if fl == 0:
		if i != 0:
			if max1 <= s:
				s = max1
			elif min1 <= s:
				s = min1
			else:
				fl = 1
		else:
			s = max1
if fl == 0:
	print('YES')
else:
	print('NO')


n = int(input())
d = True
(a, b) = [int(x) for x in input().split()]
tmp = max(a, b)
for i in range(n - 1):
	(a, b) = sorted([int(x) for x in input().split()])
	if b <= tmp:
		tmp = b
	elif a <= tmp:
		tmp = a
	else:
		d = False
		break
print('YES' if d else 'NO')


n = int(input())
max_height = max(map(int, input().split()))
for i in range(n - 1):
	for h in sorted(map(int, input().split()), reverse=True):
		if h <= max_height:
			max_height = h
			break
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
p = []
for i in range(n):
	(a, b) = map(int, input().split())
	p.append([a, n - i])
	p.append([b, n - i])
p.sort(reverse=True)
i = n
for (a, x) in p:
	if x == i:
		i -= 1
print(['NO', 'YES'][i == 0])


n = int(input())
ans = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if i == 0:
		t = max(a, b)
	else:
		x = max(a, b)
		if x <= t:
			temp = x
		else:
			temp = min(a, b)
			if temp > t:
				print('NO')
				ans = 1
				break
		t = temp
if ans == 0:
	print('YES')


import sys
lines = [line.strip() for line in sys.stdin.readlines()]
n = int(lines[0].split(' ')[0])
rects = []
for i in range(n):
	(w, h) = map(int, lines[i + 1].split(' '))
	if w > h:
		rects.append((w, h))
	else:
		rects.append((h, w))
if rects[0][0] < rects[0][1]:
	rects[0] = (rects[0][1], rects[0][0])
good = True
for (idx, rect) in enumerate(rects[1:], 1):
	if rects[idx - 1][0] >= rect[0]:
		continue
	elif rects[idx - 1][0] >= rect[1]:
		rects[idx] = (rect[1], rect[0])
		continue
	else:
		good = False
if good:
	print('YES')
else:
	print('NO')


n = int(input())
prev_max_heigt = 0
(a, b) = map(int, input().split())
prev_max_heigt = max(a, b)
ans = True
for i in range(n - 1):
	(a, b) = map(int, input().split())
	t = max(a, b)
	if t <= prev_max_heigt:
		prev_max_heigt = t
	else:
		t = min(a, b)
		if t <= prev_max_heigt:
			prev_max_heigt = t
		else:
			ans = False
if ans:
	print('YES')
else:
	print('NO')


a = int(input()) - 1
(t, k) = map(int, input().split())
m = max(t, k)
f = 0
for i in [0] * a:
	(t, k) = map(int, input().split())
	if k > t:
		(t, k) = (k, t)
	if t <= m:
		m = t
	elif k <= m:
		m = k
	else:
		f = 1
print('YES' if f == 0 else 'NO')


n = int(input())
t = 1
m = max(list(map(int, input().split(' '))))
for i in range(1, n):
	arr = list(map(int, input().split(' ')))
	if arr[0] <= m and arr[1] <= m:
		m = max(arr)
	elif arr[0] <= m:
		m = arr[0]
	elif arr[1] <= m:
		m = arr[1]
	else:
		t = 0
		break
print('YES' if t else 'NO')


n = int(input())
(a, b) = map(int, input().split())
t = max(a, b)
fl = True
for i in range(n - 1):
	(a, b) = map(int, input().split())
	if t < min(a, b):
		fl = False
		break
	elif t < max(a, b):
		t = min(a, b)
	else:
		t = max(a, b)
if fl:
	print('YES')
else:
	print('NO')


n = int(input())
ma = 10 ** 18
for i in range(n):
	[w, h] = [int(i) for i in input().split()]
	m = max(w, h)
	if m <= ma:
		ma = m
		continue
	m = min(w, h)
	if m <= ma:
		ma = m
		continue
	print('NO')
	exit(0)
print('YES')


n = int(input())
a = []
for i in range(n):
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	a.append(w)
flag = True
mx = a[0][0]
for i in range(1, n):
	if a[i][0] > mx:
		if a[i][1] > mx:
			flag = False
			break
		else:
			mx = a[i][1]
	else:
		mx = a[i][0]
if flag == True:
	print('YES')
else:
	print('NO')


number = int(input())
rem = 10 ** 9 + 1
state = True
for i in range(number):
	numList = list(map(int, input().split()))
	mmin = min(numList[0], numList[1])
	mmax = max(numList[0], numList[1])
	if mmax <= rem:
		rem = mmax
	elif mmin <= rem:
		rem = mmin
	else:
		state = False
		break
if state:
	print('YES')
else:
	print('NO')


n = int(input())
ans = True
first = True
for _ in range(n):
	if first:
		(p1, p2) = map(int, input().split())
		mn = max(p1, p2)
		first = False
	else:
		(c1, c2) = map(int, input().split())
		if c1 <= mn and c2 <= mn:
			mn = max(c1, c2)
		elif c1 <= mn and c2 > mn:
			mn = c1
		elif c1 > mn and c2 <= mn:
			mn = c2
		else:
			ans = False
if ans:
	print('YES')
else:
	print('NO')


x = []
y = []

def isRect(z):
	z.reverse()
	minV = min(z[0])
	for i in range(1, len(z)):
		p1 = min(z[i])
		q1 = max(z[i])
		if p1 >= minV:
			minV = p1
		elif q1 >= minV:
			minV = q1
		else:
			return False
	return True
for _ in range(int(input())):
	(a, b) = input().split()
	x.append(int(a))
	y.append(int(b))
z = list(zip(x, y))
if isRect(z):
	print('YES')
else:
	print('NO')


x = []
c = 0
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	x.append([a, b])
y = [max(x[0])]
for i in range(1, n):
	if max(x[i]) <= y[i - 1]:
		y.append(max(x[i]))
	else:
		y.append(min(x[i]))
z = list(reversed(sorted(y)))
if y == z:
	print('YES')
else:
	print('NO')


n = int(input())
x_min = 0
for i in range(n):
	x = list(map(int, input().split()))
	x.sort()
	if i == 0:
		x_min = x[1]
	elif i != 0:
		if x[0] > x_min:
			print('NO')
			break
		elif x_min >= x[1]:
			x_min = x[1]
		elif x[0] <= x_min <= x[1]:
			x_min = x[0]
	if i == n - 1:
		print('YES')


n = int(input())
l = sorted([int(x) for x in input().split()])
a = l[1]
x = 0
for i in range(n - 1):
	d = sorted([int(x) for x in input().split()])
	if d[1] > a:
		if d[0] > a:
			x = 1
			break
		else:
			a = d[0]
	else:
		a = d[1]
if x == 1:
	print('NO')
else:
	print('YES')


n = int(input())
rec = [list(map(int, input().split())) for _ in range(n)]
current = float('inf')
for (w, h) in rec:
	min_ = min(w, h)
	max_ = max(w, h)
	if current >= max_:
		current = max_
	elif current >= min_:
		current = min_
	else:
		print('NO')
		break
else:
	print('YES')


n = float('inf')
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if n >= a:
		n = a
	elif n >= b:
		n = b
	else:
		print('NO')
		exit()
print('YES')


import sys
n = int(input())
arr = [tuple(map(int, sys.stdin.readline().split())) for i in range(n)]
h = max(arr[0])
for x in range(1, n):
	if max(arr[x]) <= h:
		h = max(arr[x])
	elif min(arr[x]) <= h:
		h = min(arr[x])
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
w = [0] * n
h = [0] * n
for i in range(n):
	(w[i], h[i]) = map(int, input().split())
m = max(w[0], h[0])
for (i, j) in zip(w, h):
	if i > j:
		(i, j) = (j, i)
	if j <= m:
		m = j
	elif i <= m:
		m = i
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
L = []
for i in range(n):
	L.append(sorted(list(map(int, input().split()))))

def check():
	m = L[0][1]
	for i in range(1, n):
		if L[i][1] <= m:
			m = L[i][1]
		elif L[i][0] <= m:
			m = L[i][0]
		else:
			return False
	return True
if check():
	print('YES')
else:
	print('NO')


n = int(input())
lmain = []
(x, y) = map(int, input().split())
lmain.append(max(x, y))
for i in range(1, n):
	(a, b) = map(int, input().split())
	lmain.append([a, b])
ans = True
for i in range(1, n):
	if max(lmain[i][0], lmain[i][1]) <= lmain[i - 1]:
		lmain[i] = max(lmain[i][0], lmain[i][1])
	elif min(lmain[i][0], lmain[i][1]) <= lmain[i - 1]:
		lmain[i] = min(lmain[i][0], lmain[i][1])
	else:
		ans = False
		break
if ans:
	print('YES')
else:
	print('NO')


n = int(input())
mas = []
for i in range(n):
	mas.append(tuple(map(int, input().split())))
mas.reverse()
(stara, starb) = mas[0]
if n == 1:
	print('YES')
	exit(0)
(newa, newb) = mas[1]
(a, b) = (10000000000000000000000, 100000000000000000000000)
if newa >= stara or newa >= starb:
	a = newa
if newb >= stara or newb >= starb:
	b = newb
star = min(a, b)
if star > 10 ** 9:
	print('NO')
	exit(0)
for i in range(n - 2):
	(a, b) = (10000000000000000000000, 100000000000000000000000)
	(newa, newb) = mas[i + 2]
	if newa >= star:
		a = newa
	if newb >= star:
		b = newb
	star = min(a, b)
	if star >= 100000000000000000:
		print('NO')
		exit(0)
print('YES')


def turn_the_rectangles_perfect():
	n = int(input())
	(width, height) = map(int, input().split())
	stack = [max(width, height)]
	flag = True
	for i in range(n - 1):
		(width, height) = map(int, input().split())
		ma = max(width, height)
		mi = min(width, height)
		if ma <= stack[-1]:
			stack.append(ma)
		elif mi <= stack[-1]:
			stack.append(mi)
		else:
			flag = False
	if flag:
		print('YES')
	else:
		print('NO')
turn_the_rectangles_perfect()


num = int(input())
prev = list(map(int, input().split()))
num -= 1
if prev[0] > prev[1]:
	(prev[0], prev[1]) = (prev[1], prev[0])
ans = ''
for i in range(num):
	cur = list(map(int, input().split()))
	temp1 = cur[1] - prev[1]
	temp2 = cur[0] - prev[1]
	if temp1 <= 0 and temp2 <= 0:
		if max(temp1, temp2) == temp2:
			(cur[0], cur[1]) = (cur[1], cur[0])
	elif temp2 <= 0:
		(cur[0], cur[1]) = (cur[1], cur[0])
	elif temp1 <= 0:
		k = 0
	else:
		ans = 'NO'
		break
	prev = cur
if ans != '':
	print(ans)
else:
	print('YES')


n = int(input())
pv = 1000000000.0
ok = 1
for i in range(n):
	(a, b) = map(int, input().split())
	mx = max(a, b)
	mn = min(a, b)
	if mx <= pv:
		pv = mx
	elif mn <= pv:
		pv = mn
	else:
		ok = 0
if ok == 1:
	print('YES')
else:
	print('NO')


x = int(input())
pairs = []
for i in range(x):
	pairs.append(tuple(map(int, input().split())))
h = max(pairs[0])
for i in range(x):
	if min(pairs[i]) > h:
		print('NO')
		exit()
	elif max(pairs[i]) > h:
		h = min(pairs[i])
	else:
		h = max(pairs[i])
print('YES')


import sys
i = 0
for _ in range(int(input())):
	if i == 0:
		(x, y) = map(int, input().split())
		m = max(x, y)
		i += 1
		continue
	(x, y) = map(int, input().split())
	if max(x, y) <= m:
		m = max(x, y)
	elif min(x, y) <= m:
		m = min(x, y)
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
w = []
h = []
for i in range(n):
	(a, b) = map(int, input().split())
	w.append(a)
	h.append(b)
h[0] = max(w[0], h[0])
for i in range(1, n):
	mx = max(w[i], h[i])
	mn = min(w[i], h[i])
	if mx <= h[i - 1]:
		h[i] = mx
	else:
		h[i] = mn
flag = 0
for i in range(1, n):
	if h[i] > h[i - 1]:
		flag = 1
if flag == 0:
	print('YES')
else:
	print('NO')


n = int(input())
l = ['NO', 'YES']
t = 1
(a, b) = [int(x) for x in input().split(' ')]
q = a
if a < b:
	q = b
for i in range(n - 1):
	(a, b) = [int(x) for x in input().split(' ')]
	if a < b:
		(a, b) = (b, a)
	qq = a
	if q < a:
		qq = b
		if q < b:
			t = 0
	q = qq
print(l[t])


n = int(input())
(a, b) = map(int, input().split())
ch = max(a, b)
s = True
for i in range(n - 1):
	(w, h) = map(int, input().split())
	if min(w, h) > ch:
		s = False
	if max(w, h) <= ch:
		ch = max(w, h)
	elif min(w, h) <= ch:
		ch = min(w, h)
	(a, b) = (w, h)
if s:
	print('YES')
else:
	print('NO')


n = int(input())
pr = max(map(int, input().split()))
for i in range(1, n):
	(w, h) = map(int, input().split())
	if max(w, h) <= pr:
		pr = max(w, h)
	elif min(w, h) <= pr:
		pr = min(w, h)
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
maximum = float('inf')
for _ in range(n):
	(w, h) = map(int, input().split())
	if max(w, h) <= maximum:
		maximum = max(w, h)
	elif min(w, h) <= maximum:
		maximum = min(w, h)
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
from sys import stdin
from sys import exit
t = 1000000009
for i in range(n):
	(a, b) = map(int, stdin.readline().split())
	(e, r) = (min(a, b), max(a, b))
	if r <= t:
		t = r
	elif e <= t:
		t = e
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
rect = []
for i in range(n):
	rect.append([int(i) for i in input().split()])
flag = True
current = 9999999999
for i in range(n):
	if current >= max(rect[i]):
		current = max(rect[i])
	elif current >= min(rect[i]):
		current = min(rect[i])
	else:
		flag = False
if flag:
	print('YES')
else:
	print('NO')


t = int(input())
w = []
l = []
for i in range(t):
	(m, n) = map(int, input().split())
	w.append(m)
	l.append(n)
z = max(w[0], l[0])
m = []
M = []
for i in range(t):
	if w[i] > l[i]:
		m.append(l[i])
		M.append(w[i])
	else:
		m.append(w[i])
		M.append(l[i])
z = max(m[0], M[0])
flag = 0
for i in range(1, t):
	if z >= M[i]:
		z = M[i]
	elif z >= m[i]:
		z = m[i]
	else:
		flag = 1
if flag == 1:
	print('NO')
else:
	print('YES')


ok = True

def getPAG(p, i, j):
	if p < i and p < j:
		return -1
	elif i <= p and j <= p:
		return max([i, j])
	else:
		return min([i, j])
T = int(input())
rec = []
s = input().split(' ')
minn = max([int(s[0]), int(s[1])])
rec.append(minn)
for i in range(1, T):
	s = input().split(' ')
	m = getPAG(rec[i - 1], int(s[0]), int(s[1]))
	rec.append(m)
for i in range(len(rec)):
	if rec[i] == -1:
		ok = False
		break
for i in range(len(rec) - 1):
	if rec[i + 1] > rec[i]:
		ok = False
		break
if ok:
	print('YES')
else:
	print('NO')


n = int(input())
m = []
a = []
for i in range(n):
	m.append(list(map(int, input().split())))
comp = 0
for i in range(n):
	if i == 0:
		comp = max(m[i][0], m[i][1])
		a.append(comp)
		continue
	maxa = max(m[i][0], m[i][1])
	mina = min(m[i][0], m[i][1])
	if maxa <= comp:
		comp = maxa
		a.append(comp)
	else:
		comp = mina
		a.append(comp)
for i in range(0, len(a) - 1):
	if a[i] < a[i + 1]:
		print('NO')
		return
print('YES')


n = int(input())
rects = []
possible = 'YES'
for _ in range(n):
	arr = list(map(int, input().split()))
	rects.append(arr)
prev = max(rects[0])
for i in range(1, n):
	if prev >= max(rects[i]):
		prev = max(rects[i])
	elif prev >= min(rects[i]):
		prev = min(rects[i])
	else:
		possible = 'NO'
		break
print(possible)


a = int(input())
b = 'YES'
c = max(list(map(int, input().split())))
for i in range(a - 1):
	k = list(map(int, input().split()))
	if max(k) <= c:
		c = max(k)
	elif min(k) <= c:
		c = min(k)
	else:
		b = 'NO'
		break
print(b)


import datetime
n = int(input())
arr = []
for i in range(n):
	(x, y) = map(int, input().split())
	arr.append([x, y])
answer = True
previous_min = max(arr[0])
for i in range(1, n):
	if min(arr[i]) > previous_min:
		answer = False
		break
	elif max(arr[i]) <= previous_min:
		previous_min = max(arr[i])
	elif min(arr[i]) <= previous_min:
		previous_min = min(arr[i])
	else:
		answer = False
		break
if answer:
	print('YES')
else:
	print('NO')


def allocateMatrix(rows, cols):
	matrix = [[0] * cols for i in range(rows)]
	return matrix
n = int(input())
pairOld = list(map(int, input().split()))
if pairOld[0] < pairOld[1]:
	(pairOld[0], pairOld[1]) = (pairOld[1], pairOld[0])
for i in range(1, n):
	pairNew = list(map(int, input().split()))
	if pairNew[0] > pairOld[0] and pairNew[1] > pairOld[0]:
		print('NO')
		exit(0)
	if pairOld[0] - pairNew[0] < 0 or (pairOld[0] - pairNew[0] > pairOld[0] - pairNew[1] and pairOld[0] - pairNew[1] >= 0):
		(pairNew[0], pairNew[1]) = (pairNew[1], pairNew[0])
	pairOld = pairNew
print('YES')


n = int(input())
a = list()
for i in range(n):
	cur = list(input().split(' '))
	(x, y) = (int(cur[0]), int(cur[1]))
	a.append((x, y))
flag = True
last = max(a[0][0], a[0][1])
for i in range(1, n):
	if min(a[i][0], a[i][1]) > last:
		flag = False
		break
	if max(a[i][0], a[i][1]) <= last:
		last = max(a[i][0], a[i][1])
	else:
		last = min(a[i][0], a[i][1])
if flag:
	print('YES')
else:
	print('NO')


l = []
p = []
c = 0
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	l.append(n)
	p.append(s)
maxx = max(l[0], p[0])
for i in range(1, len(l)):
	if max(l[i], p[i]) <= maxx:
		maxx = max(l[i], p[i])
	elif min(l[i], p[i]) <= maxx:
		maxx = min(l[i], p[i])
	else:
		c = 1
print('YES' if c == 0 else 'NO')


n = int(input())
possible = 'YES'
prev = max(list(map(int, input().split())))
for i in range(n - 1):
	arr = list(map(int, input().split()))
	maxx = max(arr)
	minn = min(arr)
	if prev >= maxx:
		prev = maxx
	elif prev >= minn:
		prev = minn
	else:
		possible = 'NO'
		break
print(possible)


n = int(input())
k = 'YES'
(a, b) = input().split()
a = int(a)
b = int(b)
if a > b:
	h = a
else:
	h = b
for j in range(n - 1):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if h < a and h < b:
		k = 'NO'
		break
	elif a >= b and a <= h:
		h = a
	elif a >= b:
		h = b
	elif b > a and b <= h:
		h = b
	else:
		h = a
print(k)


def no():
	print('NO')
	exit()
from sys import stdin
all_in = stdin.read().splitlines()
n = int(all_in[0])
pryam = [tuple(map(int, el.split())) for el in all_in[1:]]
last = max(pryam[0])
for el in pryam[1:]:
	if min(el) > last:
		no()
	last = max(el) if max(el) <= last else min(el)
print('YES')


n = int(input())
c = []
(a, b) = map(int, input().split())
c.append(max(a, b))
for i in range(1, n):
	(a, b) = map(int, input().split())
	m1 = min(a, b)
	m2 = max(a, b)
	if m2 <= c[i - 1]:
		c.append(m2)
	else:
		c.append(m1)
if c == sorted(c)[::-1]:
	print('YES')
else:
	print('NO')


def main():
	nRects = int(input())
	rects = []
	for i in range(nRects):
		dimensions = input().split()
		rects.append((int(dimensions[0]), int(dimensions[1])))
	prevHeight = -1
	for rect in rects:
		mx = max(rect[0], rect[1])
		mn = min(rect[0], rect[1])
		if prevHeight < 0:
			prevHeight = mx
		elif mx > prevHeight:
			if mn <= prevHeight:
				prevHeight = mn
			else:
				print('NO')
				return
		else:
			prevHeight = mx
	print('YES')
main()


n = int(input())
p = max(map(int, input().split()))
ans = 'YES'
for i in range(n - 1):
	(a, b) = sorted(map(int, input().split()))
	if b <= p:
		p = b
	elif a <= p:
		p = a
	else:
		ans = 'NO'
		break
print(ans)


n = int(input())
(a, b) = [int(i) for i in input().split()]
current = max(a, b)
flag = True
for i in range(n - 1):
	(a, b) = [int(i) for i in input().split()]
	ma = max(a, b)
	mi = min(a, b)
	if mi > current:
		print('NO')
		flag = False
		break
	if ma <= current:
		current = ma
	else:
		current = mi
if flag:
	print('YES')


t = int(input())
flag = True
for i in range(t):
	(a, b) = [int(i) for i in input().split()]
	if i == 0:
		ln = max(a, b)
	elif ln >= max(a, b):
		ln = max(a, b)
	elif ln >= min(a, b):
		ln = min(a, b)
	else:
		flag = False
		break
if flag == True:
	print('YES')
else:
	print('NO')


import math
n = int(input())
height = math.inf
status = True
for i in range(n):
	(w, h) = map(int, input().split())
	m = max(w, h)
	if m <= height:
		height = m
	else:
		m = min(w, h)
		if m > height:
			status = False
			break
		height = m
if status:
	print('YES')
else:
	print('NO')


n = int(input())
pairs = []
a = 'YES'
for i in range(n):
	read = input().split()
	pairs.append([int(read[0]), int(read[1])])
if max(pairs[0]) > pairs[0][0]:
	aux = pairs[0][0]
	pairs[0][0] = pairs[0][1]
	pairs[0][1] = aux
for i in range(1, n):
	if min(pairs[i]) > pairs[i - 1][0]:
		a = 'NO'
		break
	elif max(pairs[i]) <= pairs[i - 1][0]:
		if max(pairs[i]) > pairs[i][0]:
			aux = pairs[i][0]
			pairs[i][0] = pairs[i][1]
			pairs[i][1] = aux
	elif max(pairs[i]) == pairs[i][0]:
		aux = pairs[i][0]
		pairs[i][0] = pairs[i][1]
		pairs[i][1] = aux
print(a)


n = int(input())
pre = float('inf')
flag = True
for i in range(n):
	(a, b) = map(int, input().split())
	if pre >= min(a, b):
		if pre >= max(a, b):
			pre = max(a, b)
		else:
			pre = min(a, b)
	else:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


num = int(input())
Max = max(list(map(int, input().split())))
toPrint = 'YES'
for i in range(num - 1):
	(n2, m2) = list(map(int, input().split()))
	if Max >= max(n2, m2):
		Max = max(n2, m2)
	elif Max >= min(n2, m2):
		Max = min(n2, m2)
	else:
		toPrint = 'NO'
		break
print(toPrint)


f = int(input())
rec = []
for _ in range(f):
	rec.append(tuple(map(int, input().split())))
res = 'YES'
if f > 1:
	temp = max(rec[0])
	for i in range(len(rec) - 1):
		if temp >= max(rec[i + 1]):
			temp = max(rec[i + 1])
		elif temp >= min(rec[i + 1]):
			temp = min(rec[i + 1])
		else:
			res = 'NO'
			break
print(res)


from sys import stdin
n = int(stdin.readline())
heights = []
nums = [int(x) for x in stdin.readline().split()]
heights.append(max(nums))
for i in range(n - 1):
	nums = [int(x) for x in stdin.readline().split()]
	if max(nums) <= heights[i]:
		heights.append(max(nums))
	elif min(nums) <= heights[i]:
		heights.append(min(nums))
	else:
		print('NO')
		quit()
print('YES')


n = int(input())
[a, b] = input().split()
(a, b) = (int(a), int(b))
h = max(a, b)
answer = 'YES'
for i in range(n - 1):
	[x, y] = input().split()
	(x, y) = (int(x), int(y))
	if h < min(x, y):
		answer = 'NO'
		break
	if h >= max(x, y):
		h = max(x, y)
	else:
		h = min(x, y)
	(a, b) = (x, y)
print(answer)


n = int(input())
l = []
c = 0
h = 1000000007
while n:
	(a, b) = map(int, input().split())
	x = min(a, b)
	y = max(a, b)
	if y <= h:
		h = y
	elif x <= h:
		h = x
	else:
		c = 1
		break
	n = n - 1
print('YES' if c == 0 else 'NO')


R = [sorted(map(int, input().split())) for i in range(int(input()))]
C = R[0][1]
for (s, b) in R[1:]:
	if b <= C:
		C = b
	elif s <= C:
		C = s
	else:
		print('NO')
		exit()
print('YES')


def solve(n, data):
	assert len(data) == n
	IsThereSolution = True
	last_height = max(data[0][0], data[0][1])
	for i in range(1, n):
		if data[i][1] <= last_height:
			last_height = data[i][1]
		elif data[i][0] <= last_height:
			last_height = data[i][0]
		else:
			IsThereSolution = False
			break
	return IsThereSolution

def main():
	n = int(input())
	rect = []
	for i in range(n):
		(h, w) = map(int, input().split())
		if h > w:
			(h, w) = (w, h)
		rect.append([h, w])
	answer = solve(n, rect)
	if answer:
		print('YES')
	else:
		print('NO')
main()


n = int(input())
d = []
ans = 'YES'
for i in range(n):
	(a, b) = map(int, input().split())
	d.append([a, b])
	if i > 0:
		if max(a, b) <= h:
			h = max(a, b)
		elif min(a, b) <= h:
			h = min(a, b)
		else:
			ans = 'NO'
			break
	else:
		h = max(a, b)
print(ans)


n = int(input())
mn = 10 ** 9 + 1
res = True
for i in range(n):
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	x = min(a, b)
	y = max(a, b)
	if y <= mn:
		mn = y
	elif x <= mn:
		mn = x
	else:
		res = False
		break
if res:
	print('YES')
else:
	print('NO')


n = int(input())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
val = 0
check = 1
for j in range(n - 1, -1, -1):
	if l[j][0] < l[j][1]:
		if l[j][0] >= val:
			val = l[j][0]
		elif l[j][1] >= val:
			val = l[j][1]
		else:
			check = 0
	elif l[j][1] >= val:
		val = l[j][1]
	elif l[j][0] >= val:
		val = l[j][0]
	else:
		check = 0
if check == 1:
	print('YES')
else:
	print('NO')


prev = 10 ** 9
for _ in range(int(input())):
	(w, h) = sorted(map(int, input().split()))
	if prev < w:
		print('NO')
		break
	prev = (h, w)[prev < h]
else:
	print('YES')


n = int(input())
rects = []
for _ in range(n):
	rect = [int(i) for i in input().split()]
	rects += [rect]
m = max(rects[0])
for r in rects:
	if min(r) > m:
		print('NO')
		exit()
	if max(r) <= m:
		m = max(r)
	else:
		m = min(r)
print('YES')


n = int(input())
d = 1000000000000000
ans = 'YES'
for i in range(n):
	(x, y) = map(int, input().split())
	a = max(x, y)
	b = min(x, y)
	if d >= a:
		d = a
	elif d >= b:
		d = b
	else:
		ans = 'NO'
		break
print(ans)


import functools

def f(h, t):
	if t[0] <= h:
		return t[0]
	elif t[1] <= h:
		return t[1]
	return -1
rects = [tuple(sorted(map(int, input().split()), reverse=True)) for _ in range(int(input()))]
res = functools.reduce(f, rects, 10 ** 10)
print(('NO', 'YES')[res != -1])


(N, Max) = (int(input()), max(map(int, input().split())))
for i in range(N - 1):
	X = list(map(int, input().split()))
	if Max >= max(X):
		Max = max(X)
	elif Max >= min(X):
		Max = min(X)
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
c = 0
np = []
(l, k) = list(map(int, input().split()))
np.append(max(l, k))
for x in range(n - 1):
	(l, k) = list(map(int, input().split()))
	if max(l, k) > np[-1]:
		if min(l, k) > np[-1]:
			c = 1
			print('NO')
			break
		else:
			np.append(min(l, k))
	else:
		np.append(max(l, k))
if c == 0:
	print('YES')


from sys import stdin

def main():
	(r, H) = (bool(input()), 10 ** 9)
	for s in stdin.read().splitlines():
		(w, h) = map(int, s.split())
		if h < w:
			(h, w) = (w, h)
		if H >= h:
			H = h
		elif H >= w:
			H = w
		else:
			r = False
			break
	print(('NO', 'YES')[r])
main()


cases = int(input())
found = True
rnum = 0
wds = ['NO', 'YES']
for i in range(0, cases):
	ln = [int(j) for j in input().split(' ')]
	num = max(ln)
	if i > 0:
		if num > rnum:
			num = min(ln)
			if num > rnum:
				found = False
				break
	rnum = num
print(wds[found])


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
from collections import *
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def function(arr, size, dp):
	if size == 1 or size == 0:
		return 1
	key = ''.join(map(str, arr[:size]))
	if dp[key]:
		return dp[key]
	output = function(arr, size - 1, dp)
	key = ''.join(map(str, arr[:size - 1]))
	dp[key] = output
	if arr[size - 2] * 10 + arr[size - 1] <= 26:
		output += function(arr, size - 2, dp)
		key = ''.join(map(str, arr[:size - 2]))
		dp[key] = output
	return output

def main():
	n = ii()
	w = []
	h = []
	for _ in range(n):
		(a, b) = mi()
		w.append(a)
		h.append(b)
	h[0] = max(h[0], w[0])
	for i in range(1, n):
		if max(h[i], w[i]) <= h[i - 1]:
			h[i] = max(h[i], w[i])
		elif min(h[i], w[i]) <= h[i - 1]:
			h[i] = min(h[i], w[i])
		else:
			break
	else:
		print('YES')
		exit()
	print('NO')
main()


import os
import sys
from io import BytesIO, IOBase
import math
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')
t = int(input())
(a, b) = map(int, input().split())
l = list()
f = True
ans = True
l.append(max(a, b))
for i in range(1, t):
	(a, b) = map(int, input().split())
	if min(a, b) > l[i - 1]:
		f = False
	elif max(a, b) <= l[i - 1]:
		l.append(max(a, b))
	else:
		l.append(min(a, b))
	if f == False:
		l.append(max(a, b))
		ans = False
if ans:
	print('YES')
else:
	print('NO')


read = lambda : map(int, input().split())
n = int(input())
arr = []
for i in range(n):
	arr.append([*read()])
last = max(arr[0])
for r in arr[1:]:
	mx = max(r)
	mn = min(r)
	if mx <= last:
		last = mx
	elif mn <= last:
		last = mn
	else:
		print('NO')
		exit()
print('YES')


from math import inf

def main():
	n = int(input())
	prev = inf
	for i in range(n):
		(a, b) = map(int, input().split())
		if a <= prev:
			if a < b <= prev:
				prev = b
			else:
				prev = a
		elif b <= prev:
			prev = b
		else:
			print('NO')
			return
	print('YES')
main()


def scanf(obj=list, type=int):
	return obj(map(type, input().split()))
(n,) = scanf()
now = max(scanf())
for i in range(n - 1):
	temp = scanf()
	temp.sort()
	if now < temp[0]:
		print('NO')
		quit()
	if now >= temp[1]:
		now = temp[1]
	else:
		now = temp[0]
print('YES')


n = int(input())
r = []
for _ in range(n):
	(w, h) = map(int, input().split())
	r.append([w, h])
f = 1
temp = max(r[0])
h = [temp]
for i in range(1, n):
	this = r[i]
	if max(this) <= h[-1]:
		h.append(max(this))
	elif min(this) <= h[-1]:
		h.append(min(this))
	else:
		f = 0
		break
if f:
	print('YES')
else:
	print('NO')


n = int(input())
f = 99999999999
for i in range(n):
	(x, y) = map(int, input().split())
	if f >= max(x, y):
		f = max(x, y)
	elif f >= min(x, y):
		f = min(x, y)
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
l = []
r = True
last = 10 ** 10
for i in range(0, n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a > b:
		maxy = a
		miny = b
	else:
		maxy = b
		miny = a
	if last < maxy:
		if last < miny:
			r = False
		last = miny
	else:
		last = maxy
print('YES' if r else 'NO')


n = int(input())
a = [[int(j) for j in input().split()] for i in range(n)]
ans = 1
i = 1
x = max(a[0][0], a[0][1])
while ans and i < n:
	prev_x = x
	x = max(a[i][0], a[i][1])
	if x > prev_x:
		if a[i][0] > prev_x and a[i][1] > prev_x:
			ans = 0
		else:
			x = min(a[i][0], a[i][1])
	i += 1
print('YES' if ans else 'NO')


import copy
import sys
from collections import defaultdict, Counter

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

def mapi():
	return map(int, input().split())

def maps():
	return map(str, input().split())

def print(arg, *argv, end=None):
	sys.stdout.write(str(arg))
	for i in argv:
		sys.stdout.write(' ' + str(i))
	sys.stdout.write(end) if end else sys.stdout.write('\n')

def solve():
	t = 1
	while t:
		t -= 1
		n = int(input())
		tmp = [float('inf')]
		flag = True
		for i in range(n):
			(x, y) = mapi()
			if max(x, y) <= tmp[-1]:
				tmp.append(max(x, y))
			elif min(x, y) <= tmp[-1]:
				tmp.append(min(x, y))
			else:
				flag = False
		if flag:
			print('YES')
		else:
			print('NO')
solve()


from math import inf
n = int(input())
last = inf
flag = True
for _ in range(n):
	(w, h) = map(int, input().split(' '))
	if h < w:
		(w, h) = (h, w)
	if h <= last:
		last = h
	elif w <= last:
		last = w
	else:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
hx = []
hn = []
for i in range(n):
	(w, h) = map(int, input().split())
	hx.append(max(w, h))
	hn.append(min(w, h))
h = hx[0]
c = 0
for i in range(1, n):
	if hx[i] <= h:
		h = hx[i]
	elif hn[i] <= h:
		h = hn[i]
	else:
		c = 1
		print('NO')
		break
if c == 0:
	print('YES')


n = int(input())
v = 10 ** 9 + 1
f = 0
for j in range(0, n):
	x = [int(y) for y in input().split(' ')]
	ma = max(x[0], x[1])
	if ma <= v:
		v = ma
		continue
	mi = min(x[0], x[1])
	if mi <= v:
		v = mi
		continue
	f = 1
	break
if f == 1:
	print('NO')
else:
	print('YES')


n = int(input())
h_max = 10 ** 10
trigger = 1
for i in range(n):
	(h, w) = map(int, input().split())
	if max(h, w) <= h_max:
		h_max = max(h, w)
	elif min(h, w) <= h_max:
		h_max = min(h, w)
	else:
		print('NO')
		trigger = 0
		break
if trigger:
	print('YES')


n = int(input())
(a, fail) = (10 ** 10, False)
for i in range(n):
	if not fail:
		(w, h) = map(int, input().split())
		if max(w, h) <= a:
			a = max(w, h)
		elif min(w, h) <= a:
			a = min(w, h)
		else:
			fail = True
if fail == True:
	print('NO')
else:
	print('YES')


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var):
	print(*var, file=sys.stderr)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n,) = I()
a = []
for i in range(n):
	a.append(sorted(I()))
ans = 'YES'
now = a[0][1]
for i in range(n):
	if a[i][1] <= now:
		now = a[i][1]
	elif a[i][0] <= now:
		now = a[i][0]
	else:
		ans = 'NO'
		break
print(ans)


n = int(input())
ans = True
prev = 1 << 100
for i in range(n):
	(a, b) = sorted(list(map(int, input().split())))
	if b <= prev:
		prev = b
	elif a <= prev:
		prev = a
	else:
		ans = False
		break
print('YES' if ans else 'NO')


n = int(input())
last = 10 ** 10
flag = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if max(a, b) <= last:
		last = max(a, b)
	elif min(a, b) <= last:
		last = min(a, b)
	else:
		flag = 1
if flag == 1:
	print('NO')
else:
	print('YES')


n = int(input())
t = 10 ** 9
import sys
for i in range(n):
	(w, h) = list(map(int, input().split()))
	if t >= max(w, h):
		t = max(w, h)
	elif t >= min(w, h):
		t = min(w, h)
	else:
		print('NO')
		sys.exit()
print('YES')


n = int(input())
a = list()
for i in range(n):
	(x, y) = map(int, input().split())
	if x > y:
		(x, y) = (y, x)
	a.append([x, y])
(ok, big) = (True, a[0][1])
for p in a:
	if p[1] <= big:
		big = p[1]
	elif p[0] <= big:
		big = p[0]
	else:
		ok = False
print(['NO', 'YES'][ok])


n = int(input())
flag = 'YES'
prev = 0
for i in range(n):
	(w, h) = input().strip().split(' ')
	(w, h) = (int(w), int(h))
	if i == 0:
		prev = max(w, h)
	elif prev < min(w, h):
		flag = 'NO'
		break
	elif prev >= max(w, h):
		prev = max(w, h)
	else:
		prev = min(w, h)
print(flag)


n = int(input())
l = []
(w, h) = map(int, input().split())
l.append(max(w, h))
for i in range(n - 1):
	(w, h) = map(int, input().split())
	if l[i] >= max(w, h):
		l.append(max(w, h))
	else:
		l.append(min(w, h))
for i in range(n - 1):
	if l[i] - l[i + 1] < 0:
		print('NO')
		exit()
print('YES')


n = int(input())
works = True
last = [99999999999999999]
for i in range(n):
	rec = [int(i) for i in input().split()]
	rec.sort()
	if rec[1] <= last[-1]:
		last.append(rec[1])
	elif rec[0] <= last[-1]:
		last.append(rec[0])
	else:
		works = False
		break
if works:
	print('YES')
else:
	print('NO')


n = int(input())
dimensions = []
flag = 1
dimensions.append(list(map(int, input().split())))
maximum = max(dimensions[0])
while n > 1:
	dimensions.append(list(map(int, input().split())))
	if maximum >= max(dimensions[-1]):
		maximum = max(dimensions[-1])
		n -= 1
		continue
	elif maximum >= min(dimensions[-1]):
		maximum = min(dimensions[-1])
		n -= 1
		continue
	else:
		flag = 0
		break
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
max_height = 100000000000
pos = True
for a0 in range(n):
	(w, h) = list(map(int, input().strip().split(' ')))
	if max(w, h) <= max_height:
		max_height = max(w, h)
	elif min(w, h) <= max_height:
		max_height = min(w, h)
	else:
		pos = False
if pos:
	print('YES')
else:
	print('NO')


n = int(input())
s = [[]] * n
for i in range(n):
	h = list(map(int, input().split()))
	s[i] = h
k = max(s[0][0], s[0][1])
f = True
for i in range(n):
	if s[i][0] > s[i][1]:
		(s[i][0], s[i][1]) = (s[i][1], s[i][0])
	if s[i][1] <= k:
		k = s[i][1]
	elif s[i][0] <= k:
		k = s[i][0]
	else:
		f = False
		break
if f == False:
	print('NO')
else:
	print('YES')


flag = 1
curr = -1
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if curr == -1:
		curr = max(a, b)
	elif curr >= max(a, b):
		curr = max(a, b)
	elif curr >= min(a, b):
		curr = min(a, b)
	else:
		flag = 0
		break
if flag == 1:
	print('YES')
else:
	print('NO')


n = int(input())
lis = []
for i in range(n):
	lis.append(list(map(int, input().split())))
flag = 0
init = max(lis[0])
for i in lis[1:]:
	temp_lis = sorted(i)
	if temp_lis[0] > init:
		flag = 1
		break
	elif temp_lis[1] <= init:
		init = temp_lis[1]
	else:
		init = temp_lis[0]
if flag == 0:
	print('YES')
else:
	print('NO')


def solve():
	n = int(input())
	(v1, v2) = map(int, input().split())
	v1 = max(v1, v2)
	for i in range(n - 1):
		(t1, t2) = map(int, input().split())
		if min(t1, t2) > v1:
			print('NO')
			return
		elif max(t1, t2) <= v1:
			v1 = max(t1, t2)
		else:
			v1 = min(t1, t2)
	print('YES')
solve()


n = int(input())
(a, b) = map(int, input().split())
height = max(a, b)
for i in range(n - 1):
	(a, b) = map(int, input().split())
	if a == height or b == height:
		continue
	elif min(a, b) > height:
		print('NO')
		exit()
	elif max(a, b) > height:
		height = min(a, b)
	else:
		height = max(a, b)
print('YES')


rectangle_count = input()
rectangle_count = int(rectangle_count)
status = 0
temp = 0
compare = 0
rec_size = input()
rec_size = rec_size.split(' ')
rec_size = list(map(int, rec_size))
compare = max(rec_size)
status = 0
for i in range(1, rectangle_count):
	rec_size = input()
	rec_size = rec_size.split(' ')
	rec_size = list(map(int, rec_size))
	if compare >= max(rec_size):
		compare = max(rec_size)
	elif compare >= min(rec_size):
		compare = min(rec_size)
	else:
		status = status + 1
		break
if status == 0:
	print('YES')
else:
	print('NO')


import sys
n = int(input())
c = 1000000000.0
for i in range(n):
	(a, b) = list(map(int, input().split()))
	d = e = -1
	if a <= c:
		d = a
	if b <= c:
		e = b
	c = max(d, e)
	if c == -1:
		print('NO')
		sys.exit()
print('YES')


n = int(input())
lstl = []
lstr = []
for i in range(n):
	(l, r) = [int(i) for i in input().split()]
	lstl.append(l)
	lstr.append(r)
flag = True
maxi = max(lstl[0], lstr[0])
for i in range(1, n):
	temp1 = max(lstl[i], lstr[i])
	temp2 = min(lstl[i], lstr[i])
	if temp1 <= maxi:
		maxi = temp1
	elif temp2 <= maxi:
		maxi = temp2
	else:
		print('NO')
		flag = False
		break
if flag:
	print('YES')


n = int(input())
a = []
for i in range(0, n):
	a.append([int(i) for i in input().split()])
if a[0][0] > a[0][1]:
	(a[0][0], a[0][1]) = (a[0][1], a[0][0])
flag = 0
for i in range(1, n):
	if a[i][1] > a[i - 1][1]:
		if a[i][0] > a[i - 1][1]:
			flag = 1
			break
		else:
			(a[i][0], a[i][1]) = (a[i][1], a[i][0])
	elif a[i][1] <= a[i - 1][1]:
		if a[i][0] <= a[i - 1][1]:
			if a[i][0] > a[i][1]:
				(a[i][0], a[i][1]) = (a[i][1], a[i][0])
if flag == 1:
	print('NO')
else:
	print('YES')


def main():
	n = int(input())
	(w, h) = [int(i) for i in input().split(' ')]
	h_prev = max(w, h)
	for i in range(1, n):
		(w, h) = [int(i) for i in input().split(' ')]
		h_prev_old = h_prev
		if h > h_prev and w > h_prev:
			print('NO')
			exit()
		else:
			pesi = [h, w]
			h_prev = max([i for i in pesi if i <= h_prev])
	print('YES')
main()


n = int(input())
l1 = list(map(int, input().split()))
ans = 'YES'
if l1[0] > l1[1]:
	mi = l1[0]
else:
	mi = l1[1]
for f in range(n - 1):
	l = list(map(int, input().split()))
	if l[0] > l[1]:
		if l[0] <= mi:
			mi = l[0]
		elif l[1] <= mi:
			mi = l[1]
		else:
			ans = 'NO'
			break
	elif l[1] <= mi:
		mi = l[1]
	elif l[0] <= mi:
		mi = l[0]
	else:
		ans = 'NO'
		break
print(ans)


p = 0
f = 0
for i in range(int(input())):
	(n, m) = map(int, input().split())
	if i == 0:
		p = max(n, m)
	elif p >= max(n, m):
		p = max(n, m)
	elif p >= min(n, m):
		p = min(m, n)
	else:
		f = 1
		break
if f == 1:
	print('NO')
else:
	print('YES')


n = int(input())
tuples = []
for i in range(n):
	tuples.append(tuple([int(x) for x in input().split()]))
current_value = min(tuples[n - 1])
for i in range(n - 2, -1, -1):
	if min(tuples[i]) >= current_value:
		current_value = min(tuples[i])
	elif max(tuples[i]) >= current_value:
		current_value = max(tuples[i])
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
rectangles = []
flag = 0
for i in range(n):
	l = [int(x) for x in input().split()]
	rectangles.append(l)
if rectangles[0][1] < rectangles[0][0]:
	(rectangles[0][1], rectangles[0][0]) = (rectangles[0][0], rectangles[0][1])
for i in range(1, len(rectangles)):
	temp = []
	for elem in rectangles[i]:
		if elem <= rectangles[i - 1][1]:
			temp.append(elem)
	if len(temp) == 0:
		flag = 1
		print('NO')
		break
	if len(temp) == 2:
		temp.pop(temp.index(min(temp)))
	a = rectangles[i].index(temp[0])
	if a == 0:
		(rectangles[i][1], rectangles[i][0]) = (rectangles[i][0], rectangles[i][1])
if flag == 0:
	print('YES')


x = input().strip('\n')
y = []
for i in range(0, int(x)):
	y.append([int(x) for x in input().strip('\n').split(' ')])
p = []
p.append(max(y[0]))
for j in range(1, len(y)):
	if max(y[j]) <= p[j - 1]:
		p.append(max(y[j]))
	else:
		p.append(min(y[j]))
s = 0
for m in range(0, len(p) - 1):
	if p[m] < p[m + 1]:
		print('NO')
		exit()
print('YES')


k = 1000000000
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n <= k and m <= k:
		k = max(n, m)
	elif n <= k:
		k = n
	elif m <= k:
		k = m
	else:
		print('NO')
		break
else:
	print('YES')


def main():
	n = int(input())
	cur_max = max(map(int, input().split()))
	for i in range(1, n):
		(w, h) = map(int, input().split())
		maxi = max(w, h)
		mini = min(w, h)
		if cur_max >= maxi:
			cur_max = maxi
		elif cur_max >= mini:
			cur_max = mini
		else:
			print('NO')
			return
	print('YES')
main()


cnt = lambda s, x: s.count(x)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
dgl = lambda : list(map(int, input()))
n = ii()
l1 = [max(f())]
for _ in range(n - 1):
	(a, b) = f()
	if max(a, b) <= l1[-1]:
		l1.append(max(a, b))
	elif min(a, b) <= l1[-1]:
		l1.append(min(a, b))
	else:
		print('NO')
		exit(0)
print('YES')


n = int(input())
h = 1000000001
for i in range(n):
	x = list(map(int, input().split()))
	a = x[0]
	b = x[1]
	if h >= max(a, b):
		h = max(a, b)
	elif h < min(a, b):
		print('NO')
		break
	else:
		h = min(a, b)
else:
	print('Yes')


import sys
input = sys.stdin.readline
n = int(input())
(a, b) = map(int, input().split())
minh = max(a, b)
f = True
for _ in range(n - 1):
	(w, h) = map(int, input().split())
	if min(w, h) > minh:
		f = False
		break
	elif max(w, h) > minh:
		minh = min(w, h)
	else:
		minh = max(w, h)
print('YES' if f else 'NO')


n = int(input())
ls = []
for i in range(n):
	ls.append(list(map(int, input().split())))
ls = list(reversed(ls))
for i in range(n):
	if not i and ls[0][0] < ls[0][1]:
		(ls[0][0], ls[0][1]) = (ls[0][1], ls[0][0])
	elif not i:
		continue
	elif ls[i - 1][1] <= min(ls[i][0], ls[i][1]):
		if ls[i][0] < ls[i][1]:
			(ls[i][0], ls[i][1]) = (ls[i][1], ls[i][0])
	elif ls[i - 1][1] <= max(ls[i][0], ls[i][1]):
		if ls[i][0] > ls[i][1]:
			(ls[i][0], ls[i][1]) = (ls[i][1], ls[i][0])
	else:
		print('NO')
		exit()
print('YES')


num_int_input = input()
n = int(num_int_input)
rect_list = []
for i in range(n):
	rectangle = input().split()
	width = int(rectangle[0])
	height = int(rectangle[1])
	rect_list.append([width, height])
can_order = True
width = rect_list[0][0]
height = rect_list[0][1]
highest = width if width > height else height
for i in range(n):
	width = rect_list[i][0]
	height = rect_list[i][1]
	if width > highest and height > highest:
		can_order = False
		break
	elif width > highest and height <= highest:
		highest = height
	elif width <= highest and height > highest:
		highest = width
	else:
		highest = width if width > height else height
if can_order:
	print('YES')
else:
	print('No')


def main():
	n = int(input())
	(leaul, last) = sorted(map(int, input().split()))
	for i in range(n - 1):
		(w, h) = map(int, input().split())
		if last >= max(w, h):
			last = max(w, h)
		elif last >= min(w, h):
			last = min(w, h)
		else:
			print('NO')
			exit(0)
	print('YES')
main()


n = int(input())
w = []
h = []
for i in range(n):
	(wi, he) = list(map(int, input().split()))
	w.append(min(wi, he))
	h.append(max(wi, he))
flag = 1
for i in range(1, n):
	if h[i] <= h[i - 1]:
		continue
	elif w[i] <= h[i - 1]:
		h[i] = w[i]
	else:
		flag = 0
		break
if flag == 0:
	print('NO')
else:
	print('YES')


n = int(input())
c = 10 ** 10
for i in range(n):
	(w, h) = sorted(map(int, input().split()))
	if h <= c:
		c = h
	elif w <= c:
		c = w
	else:
		c = 0
print(['NO', 'YES'][c > 0])


n = int(input())
a = 0
aa = 0
for i in range(n):
	q = input()
	w = q.split()
	z = int(w[0])
	x = int(w[1])
	if i > 0:
		if max(z, x) <= a:
			aa += 1
			a = max(z, x)
		elif min(z, x) <= a:
			aa += 1
			a = min(z, x)
	else:
		aa += 1
		a = max(z, x)
if aa == n:
	print('YES')
else:
	print('NO')


import sys
amount = int(input())
curr = 10000000000.0
for i in range(amount):
	(w, h) = [int(s) for s in input().split()]
	if max(w, h) <= curr:
		curr = max(w, h)
	elif min(w, h) <= curr:
		curr = min(w, h)
	else:
		print('NO')
		sys.exit(0)
print('YES')


def get_ints():
	return list(map(int, input().split()))
valid = True
m = 1000000000.0
for _ in range(int(input())):
	(x, y) = get_ints()
	j = max(x, y)
	if j <= m:
		m = j
	elif min(x, y) <= m:
		m = min(x, y)
	else:
		valid = False
		break
print('YES' if valid else 'NO')


t = int(input())
ruined = 0
old = []
for i in range(t):
	old.append([int(x) for x in input().split()])
init = max(old[0])
for i in range(1, t):
	if max(old[i]) <= init:
		init = max(old[i])
	elif min(old[i]) <= init:
		init = min(old[i])
	else:
		ruined = 1
		break
if ruined:
	print('NO')
else:
	print('YES')


n = int(input())
l1 = []
for val in range(0, n):
	l2 = []
	(x, y) = map(int, input().split())
	l2.append(x)
	l2.append(y)
	l1.append(l2)
k = max(l1[0])
s = 1
p = 0
while s < len(l1):
	if l1[s][0] > l1[s][1]:
		if l1[s][0] <= k:
			k = l1[s][0]
		elif l1[s][1] <= k:
			k = l1[s][1]
		else:
			p = 1
			break
	elif l1[s][1] <= k:
		k = l1[s][1]
	elif l1[s][0] <= k:
		k = l1[s][0]
	else:
		p = 1
		break
	s = s + 1
if p == 1:
	print('NO')
else:
	print('YES')


n = int(input())
l = []
done = 0
for i in range(n):
	(a, b) = map(int, input().split())
	x = max(a, b)
	y = min(a, b)
	if len(l) == 0:
		l.append(x)
	else:
		z = l[len(l) - 1]
		if y > z:
			done = 1
		elif x > z and y <= z:
			l.append(y)
		else:
			l.append(x)
if done == 1:
	print('NO')
else:
	print('YES')


def turn_the_rectangles():
	n_rectangles = int(input())
	if n_rectangles == 0:
		print('YES')
		return
	heights = []
	wh = input().split()
	(width, height) = [int(x) for x in wh]
	heights.append(max(width, height))
	for _ in range(0, n_rectangles - 1):
		wh = input().split()
		(width, height) = [int(x) for x in wh]
		max_height = max(width, height)
		min_height = min(width, height)
		if max_height <= heights[-1]:
			heights.append(max_height)
		elif min_height <= heights[-1]:
			heights.append(min_height)
		else:
			print('NO')
			return
	print('YES')
turn_the_rectangles()


inf = 1061109567
n = int(input())
last = inf
flag = 1
for i in range(n):
	(x, y) = map(int, input().split())
	maxx = max(x, y)
	minn = min(x, y)
	if minn > last:
		flag = 0
	elif maxx <= last:
		last = maxx
	else:
		last = minn
if flag == 1:
	print('YES')
else:
	print('NO')


n = int(input())
a = []
z = 0
for i in range(n):
	b = list(map(int, input().split()))
	a.append(b)
temp = min(a[n - 1])
for i in range(n - 2, -1, -1):
	if temp <= a[i][0] or temp <= a[i][1]:
		if temp <= a[i][1] and temp <= a[i][0]:
			temp = min(a[i])
			z = 1
		elif temp <= a[i][0]:
			temp = a[i][0]
			z = 1
		else:
			temp = a[i][1]
			z = 1
	else:
		z = 0
		break
if z != 0:
	print('YES')
elif n == 1:
	print('YES')
else:
	print('NO')


n = int(input())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
m = max(l[0])
f = 0
for i in range(1, n):
	if max(l[i]) <= m:
		p = max(l[i])
	else:
		p = min(l[i])
	if p > m:
		f = 1
		break
	else:
		m = p
if f == 1:
	print('NO')
else:
	print('YES')


n = int(input())
w = []
h = []
for i in range(n):
	(x, y) = map(int, input().split())
	w.append(x)
	h.append(y)
f = True
h[0] = max(w[0], h[0])
for i in range(1, n):
	if min(w[i], h[i]) > h[i - 1]:
		f = False
		break
	elif max(w[i], h[i]) <= h[i - 1]:
		h[i] = max(w[i], h[i])
	else:
		h[i] = min(w[i], h[i])
if not f:
	print('NO')
else:
	print('YES')


h = float('inf')
n = int(input())
for _ in range(n):
	(a, b) = sorted(map(int, input().split()))
	if b <= h:
		h = b
	elif a <= h:
		h = a
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
list = [10000000000]
for i in range(n):
	(x, y) = map(int, input().split())
	if min(x, y) <= list[-1] and max(x, y) > list[-1]:
		list.append(min(x, y))
	if max(x, y) <= list[-1]:
		list.append(max(x, y))
print('YES' if len(list) - 1 == n else 'NO')


n = int(input())
non_ascending = True
last = 90000000000.0
for i in range(n):
	(w, h) = map(int, input().split(' '))
	ma = max(w, h)
	mi = min(w, h)
	if ma <= last:
		last = ma
	elif mi <= last:
		last = mi
	else:
		non_ascending = False
print('YES' if non_ascending else 'NO')


n = int(input())
(greater, lesser) = map(int, input().split())
height = max(greater, lesser)
for _ in range(n - 1):
	(greater, lesser) = map(int, input().split())
	if lesser > greater:
		(greater, lesser) = (lesser, greater)
	if lesser > height:
		print('NO')
		exit()
	elif greater <= height:
		height = greater
	else:
		height = lesser
print('YES')


def main():
	n = int(input())
	if n == 1:
		print('YES')
		return 0
	lst = [tuple(map(int, input().split())) for _ in range(n)]
	c = 0
	if max(lst[0]) < min(lst[1]):
		print('NO')
		return 0
	for i in range(1, n + 1):
		if min(lst[-i]) >= c:
			c = min(lst[-i])
		elif max(lst[-i]) >= c:
			c = max(lst[-i])
		else:
			print('NO')
			return 0
	print('YES')
	return 0
main()


def main():
	n = int(input())
	h_prev = 10 ** 9
	for i in range(n):
		(w, h) = [int(i) for i in input().split(' ')]
		if min(w, h) > h_prev:
			print('NO')
			exit()
		else:
			h_prev = max([i for i in [h, w] if i <= h_prev])
	print('YES')
main()


n = int(input())
prevH = 1000000000.0
rs = True
for i in range(n):
	l = input().split()
	l[0] = int(l[0])
	l[1] = int(l[1])
	_max = max(l)
	_min = min(l)
	if prevH < _min:
		rs = False
		break
	if prevH >= _max:
		prevH = _max
	else:
		prevH = _min
print('YES') if rs == True else print('NO')


n = int(input())
last = int(1000000000.0 + 1)
may = True
while n != 0:
	(w, h) = map(int, input().split())
	m = max(w, h)
	g = min(w, h)
	if m <= last:
		last = m
	elif g <= last:
		last = g
	else:
		print('NO')
		may = False
		break
	n -= 1
if may:
	print('YES')


before_height = 10 ** 9 + 1
cnt = int(input())

def choose_height(num1, num2, pre_height):
	big = num1 if num1 > num2 else num2
	small = num1 if num1 < num2 else num2
	if big <= pre_height:
		return big
	elif small <= pre_height:
		return small
	else:
		return -1
result = True
while cnt > 0:
	num = input().split()
	num1 = int(num[0])
	num2 = int(num[1])
	before_height = choose_height(num1, num2, before_height)
	if before_height == -1:
		result = False
	cnt -= 1
if result:
	print('YES')
else:
	print('NO')


x = int(input())
a = []
for i in range(x):
	y = input()
	a.append(y.split())
maxx = max(int(a[0][0]), int(a[0][1]))
for i in range(1, x):
	if maxx >= max(int(a[i][0]), int(a[i][1])):
		maxx = max(int(a[i][0]), int(a[i][1]))
	elif maxx >= min(int(a[i][0]), int(a[i][1])):
		maxx = min(int(a[i][0]), int(a[i][1]))
	else:
		print('NO')
		exit()
print('YES')


def isSorted(a):
	for i in range(1, len(a)):
		if a[i] > a[i - 1]:
			return False
	return True
n = int(input())
(l, h) = (n * [0], n * [0])
c = [0] * n
for i in range(n):
	(l[i], h[i]) = map(int, input().split())
c[0] = max(l[0], h[0])
for i in range(1, n):
	if l[i] <= c[i - 1] and h[i] <= c[i - 1]:
		c[i] = max(h[i], l[i])
	else:
		c[i] = min(h[i], l[i])
if isSorted(c):
	print('YES')
else:
	print('NO')


n = int(input())
(a, b) = map(int, input().split())
flag = True
m = max(a, b)
for i in range(n - 1):
	(a, b) = map(int, input().split())
	if m >= a and m < b:
		m = a
	elif m >= b and m < a:
		m = b
	elif m >= a and m >= b:
		m = max(a, b)
	else:
		flag = False
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
l = []
for i in range(n):
	(w, h) = map(int, input().split())
	l.append((min(w, h), max(w, h)))
ok = True
i = 1
p = l[0][1]
while i < n and ok:
	if p < l[i][0]:
		ok = False
	elif p >= l[i][1]:
		p = l[i][1]
	else:
		p = l[i][0]
	i += 1
print('YES' if ok else 'NO')


from sys import exit
n = int(input())
a = [input().split() for i in range(n)]
prv = 1234567890
for i in range(0, n):
	mn = min(int(a[i][0]), int(a[i][1]))
	mx = max(int(a[i][0]), int(a[i][1]))
	if prv < mn:
		print('NO')
		exit()
	prv = mx if mx <= prv else mn
print('YES')


k = int(input())
cur_min_vys = 0
min_vys = 0
v = 0
for i in range(k):
	inp = list(map(int, input().split()))
	cur_min_vys = min(inp)
	if cur_min_vys <= min_vys and max(inp) <= min_vys:
		min_vys = max(inp)
		continue
	elif cur_min_vys <= min_vys and max(inp) > cur_min_vys:
		min_vys = cur_min_vys
		continue
	elif min_vys == 0:
		min_vys = max(inp)
		continue
	elif cur_min_vys > min_vys:
		print('NO')
		v = 1
		break
if v == 0:
	print('YES')


n = int(input())
w_h = list(map(int, input().split()))
pre_side = max(w_h)
flag = True
for _ in range(1, n):
	w_h = list(map(int, input().split()))
	min_side = min(w_h)
	max_side = max(w_h)
	if pre_side >= max_side:
		pre_side = max_side
	elif pre_side >= min_side:
		pre_side = min_side
	else:
		flag = False
if flag == True:
	print('YES')
else:
	print('NO')