Under construction

Still being built. Things may change

Fading Wind

Time limit1sMemory limit1024 MB

Summary
Simulate a paper airplane's height and velocity under a fading wind and output the total horizontal distance it travels.
Level

Easy2 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Problem

You are competing in an outdoor paper airplane flying contest, and you want to predict how far your paper airplane will fly. Your design has a fixed factor kk. If the airplane's velocity is at least kk, it rises. If its velocity is less than kk, it descends.

Here is how your paper airplane flies:

  • You start by throwing the airplane with a horizontal velocity of vv at a height of hh. An external wind blows with a strength of ss.

  • While h>0h > 0, repeat the following sequence:

    • Increase vv by ss. Then, decrease vv by max⁡(1,⌊v10⌋)\max(1, \left\lfloor \frac{v}{10} \right\rfloor). Here ⌊v10⌋\left\lfloor \frac{v}{10} \right\rfloor is v10\frac{v}{10} rounded down to the nearest integer.
    • If v≥kv \ge k, increase hh by one.
    • If 0<v<k0 < v < k, decrease hh by one. If hh is zero after the decrease, set vv to zero.
    • If v≤0v \le 0, set hh to zero and vv to zero.
    • The airplane now travels horizontally by vv units.
    • If s>0s > 0, decrease ss by 11.

Compute how far the paper airplane travels horizontally.

Input

The single line of input contains four integers hh, kk, vv, and ss (1≤h,k,v,s≤103)(1 \le h, k, v, s \le 10^3), where hh is the starting height, kk is the fixed factor, vv is the starting velocity, and ss is the strength of the wind.

Output

Output a single integer, the horizontal distance the airplane travels. The distance is always an integer.

Examples4

  1. Example 1

    Input
    1 1 1 1
    
    Expected output
    1
    
  2. Example 2

    Input
    2 2 2 2
    
    Expected output
    9
    
  3. Example 3

    Input
    1 2 3 4
    
    Expected output
    68
    
  4. Example 4

    Input
    314 159 265 358
    
    Expected output
    581062