#BST0000006. Successor trong BST (Inorder Successor in a BST)

Successor trong BST (Inorder Successor in a BST)

Inorder Successor in a BST

Source: Phuoc Hung OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Build a BST from a1,a2,…,ana_1,a_2,\ldots,a_n in insertion order. Duplicate insertion keys are ignored.

A key xx is guaranteed to exist in the tree. The strict inorder successor of xx is the smallest stored key that is greater than xx.

Find this strict inorder successor. If no stored key is greater than xx, the successor does not exist.

Input

The first line contains nn.

The second line contains nn signed integers a1,a2,…,ana_1,a_2,\ldots,a_n in insertion order.

The third line contains xx.

Output

Print the successor key if it exists; otherwise print NONE.

Subtasks

Subtask 1 (20 points): 1≤n≤201\le n\le 20.

Subtask 2 (30 points): 1≤n≤50001\le n\le 5000.

Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000.

In all subtasks, aia_i and xx are signed 64-bit integers, duplicate insertion keys are ignored, and xx is guaranteed to belong to the resulting BST.

Examples

Input

7
8 3 10 1 6 14 4
6

Output

8

Explanation

The stored keys greater than 66 are 8,10,148,10,14. The smallest of them is 88, so the strict inorder successor of 66 is 88.