P1292 Pouring Beer

Description

Winy is the owner of a bar. His bar offers two volumes of beer, $a$ ml and $b$ ml, served in cups with capacities $a$ ml and $b$ ml respectively. Business is not good. Winy finds that the drunks are very poor. Sometimes they have to leave because they cannot afford $a$ ml or $b$ ml of beer. Therefore, Winy decides to sell a third volume of beer (a smaller volume). Winy has only two cups with capacities $a$ ml and $b$ 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. $a≥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 $b$ ml. 2. Pour the beer from the cup of capacity $a$ ml into the barrel. 3. Pour the beer from the cup of capacity $b$ ml into the cup of capacity $a$ 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 $a$ ml cup is as small as possible. He asks you to help design a pouring plan.

Input Format

A single line with two integers $a$ and $b$, satisfying $0

Output Format

The first line contains an integer $c$, representing the minimal volume that can be obtained. The second line contains two integers $P_a$ and $P_b$ (separated by a space), representing respectively the number of times pouring from the $a$ ml cup into the barrel and the number of times pouring into the $b$ ml cup from the barrel. If multiple pairs $P_a,P_b$ satisfy the requirement, output the one with the smallest $P_a$. If there are still multiple choices under the smallest $P_a$, output the one with the smallest $P_b$.

Explanation/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