#P1292. 倒酒

倒酒

Description

Winy is the owner of a bar. His bar offers two volumes of beer, aa ml and bb ml, served in cups with capacities aa ml and bb ml respectively.

Business is not good. Winy finds that the drunks are very poor. Sometimes they have to leave because they cannot afford aa ml or bb ml of beer. Therefore, Winy decides to sell a third volume of beer (a smaller volume).

Winy has only two cups with capacities aa ml and bb ml, and the cups have no markings. He can only obtain new volumes by pouring between the two cups and the barrel.

To simplify the pouring steps, Winy stipulates:

  1. aba≥b.
  2. The barrel has infinite capacity, and the amount of beer in the barrel is also infinite (but much smaller than the barrel’s capacity).
  3. Only three pouring operations are allowed:
    1. Pour beer from the barrel into the cup of capacity bb ml.
    2. Pour the beer from the cup of capacity aa ml into the barrel.
    3. Pour the beer from the cup of capacity bb ml into the cup of capacity aa ml.
  4. Each pour must either fill the receiving cup to full or empty the source cup completely.

Winy hopes that after several pours, the remaining volume of beer in the aa ml cup is as small as possible. He asks you to help design a pouring plan.

Input Format

A single line with two integers aa and bb, satisfying 0<ba1090<b≤a≤10^9.

Output Format

The first line contains an integer cc, representing the minimal volume that can be obtained.

The second line contains two integers PaP_a and PbP_b (separated by a space), representing respectively the number of times pouring from the aa ml cup into the barrel and the number of times pouring into the bb ml cup from the barrel.

If multiple pairs Pa,PbP_a,P_b satisfy the requirement, output the one with the smallest PaP_a. If there are still multiple choices under the smallest PaP_a, output the one with the smallest PbP_b.

5 3

1
1 2

Hint

Sample explanation:

The pouring plan is:

  1. Barrel -> cup B.
  2. Cup B -> cup A.
  3. Barrel -> cup B.
  4. Cup B -> cup A.
  5. Cup A -> barrel.
  6. Cup B -> cup A.

Translated by ChatGPT 5