Time limit
2s
Memory limit
128 MB
Youngsik and his friends sit in a circle. The seats are numbered from 1 through N in clockwise order.
At first, the person in seat 1 receives the ball. Whenever a person receives the ball, they throw it to someone else according to how many times they have received the ball so far, including the ball they just received.
The game ends as soon as any person has received the ball M times. Find the total number of throws made before the game ends.
The first line contains three integers N, M, and L.
Print one integer: the total number of times the ball is thrown.
In the first visible test, seat 1 receives the ball first. The ball then moves through seats 1 -> 3 -> 5 -> 2 -> 4 -> 1 -> 4 -> 2 -> 5 -> 3 -> 1. Seat 1 receives the ball for the third time, so the game ends after 10 throws.