beecrowd | 1498
# Inverting Huffman

**Timelimit: 1**

By Leopoldo Taravilse Argentina

Static Huffman coding is an encoding algorithm used mainly for text compression. Given a text of certain size made of *N* different characters, the algorithm chooses *N* codes, one for each different character. The text is compressed using these codes. To choose the codes, the algorithm builds a binary rooted tree having *N* leaves. For *N* ≥ 2 the tree can be built as follows.

1. For each different character in the text build a tree containing just a single node, and assign to it a weight coincident with the number of occurrences of the character within the text.

2. Build a set s containing the above *N* trees.

3. While s contains more than one tree:

(a) Choose *t _{1}* ∈

(b) Choose

(c) Build a new tree

(d) Include

4. Return the only tree that remains in

For the text “

Your task is, given the lengths of the

The input contains many test cases and ends with EOF. The first line of each test case contains an integer **N** (2 ≤ **N** ≤ 50) representing the number of different characters that appear in the text. The second line contains **N** integers **L _{i}** indicating the lengths of the codes chosen by Huffman algorithm for the different characters (1 ≤

For each test case, print a line with an integer representing the minimum size (total number of characters) that the text can have so as the generated codes have the given lengths.

Exemplo de Entrada | Exemplo de Saída |

2 |
2 |