#P11100. Maximum Optimal Multiple

    ID: 13158 Type: Default 1000ms 256MiB

Maximum Optimal Multiple

Maximum Optimal Multiple

Given two positive integers x and y, consider all multiples of x. These multiples are "optimal" in the sense that each yields the same absolute difference (profit) when compared with y if they are the two closest to y. However, when y is exactly in the middle of two multiples of x (i.e. the profit is the same), the two optimal multiples are different. Your task is to determine the maximum among these optimal multiples.

Note: The optimal multiple is defined as the multiple of x which is closest to y. In the event of a tie, output the larger multiple.

For example, if x = 4 and y = 6, the two closest multiples are 4 and 8 with equal differences (2). The answer is 8.

inputFormat

The input consists of two space-separated integers: x and y.

Constraints:

  • 1 ≤ x, y ≤ 109

outputFormat

Output a single integer representing the maximum optimal multiple of x that is closest to y (if there is a tie, output the larger one).

sample

5 12
10