All problems

Problem 22

Minimum and Maximum

Easy · 10 pts · Array

Problem

You are given an array of N integers. Print its smallest element and its largest element, in that order, separated by a space. A single pass is enough: start with the first element as both the current minimum and the current maximum, then update them while scanning the rest. If the array has one element, it is both the minimum and the maximum.

Input

First line: integer N. Second line: N space-separated integers.

Output

Print the minimum and the maximum separated by a space.

Constraints

1 <= N <= 100000; -1000000000 <= A[i] <= 1000000000

Example input

4
3 1 9 4

Example output

1 9

Explanation

The array is 3 1 9 4. The smallest value is 1 and the largest is 9, so the output is 1 9.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Sum of Array Next: Rotate Array Right