Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/massiv-min-va-max-almashtirish

Swap the smallest and the largest

Easy 1000 ms 128 MB 32%
Share

A positive integer $n$ and an array of $n$ distinct integers are given. Swap the smallest and the largest elements of the array and print the array.

Swapping the smallest and the largest elements of an array

Input

The first line contains a positive integer $n$. The second line contains $n$ integers separated by spaces.

Output

One line with $n$ integers separated by spaces.

Note

$2 \le n \le 1000$
$-10^{9} \le a_{i} \le 10^{9}$
All numbers $a_{i}$ are distinct.

Examples

Input #1
5
15 3 42 99 27
Output #1
15 99 42 3 27
Input #2
3
10 50 30
Output #2
50 10 30

Sign in to submit a solution

Signing up is free and takes a minute.