Write a program that finds the element in an array that is closest in value to a given number.
Input:
- the first line contains one natural number N
, not exceeding 1000 – array size;
- the second line contains N
numbers – array elements (integers not exceeding 1000 in modulus);
- the third line contains one integer x
, modulo not exceeding 1000.
Output: print the value of the array element closest to x
. If there are several such numbers, print any of them.
Examples
# |
Input |
Output |
1 |
5
1 2 3 4 5
6
|
5 |
2 |
5
5 4 3 2 1
3
|
3 |