Hide

Problem F
Gift Box

Languages en pt

John loves boxes. His wife Maria wants to surprise him for his birthday and give him a beautiful box as a gift, and when John opens that box, there will be another box inside it! Of course, when John opens that second box, there will be another box inside it and so on, until the last box, that will be empty.

The problem with that is that it’s not always possible to put one box inside another. Every box has three dimensions, $c$, $l$ and $h$. A box $j$ can be put inside box $i$ if there is a way to rotate $j$ (permute $j_ c$, $j_ l$ and $j_ h$) in such a way that $j_ c < i_ c$, $j_ h < i_ h$ and $j_ l < i_ l$.

Maria is now afraid she might not be able to give her husband all the boxes she bought in the way she intended. Please help Maria.

Input

The first line of input will consist of an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$), the number of boxes Maria has. $n$ lines will follow, each one with three integers, $i_ c$, $i_ l$ and $i_ h$ ($1 \leq i_ c, i_ l, i_ h \leq 10^9$), corresponding to the dimensions of the $i$-th box.

Output

Print “S” if Maria can gift all the boxes to her husband in the way she wants to and “N” if she can’t.

Sample Input 1 Sample Output 1
3
1 1 1
2 2 2
3 3 3
S
Sample Input 2 Sample Output 2
3
1 2 3
2 3 4
3 4 5
S
Sample Input 3 Sample Output 3
3
10 30 20
50 38 42
13 23 28
N

Please log in to submit a solution to this problem

Log in