Sponsored
Use these hints if you're stuck. Try solving on your own first.
Since the constraints are very small, you can simulate the process described.
Solve with full IDE support and test cases