A charity keeps its distinct donation amounts in a binary search tree. Starting from an empty tree, the amounts are inserted one at a time in the order given (standard BST insertion: go left when the new amount is smaller than the current node, otherwise go right). Given an inclusive range [lo, hi], report the sum of every stored amount x with lo <= x <= hi.
Input format
Line 1: an integer n, the number of donations.
Line 2: n space-separated distinct integers, the amounts in insertion order.
Line 3: two space-separated integers lo and hi with lo <= hi.
Output format
A single integer: the sum of all stored amounts within [lo, hi] (0 if none qualify).
Constraints
- 1 <= n <= 40
- All amounts are distinct, each with absolute value <= 1000000.
- -2000000 <= lo <= hi <= 2000000