Evolution of molecules (2) X62507


Statement
 

pdf   zip

In an experiment with nn molecules of several integer weights, a curious phenomenon has been detected. Repeatedly, the two heaviest molecules are combined, they disappear, and generate a new molecule. If the heaviest molecule has weight xx, and the second heaviest has weight yy, there are two possibilities. If the last digit of xx and yy is the same, a fusion of type AA takes place and the new molecule will have weight xy/2x - \lfloor y/2 \rfloor. If their last digit is different, a fusion of type BB happens and the new molecule will have weight xy/4x - \lfloor y/4 \rfloor. The process finishes when only one molecule exists.

For example, if the initial weights are 21, 6, 3 and 20, first of all 21 and 20 are combined with a fusion of type BB and generate a molecule with weight 2120/4=215=1621 - \lfloor 20/4 \rfloor = 21 - 5 = 16. We now have 6, 3 and 16, and 16 and 6 are combined via a type AA fusion, generating 166/2=163=1316 - \lfloor 6/2 \rfloor = 16 - 3 = 13. We now have 3 and 13, that are combined with a fusion of type AA and generate 133/2=131=1213 - \lfloor 3/2 \rfloor = 13 - 1 = 12, that is the weight of the final molecule. In the overall process, two fusions of type AA and one fusion of type BB have occurred.

Write a program that efficiently simulates this process and writes the weight of the last molecule and the number of fusions of each type.

Input

The input consists of several cases. Each case begins with the number of molecules nn, followed by nn weights, which are integers between 1 and 10910^9. You can assume that 1n1051 \le n \le 10^5.

Output

For each case, write the weight of the last molecule, followed by the number of fusions of type AA and the number of fusions of type BB.

Observation

We advise you not to use multisets to solve this problem.

Public test cases
  • Input

    4  21 6 3 20
    2  1000000000 999999999
    1  42
    3  23 23 23
    5  5 4 1 2 3
    

    Output

    12 2 1
    750000001 0 1
    42 0 0
    20 1 1
    4 0 4
    
  • Information
    Author
    Language
    English
    Translator
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++