Rotate the rectangles
In a sequence, there are n rectangles. Each rectangle can either be rotated by 90 degrees or left in its original orientation. Rotating a rectangle swaps its height and width. You have the option to rotate any number of rectangles, including all or none. The sequence of rectangles must remain unchanged.
Your task is to determine whether it's possible to rotate the rectangles such that their heights are in non-increasing order. This means that after any rotations, the height of each rectangle should be less than or equal to the height of the preceding rectangle.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5
) – the number of rectangles. Each of the following n lines contains two integers w[i]
, h[i]
(1 ≤ w[i]
, h[i]
≤ 10^9
) – representing the width and height of the i-th rectangle.
Output
Print "YES" (without quotes) if it is possible to arrange the rectangles so that their heights are in non-increasing order, otherwise print "NO".