Indicator
InterviewTime limit2sMemory limit1024 MB
Given a cyclic counter from 1 to m, find the fewest button presses that move it from a to b.
- Level
Easy1 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Losyash decided to take up running and borrowed a stopwatch from Pin. A few weeks later he was fitter and started running more than one lap at a time at the stadium. That is when he ran into a classic athletics problem: if you run long enough, you lose track of how many laps you have finished and how many are left. Luckily the stopwatch had an indicator that shows the current lap number. Each time he crossed the finish line, he pressed a button on the stopwatch and the number on the indicator went up by one.
What kind of indicator can show arbitrarily large natural numbers? None. The indicator is built around a gear with teeth. The teeth have the natural numbers from 1 to written on them, and the gear turns each time the button is pressed. So if the indicator shows and the button is pressed, the display resets to 1.
After one run, Losyash remembered that Sovunya had asked to borrow the stopwatch so she could cook Sichuan sauce exactly by the recipe. Losyash loves that sauce, so he went to Sovunya's place right away. He also wanted to make her happy by setting the indicator to , her favorite number. Since is between 1 and , the indicator can show it. At that moment the indicator showed .
Losyash did not want to do anything extra, so he decided to press the button as few times as possible to make the indicator show . He was too lazy to count the presses he had made, so that count is up to you.
Input
The first line contains the integer , the largest value the indicator can show ().
The second line contains the integer , the value the indicator initially showed ().
The third line contains the integer , Sovunya's favorite number ().
Output
Print one integer: the minimum number of button presses needed for the indicator to show .
Hint
In the first example the stopwatch already shows Sovunya's favorite number, so nothing needs to be done.
In the second example three presses are needed: .
In the third example four presses are needed: .