Under construction

Still being built. Things may change

The Math of Sailing

Time limit1sMemory limit512 MB

Summary
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 t1t_1, t2t_2, t3t_3, and t4t_4. 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 a1a_1, the sizes of the middle mast sails be a2a_2 and a3a_3, and the size of the back mast sail be a4a_4. The maneuverability of the ship is a1a4+a2+a3a_1 a_4 + a_2 + a_3, and its stability is a1+a4+a2a3a_1 + a_4 + a_2 a_3.

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 t1,…,t4t_1, \ldots, t_4 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: a1a4+a2+a3=a1+a4+a2a3a_1 a_4 + a_2 + a_3 = a_1 + a_4 + a_2 a_3.

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 t1t_1, t2t_2, t3t_3, and t4t_4, the sizes of the fabric pieces Polycarp has (1≤ti≤1041 \le t_i \le 10^4).

Output

On the first line, print pp, a permutation of the integers from 1 to 4. The ii-th number should specify which piece of fabric was used to create the ii-th sail. For example, if the second sail was created by decreasing the size of the fourth piece of fabric, then p2=4p_2 = 4.

On the second line, print the resulting sail sizes a1a_1, a2a_2, a3a_3, and a4a_4, separated by spaces (1≤a1,a2,a3,a4≤1041 \le a_1, a_2, a_3, a_4 \le 10^4). 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 2⋅10−62 \cdot 10^{-6}, and the two values differ from each other by no more than 10−610^{-6}.

Examples3

  1. Example 1

    Input
    1 1 1 1
    
    Expected output
    1 2 3 4
    1.0 1.0 1.0 1.0
    
  2. Example 2

    Input
    7 5 3 5
    
    Expected output
    1 2 4 3
    7.0 4.0 5.0 3.0
    
  3. Example 3

    Input
    2 3 4 5
    
    Expected output
    1 2 3 4
    2.0 2.3333333333 4 5