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: interview

Starter code:

Solutions:
n = int(input())

data = []

for i in range(n):
    a, b = list(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())
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')

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")


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")
        return

print("YES")

n = int(input())
p = []
for i in range(n):
    a, b = list(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])


def main():
    #string         input()
    #int            int(input())
    #listOfStrings  input().split()
    #ints           map(int, input().split())
    #listOfInts     list(map(int, input().split()))
    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()

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())
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')
        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")

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())
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())
f=0
for i in range(n):
  if(i==0):
    a,b=list(map(int,input().split()))
    mini=max(a,b)
  else:
    a,b=list(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")
      




import math as ma
from decimal import Decimal as dec
def li():
    return list(map(int , input().split()))
def num():
    return list(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)
	else:
		if(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())
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")


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())
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())
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')
        return
print('YES')

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())
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())
ans = "YES"
a = int(1e9)
for _ in range(n):
    h, w = list(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())
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())
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())
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:
        print('NO');return
print('YES')

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")