#BST0000001. Đường tìm kiếm trong BST (BST Search Path)

Đường tìm kiếm trong BST (BST Search Path)

BST Search Path

Source: Phuoc Hung OJ

Version: Phuoc Hung OJ Extended

Problem Statement

A binary search tree (BST) is a binary tree in which, for every node with key vv, every key in its left subtree is smaller than vv and every key in its right subtree is greater than vv.

Initially the tree is empty. Insert a1,a2,…,ana_1,a_2,\ldots,a_n in the given order. To insert aia_i, start at the root: go to the left child if aia_i is smaller than the current key, and to the right child if it is larger. Create a new node when the required child is empty. If the key already exists, ignore that insertion and leave the tree unchanged.

After the tree is built, search for the query key xx. The search starts at the root and follows the same comparison rule. Print all keys of the visited nodes in order, from the root to the point where the search stops.

If a node with key xx is reached, the final status is FOUND. If the search reaches an empty branch without finding xx, the final status is NOT FOUND.

Input

The first line contains an integer nn — the number of keys used to build the tree.

If n>0n>0, the next line contains nn signed integers a1,a2,…,ana_1,a_2,\ldots,a_n in insertion order. If n=0n=0, this line is absent.

The last line contains the query key xx.

Output

If the tree is non-empty, print the visited keys separated by one space, followed by FOUND or NOT FOUND on the same line.

If the tree is empty, no node is visited; print only:

NOT FOUND

Subtasks

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

Subtask 2 (30 points): 0≤n≤50000\le n\le 5000.

Subtask 3 (50 points): 0≤n≤2000000\le n\le 200000.

In all subtasks, aia_i and xx are signed 64-bit integers, so −263≤ai,x≤263−1-2^{63}\le a_i,x\le 2^{63}-1. Duplicate insertion keys are ignored.

Examples

Input

7
8 3 10 1 6 14 4
6

Output

8 3 6 FOUND

Explanation

The first key 88 becomes the root. To search for x=6x=6, first visit 88. Since 6<86<8, move left to 33. Since 6>36>3, move right and reach 66.

The visited keys are 8,3,68,3,6, and the query key is found, so the final status is FOUND.