#P1107. Cat and Persimmon Trees

    ID: 13125 Type: Default 1000ms 256MiB

Cat and Persimmon Trees

Cat and Persimmon Trees

A caring student, Lei Tao, has been taking care of an injured kitten in his dormitory. One day after class, he finds that the kitten is missing – later he discovers it lazily staring at the persimmon trees outside. In front of the dormitory there are N persimmon trees, each of the same height H. In winter, although all the leaves have fallen, the trees remain laden with bright persimmons.

The agile kitten embarks on its "persimmon eating action" as follows:

  1. The kitten starts by jumping from the dormitory balcony onto the top (height H) of any one of the N trees. At that moment, if there is a persimmon, it is immediately eaten.
  2. After the initial jump, the kitten must visit all the trees (one by one). When the kitten is on a tree, it may perform as many vertical jumps as it wishes. Each vertical jump takes it exactly 1 unit down along the same tree. Every time the kitten lands (or is at a position) on a tree where a persimmon still hangs, it will eat that persimmon immediately.
  3. However, once the kitten leaves a tree, any persimmons that have not been eaten on that tree will fall off and are lost forever. Hence, on each tree the kitten can only collect the persimmons from the portion of the tree it traverses before leaving.
  4. To move from the current tree to another one, the kitten may perform a horizontal jump at any moment. In such a jump, the kitten leaves the current tree at its current height x and lands on any other tree at height x - Δ (i.e. its height drops by a fixed amount Δ during the jump). Upon landing on the new tree, the persimmon at that position is eaten.
  5. This process continues until the kitten eventually reaches the ground (height 0).

The kitten must visit every tree. In other words, it begins on one tree and is forced to perform exactly N - 1 horizontal jumps to visit all N trees. Notice that once a tree is left the remaining persimmons on that tree are lost. Thus, on each tree the kitten has control over how many vertical jumps it performs before taking the horizontal jump. On the tree where it finishes (the last one visited) it descends all the way to the ground (collecting persimmons along the way).

If the kitten uses a strategy in which it performs immediate horizontal jumps (i.e. it does no vertical jumps on a tree before switching), then on the first N - 1 trees it gains exactly 1 persimmon (the one at the landing position) on each tree, and on the last tree it collects all persimmons from its starting height down to height 1. Note that when performing a horizontal jump, the height drop is Δ. Since the kitten starts at height H on the first tree, after N - 1 horizontal jumps its landing height on the final tree will be H - (N - 1)·Δ. To be able to land on a tree (i.e. to have at least height 1 to collect a persimmon), we must have:

H(N1)Δ1.H - (N - 1)\cdot Δ \ge 1.

Under this necessary condition, one optimal strategy is to delay vertical jumps in such a way that the total number of persimmons collected is maximized. It turns out that no matter how the kitten mixes vertical jumps with horizontal jumps, the maximum total number of persimmons it can collect is given by

Answer=H(N1)(Δ1).\text{Answer} = H - (N - 1)\,(Δ - 1).

Your task is to help Lei Tao determine, given the number of trees N, the height of each tree H, and the drop in height when jumping horizontally Δ, the maximum number of persimmons the kitten can eat. You may assume that the input always satisfies the feasibility condition $$ H \ge (N - 1)\,Δ + 1. $$

inputFormat

The input consists of a single line containing three integers: N, H, and Δ (Delta), where

  • N (1 ≤ N ≤ 105) is the number of persimmon trees,
  • H (1 ≤ H ≤ 109) is the height of each tree,
  • Δ (1 ≤ Δ ≤ 109) is the height loss when making a horizontal jump.

It is guaranteed that the feasibility condition H ≥ (N - 1)·Δ + 1 holds.

outputFormat

Output a single integer, the maximum number of persimmons the kitten can eat.

Note: Under the optimal strategy the answer is given by

H(N1)(Δ1).H - (N - 1)(Δ - 1).

sample

3 10 2
8