Problems > Closest to Zero

Closest to Zero

Difficulty: 1000 2000 ms 128 MB

implementation

Print the value closest to zero. If a negative and a positive value tie in distance, print the positive one.

Input: the first line has an integer N; the second line has N integers separated by spaces.

Output: the value closest to zero (positive wins ties).

Constraints:

  • 1 ≤ N ≤ 2000
  • −109 ≤ ai ≤ 109

Sample Tests

Input 1
5
7 -2 3 2 -5
Output 1
2
Input 2
2
-3 3
Output 2
3

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.