A boarding gate assigns distinct integer tokens and stores them in a binary search tree. Starting from an empty tree, the tokens are inserted one at a time in the order given (standard BST insertion: go left when the new token is smaller than the current node, otherwise go right). Given a target key (which may or may not be one of the stored tokens), report its in-order successor: the smallest stored token that is strictly greater than key.
Input format
Line 1: an integer n, the number of tokens.
Line 2: n space-separated distinct integers, the tokens in insertion order.
Line 3: an integer key.
Output format
A single integer: the smallest stored token strictly greater than key. If no stored token is strictly greater than key, print NONE.
Constraints
- 1 <= n <= 40
- All tokens are distinct, each with absolute value <= 1000000.
- -2000000 <= key <= 2000000