ICPC

Two batteries alternate powering a phone whose drain rate A exceeds the recharge rate B; find how many whole seconds the system lasts.

Medium6MathSimulationBinary searchImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

"I once met an interesting guy who had a phone with two batteries." (Dudu, 2014)

After meeting that man, Dudu decided to build a phone with a pair of batteries for his upcoming trip to Thailand.

His company, Interesting Chap Phone Charging (ICPC), developed a dual battery technology. While one battery supplies the phone, the other one is recharged through a solar receptor.

The catch is that the phone uses energy faster than a battery can be recharged. ICPC wants to know how many seconds such a system lasts before it runs completely out of charge.

Input

Four integers AA, BB, CC, DD are given. AA is the rate at which the phone uses energy in amperes (coulombs per second), BB is the rate at which a battery is recharged in amperes, CC is the initial charge of the first battery in coulombs, and DD is the initial charge of the second battery in coulombs.

ICPC's batteries have infinite capacity, and the phone switches from one battery to the other instantaneously. The phone starts on the first battery.

  • 0A,B,C,D<2310 \le A, B, C, D < 2^{31}
  • A>BA > B

Output

Print one integer, the number of seconds the phone lasts on an ICPC dual battery. Round the answer down if it is not an integer.

Hint

Follow the case A=5A = 5, B=1B = 1, C=10C = 10, D=10D = 10.

The phone starts on the first battery. After 2 seconds that battery is completely depleted, and the second battery has been charged up to 12 coulombs.

The second battery takes 2.4 seconds to deplete, and by then the first battery holds 2.4 coulombs. Time to switch back to the first battery.

After 0.48 more seconds the first battery is empty and the second one holds 0.48 coulombs.

The process continues for an extra 0.12 seconds until neither battery has any power left. The number of battery swaps is infinite.