#P333. 练56.2 查找最接近的元素

练56.2 查找最接近的元素

Description

In a non-decreasing sequence, find the element closest to a given value.

Input Format

The first line contains an integer nn, representing the length of the non-decreasing sequence. 1n1000001≤n≤100000.
The second line contains nn integers, representing the elements of the non-decreasing sequence. All elements are between 00 and 1,000,000,0001,000,000,000.
The third line contains an integer mm, representing the number of queries. 1m100001≤m≤10000.
The next mm lines each contain an integer, representing the given value for which the closest element is to be found. All given values are between 00 and 1,000,000,0001,000,000,000.

Output Format

mm lines, each containing an integer representing the element closest to the corresponding given value, maintaining the input order. If multiple values satisfy the condition, output the smallest one.

Sample

3
2 5 8
2
10
5
8
5