Sponsored
Use these hints if you're stuck. Try solving on your own first.
Can we process the queries in a smart order to avoid repeatedly checking the same items?
How can we use the answer to a query for other queries?
Solve with full IDE support and test cases