Sponsored
Use these hints if you're stuck. Try solving on your own first.
All the queries are given in advance. Is there a way you can reorder the queries to avoid repeated computations?
Solve with full IDE support and test cases