Fallen Crystals

Given N crystals with distinct strengths and a hidden target at rank K, minimize the worst-case number of swings to break it using forces up to P without risking an explosion (force gap W).

Hard8Binary searchGame theoryDynamic programmingNo attempts yetTime limit1sMemory limit512 MB

Problem

MM mana crystals fell on New Namustrum. The dead rose after the crystals landed, and Marko, the head of the village, captured Kul'den, the wizard who raised them. Under questioning, Kul'den admitted that the MM mana crystals feed mana to the risen dead and that destroying every crystal stops them. The village owns a blunt hammer, and one swing applies force to exactly one crystal.

While Marko was breaking the crystals one at a time, a large explosion went off. Medivh, the village archmage, analyzed the cause and found that a crystal holding a large amount of condensed mana overloads and explodes when it is struck with a force far greater than the force needed to break it. Tassadar, the village shaman, appraised the NN remaining crystals and determined that exactly one of them holds condensed mana and that this crystal is the KK-th strongest of the NN. So K1K-1 crystals are stronger than it and NKN-K crystals are weaker. The remaining crystals all have different strengths and the full order of strengths is known, but nobody knows the actual strength values.

The strengths are distinct positive real numbers, all at most PP. Lindhol the blacksmith fixes a positive real number pp at most PP in his head and applies exactly that force to a crystal. A crystal of strength XX struck with a force of XX or more breaks and disappears, and a crystal that is gone cannot be struck again. A force below XX does nothing. The crystal with condensed mana is the exception: striking it with a force stronger than its strength by WW or more, that is with a force of at least X+WX + W, makes it explode.

You tell Lindhol which crystal by strength rank to hit and with how much force, one order at a time, and you learn at once whether that crystal broke. You may never give an order that carries any chance of an explosion. Whatever the true strengths are, you want to break the condensed crystal without an explosion, using a strategy that makes the largest possible number of swings as small as it can be. Find the number of swings in the worst case under that strategy.

Input

The first line contains four integers NN, KK, PP, WW separated by spaces. In order they are the number of remaining mana crystals NN, the strength rank of the crystal with condensed mana KK, the maximum power of the blunt hammer PP, and the force gap that causes an explosion WW. (1N10001 \le N \le 1000, 1KN1 \le K \le N, 1P20001 \le P \le 2000, 1WP1 \le W \le P)

Inputs for which no assignment of strengths satisfies the conditions are not given.

Output

Print on one line the number of hammer swings needed to break the crystal with condensed mana in the worst case, under a strategy that minimizes that number.