A reserve fund stores its distinct positive deposit 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). Process the stored amounts in ascending order, keeping a running total. Report the smallest amount x at which the running total (of every stored amount <= x) first reaches or exceeds a threshold T.
Input format
Line 1: an integer n, the number of deposits.
Line 2: n space-separated distinct positive integers, the deposits in insertion order.
Line 3: an integer T.
Output format
A single integer: the smallest deposit x at which the ascending running total first becomes >= T. If the total of all deposits is still < T, print NONE.
Constraints
- 1 <= n <= 40
- 1 <= T <= 100000000
- All deposits are distinct positive integers, each <= 1000000.