PROGRAMMING:Constructing Huffman tree ordered input
Construct a Huffman tree and output its middle order sequence.
The word frequency is given from small to large (no more than 10), and the Huffman tree is constructed according to the word frequency.
In order to ensure the uniqueness of the constructed Huffman tree, this paper makes the following restrictions:
(1) When selecting the two binary trees with the minimum weight of the root node, the one with the smaller weight is selected as the left subtree.
(2) If the weights of root nodes of multiple binary trees are equal, they are divided into left and right according to the order. The first one is the left subtree, and the second one is the right subtree.
###Input format:
Input the number of word frequency in the first line;
On the second line, enter each word frequency in descending order
###Output format:
Output middle sequence, separated by a space
###Input example:
```in
three
1 1 2
```
###Output example:
```out
2 4 1 2 1
```
answer:If there is no answer, please comment
The word frequency is given from small to large (no more than 10), and the Huffman tree is constructed according to the word frequency.
In order to ensure the uniqueness of the constructed Huffman tree, this paper makes the following restrictions:
(1) When selecting the two binary trees with the minimum weight of the root node, the one with the smaller weight is selected as the left subtree.
(2) If the weights of root nodes of multiple binary trees are equal, they are divided into left and right according to the order. The first one is the left subtree, and the second one is the right subtree.
###Input format:
Input the number of word frequency in the first line;
On the second line, enter each word frequency in descending order
###Output format:
Output middle sequence, separated by a space
###Input example:
```in
three
1 1 2
```
###Output example:
```out
2 4 1 2 1
```
answer:If there is no answer, please comment