Flatland Fidget Spinner

Hello everyone,
Can you give help with this problem, do you have any code for it

Here is the link for the problem:
https://open.kattis.com/problems/fidgetspinner

Thanks for help
Best Regards