Sum of nodes in a subtree#10433

Sum of nodes in a subtree

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 nodes in the specified subtree.

Input

The first line contains numbers n~(1 \le n \le 1000) and v~(0 \le v \le 10000). The second line contains integers.

Output

Create the Binary Search Tree from input data. Print the sum of all nodes in the subtree with root in . If vertex is not present in the tree, print .

Examples

The sum of nodes in the subtree with root equals 4 + 5 + 7 = 16.

Example 1

Loading
Loading