#C3133. Move Negatives to End

    ID: 46527 Type: Default 1000ms 256MiB

Move Negatives to End

Move Negatives to End

Given an array of integers, your task is to move all negative numbers to the end of the array while maintaining the relative order of non-negative numbers (i.e. positive numbers and zeros). The operation must preserve the original order among positive numbers and zeros, and also preserve the order of the negatives as they appear in the input.

Note: If the array is empty, simply output an empty line.

Input/Output Format:

  • The input is read from stdin. The first line contains an integer n, denoting the number of elements in the array. The second line contains n space-separated integers.
  • The output should be written to stdout. Output the modified array on a single line with elements separated by a space.

Example:

Input:
7
1 -2 3 -4 5 -6 7

Output: 1 3 5 7 -2 -4 -6

</p>

inputFormat

The input is provided via standard input (stdin) with the following format:

  • The first line contains a single integer n representing the number of elements in the array.
  • The second line contains n space-separated integers.

outputFormat

Output the rearranged array in a single line, where all non-negative numbers (positive numbers and zeros) are listed first, followed by the negative numbers. Each number should be separated by a single space.

## sample
7
1 -2 3 -4 5 -6 7
1 3 5 7 -2 -4 -6