Fractification
InterviewTime limit2sMemory limit512 MB
Given four positive integers, arrange them into two fractions a/b + c/d so the sum is as small as possible, and print the arrangement.
- Level
Medium4 of 10
- Topics
- Greedy, Sorting, Math, Brute force
- Solved
- No attempts yet
Problem
Little children love to break their toys so much! Little Andrew is no exception: he breaks everything he sees into fragments. This time he is about to break a set of four positive integers.
Let the fractification of four integers (, , , ) be the sum Little Andrew doesn't like anything larger than himself, so he wants the fractification to be as small as possible.
Help Andrew make the fractification of the given four integers as small as possible. You may swap these integers with each other in any way you want.
Input
The first and only line of input contains four positive integers , , , separated by spaces ().
Output
Print four integers that are a permutation of the given four such that their fractification is as small as possible. If more than one such permutation exists, print any of them.
Notes
In the first example, the output permutation gives which is minimal.
In the second example, the only possible output gives