Static Huffman coding is an encoding algorithm used mainly for text compression. Given a text made of N different characters, the algorithm chooses N codes, one for each different character, and the text is compressed with those codes. To choose the codes, the algorithm builds a binary rooted tree having N leaves. For N≥2 the tree is built as follows.
At steps 3.1 and 3.2 the set s may contain several trees with minimum weight, so the text alone does not fix the shape of the tree. In the text abracadabra the character a occurs 5 times, b and r occur twice each, and c and d occur once each. One run of the algorithm gives code lengths 1, 2, 3, 4, 4 for a, b, r, c, d, and another run gives 1, 3, 3, 3, 3.
For each different character in the text, its code depends on the path that exists, in the final tree, from the root to the leaf corresponding to the character. The length of the code is the number of edges in that path, which is the same as the number of internal nodes in the path.
Given the lengths of the N codes chosen by the algorithm, find the minimum size (total number of characters) that the text can have so that the generated codes have those N lengths.
The first line contains an integer N, the number of different characters that appear in the text. (2≤N≤50)
The second line contains N integers Li, the lengths of the codes the algorithm chose for the different characters. (1≤Li≤50, i=1,2,…,N)
At least one tree built as described above produces codes with the given lengths.
Print one line with an integer, the minimum size (total number of characters) that the text can have so that the generated codes have the given lengths.