#K75632. Winning Card Finder

    ID: 34463 Type: Default 1000ms 256MiB

Winning Card Finder

Winning Card Finder

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

Mathematical formulation:
Find a card number \( c \) from the list \( C \) such that \[ |c - target| = \min_{x \in C} |x - target| \] and if there exists another card \( c' \) with the same absolute difference, choose \( c \) such that \( c \leq c' \).

The input is provided via standard input and the result must be printed to standard output.

inputFormat

The first line contains an integer representing the target number. The second line contains a space-separated list of integers representing the card numbers.

For example:

50
49 51 52 48 47

outputFormat

Output a single integer which is the winning card number according to the problem statement. The output should be printed on standard output.

For the above example, the correct output is:

49
## sample
50
49 51 52 48 47
49

</p>