Russian Dolls
Time limit1sMemory limit128 MB
Given 2n dolls with height, diameter, and wall thickness, decide whether they can be split into two chains of n that each nest perfectly.
Problem
Russian nesting dolls are hollow wooden figures. Within a set the dolls have the same shape but different sizes: the largest doll holds the second largest, which holds the third largest, and so on.
Model each doll as a cylinder of height , diameter , and wall thickness . Its hollow interior then has height and diameter . Doll fits inside doll , standing straight up, exactly when 's outer height and outer diameter both fit within 's hollow: that is, when 's height is at most and 's diameter is at most .
Boris and Natasha each own a set of dolls. Their two sets were mixed together into a single pile of dolls. Decide whether the pile can be sorted back into two proper nesting sets of exactly dolls each — that is, whether the dolls can be partitioned into two groups of so that, within each group, every doll nests inside the next-larger one.
Input
The input contains several test cases. Each test case begins with a line containing , the number of dolls in one set (). The next lines each contain three integers , , — the height, diameter, and wall thickness of one doll (). A line containing a single follows the last test case.
Output
For each test case, print a single line: YES if the dolls can be separated into two nesting sets of exactly dolls each, or NO otherwise.