A neighborhood grocery co-op tags every item in its catalog feed with two independent flags: whether the item is low-fat, and whether its packaging is recyclable. For this season's "Green & Healthy" shelf, the co-op wants to feature only the items that qualify on both counts at once.
Given the catalog feed, output the ids of every item whose low-fat flag AND recyclable-packaging flag are both set to yes, listed in the same relative order the items appear in the feed.
The first line contains a single integer n, the number of catalog items.
Each of the next n lines contains three space-separated tokens: product_id (an integer), low_fat (either Y or N), and recyclable (either Y or N).
Print the ids of all qualifying items, space-separated on a single line, in their original feed order. If no item qualifies, print an empty line.
Y or N.Example 1
Input
5 1 Y Y 2 Y N 3 N Y 4 Y Y 5 N N
Expected
1 4
Explanation
Item 1 is low-fat and recyclable, so it qualifies. Item 2 is low-fat but not recyclable. Item 3 is recyclable but not low-fat. Item 4 is low-fat and recyclable, so it qualifies. Item 5 is neither. In feed order the qualifying ids are 1 and 4.
Example 2
Input
3 10 N Y 20 N N 30 Y N
Expected
(empty)Explanation
None of the three items has both flags set to Y: item 10 is only recyclable, item 20 is neither, and item 30 is only low-fat. No item qualifies, so the output is an empty line.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →