The Math of Sailing
Time limit1sMemory limit512 MB
Given four fabric sizes, assign and shrink them into sails a1..a4 so that a1*a4+a2+a3 = a1+a4+a2*a3 and the common value is maximized.
- Level
Medium6 of 10
- Topics
- Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
Captain Polycarp has dreamed of owning a three-masted sailing ship since childhood. At last his dream is about to come true: he has saved enough money and bought a beautiful caracca Pulcheria. However, he overlooked that the ship was sold without sails. Now he has to obtain the sails separately.
A caracca must have exactly four sails: one on the back mast, one on the front mast, and two on the middle mast. Coincidentally, Polycarp has exactly four pieces of fabric with sizes , , , and . He can use these pieces as sails in any order, making them smaller beforehand if needed.
Let the size of the front mast sail be , the sizes of the middle mast sails be and , and the size of the back mast sail be . The maneuverability of the ship is , and its stability is .
For the caracca to sail the sea safely, the captain must adjust the sails so that the maneuverability equals the stability. For maximum comfort, these two values should be as large as possible.
In short, Polycarp must decrease the values of if needed, then distribute the resulting sizes among the four sails in any order so that the following equality holds and both sides are as large as possible: .
Help him find a way to make the ship's maneuverability equal its stability while maximizing the two equal values.
Input
The first and only line contains four integers , , , and , the sizes of the fabric pieces Polycarp has ().
Output
On the first line, print , a permutation of the integers from 1 to 4. The -th number should specify which piece of fabric was used to create the -th sail. For example, if the second sail was created by decreasing the size of the fourth piece of fabric, then .
On the second line, print the resulting sail sizes , , , and , separated by spaces (). These values do not have to be integers.
The answer is accepted if the absolute errors of the resulting maneuverability and stability with respect to the correct answer do not exceed , and the two values differ from each other by no more than .