#P7909. Candy Distribution Reward

    ID: 21094 Type: Default 1000ms 256MiB

Candy Distribution Reward

Candy Distribution Reward

You are one of n children in the Red Sun Kindergarten, where n ≥ 2. One day, you discover infinitely many candies in the backyard. You plan to take some candies back to distribute among all the n children.

However, being just an ordinary kindergarten child, your strength is limited so that you can carry at most R candies. On the other hand, if you take too few, the candies will not be enough for a fair distribution; therefore, you must take at least L candies. It is guaranteed that n ≤ L ≤ R.

The distribution process is as follows: if you take k candies (with L ≤ k ≤ R), you put them in a basket. Then, as long as the basket contains at least n candies, all n children (including yourself) each take exactly one candy from the basket. This process repeats until the basket has fewer than n candies. The candies remaining in the basket become your reward for carrying the candies (note that this reward is only the leftover candies, not the total candies you receive).

Your goal is to choose a number of candies k (where L ≤ k ≤ R) such that the number of reward candies (i.e. the remainder when k is divided by n) is maximized. Formally, you want to maximize
$$\;reward = k \bmod n\;.$$

Write a program that takes n, L, and R as input and outputs the maximum number of reward candies you can obtain.

inputFormat

The input consists of a single line containing three integers n, L, and R separated by spaces, where n ≥ 2 and n ≤ L ≤ R.

outputFormat

Output a single integer representing the maximum number of reward candies obtainable.

sample

3 5 8
2