A warehouse assigns distinct integer bin labels. Starting from an empty binary search tree, insert the labels in the order given, using the standard BST rule: to insert a key x, walk down from the root, going left if x is smaller than the current node and right if x is larger, until an empty spot is reached, where a new node is created. No rebalancing is performed.
For each of q arriving packages, you are given its target label t. The package must be stored in the ceiling bin: the smallest existing bin label that is greater than or equal to t. If no such bin exists, report -1 for that query.
Input format
Line 1: an integer n.
Line 2: n space-separated distinct integers — the bin labels, in insertion order.
Line 3: an integer q.
Line 4: q space-separated integers t_1 ... t_q — the query targets.
Output format
q lines. Line i contains the ceiling of t_i, or -1 if no bin label is greater than or equal to t_i.
Constraints
- 1 ≤ n ≤ 40
- -1000 ≤ each bin label ≤ 1000, all labels distinct
- 1 ≤ q ≤ 40
- -2000 ≤ t_i ≤ 2000