#C9543. Closest Element Finder
Closest Element Finder
Closest Element Finder
Given an array of integers and a target integer x, find the element in the array that is closest to x in terms of absolute difference. If there are several elements with the same absolute difference, return the smallest one.
The absolute difference is defined as \(|a - x|\), where \(a\) is an element of the array.
Your program should read from stdin and write the result to stdout.
inputFormat
The first line contains an integer n, the number of elements in the array.
The second line contains n space-separated integers, representing the array elements.
The third line contains an integer x, the target number.
outputFormat
Output a single integer: the element in the array that is closest to x. If there are multiple such elements, output the smallest one.
## sample6
10 22 28 29 30 40
54
40