Tommy has a binary tree rooted at
units of cost are incurred; and are swapped.
Find the minimum units of cost necessary to disassemble the binary tree.
Constraints
Test | |
---|---|
1 - 3 | |
4 - 7 | |
8 - 11 | |
12 - 16 | |
17 - 25 |
Input Specification
The first line contains a positive integer
The second line contains
The third line contains
Output Specification
Output the answer.
Sample Input 1
Copy
3
2 1 3
1 1
Sample Output 1
Copy
7
Comments