In an experiment with 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 , and the second heaviest has weight , there are two possibilities. If the last digit of and is the same, a fusion of type takes place and the new molecule will have weight . If their last digit is different, a fusion of type happens and the new molecule will have weight . 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 and generate a molecule with weight . We now have 6, 3 and 16, and 16 and 6 are combined via a type fusion, generating . We now have 3 and 13, that are combined with a fusion of type and generate , that is the weight of the final molecule. In the overall process, two fusions of type and one fusion of type 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.
The input consists of several cases. Each case begins with the number of molecules , followed by weights, which are integers between 1 and . You can assume that .
For each case, write the weight of the last molecule, followed by the number of fusions of type and the number of fusions of type .
We advise you not to use multisets to solve this problem.
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