Submit Test

Markdown Preview

Add a Code Snippet

Play with array (100 Marks)

You will be given an array and you need to find the largest and second largest number and print them respectively and rest of the numbers of the array will be printed after those two numbers with same sequence as given in the array.

Note: The length of the array should not be less than 2.

Input Format

You will be taking a number as an input stdin which tells about the length of the array. On another line, array elements should be there with single space between them.

Constraints

2 <= L <= 1000

1 <= Ai <= 1000

Output Format

You need to print the largest element first followed by the second largest element and then other elements in the same sequence as given in the array(while displaying the elements should be in single line and separated by single space).

Sample TestCase 1

Input

7
29 79 17 8 4 9 97

Output

97 79 29 17 8 4 9

Explanation

Within the given array, 97 and 79 are the largest and second largest element while others preserving their orders.