#C13292. Closest Number Finder

    ID: 42814 Type: Default 1000ms 256MiB

Closest Number Finder

Closest Number Finder

You are given a list of integers and a target integer. Your task is to find the number in the list that is closest to the target. In case two numbers are equally close, return the smaller number.

The distance between a number x and the target T is defined as \( |T - x| \) (i.e., the absolute difference). Formally, given an array \( A = [a_1, a_2, \ldots, a_n] \) and a target \( T \), you need to find \( a_k \) such that

[ |T - a_k| = \min_{1 \leq i \leq n} |T - a_i| ]

and if there is more than one such ( a_k ), choose the smallest one among them.

inputFormat

The input is read from stdin and consists of three parts:

  1. An integer \( n \) representing the number of elements in the list.
  2. A line containing \( n \) space-separated integers.
  3. An integer representing the target value.

outputFormat

Output a single integer to stdout, which is the number from the list closest to the target according to the problem specification.

## sample
4
4 1 10 -5
3
4