Under construction

Still being built. Things may change

ICPC Square

Time limit1sMemory limit2048 MB

Summary
Given N, D, and S, find the highest floor reachable from S by moving from floor x to a multiple y of x where y minus x is at most D.
Level

Medium6 of 10

Topics
Number theory, Dynamic programming, Math
Solved
No attempts yet

Problem

ICPC Square is a hotel provided by the ICPC Committee for the accommodation of the participants. It has NN floors, numbered from 1 to NN. The hotel has an unusual elevator. A person on floor xx can ride the elevator once to floor yy if and only if yy is a multiple of xx and y−x≤Dy - x ≤ D.

You are currently on floor SS. You can ride the elevator zero or more times. Find the highest floor you can reach.

Input

A single line contains three integers NN, DD, and SS (2≤N≤10122 ≤ N ≤ 10^{12}; 1≤D≤N−11 ≤ D ≤ N - 1; 1≤S≤N1 ≤ S ≤ N).

Output

Print a single integer, the highest floor you can reach by riding the elevator zero or more times.

Examples2

  1. Example 1

    Input
    64 35 3
    
    Expected output
    60
    
  2. Example 2

    Input
    2024 2023 1273
    
    Expected output
    1273