Sum of leaves#10432

Sum of leaves

1 second
128 megabytes
Very easy

Given an array of integers. Create a Binary Search Tree from these numbers. If the number is already in the tree, do not insert it (no duplicates).

Find the sum of all leaves in a tree.

Input

The first line contains number n~(1 \le n \le 1000). The second line contains integers.

Output

Create the Binary Search Tree from input data. Print the sum of all leaves in a tree.

Examples

The sum of leaves equals to 1 + 5 + 11 = 17.

Example 1

Loading
Loading