#K3846. Aggregate Array: Grouping Positive and Negative Numbers

    ID: 26203 Type: Default 1000ms 256MiB

Aggregate Array: Grouping Positive and Negative Numbers

Aggregate Array: Grouping Positive and Negative Numbers

Given an array of integers, rearrange the elements so that all positive numbers (i.e., numbers strictly greater than 0) appear before all negative numbers (i.e., numbers strictly less than 0), while preserving the relative order among the positive numbers and among the negative numbers. Any occurrences of 0 should be ignored and omitted from the output.

More formally, let \(A = [a_1, a_2, \dots, a_n]\) be the input array. Produce an array \(B\) such that \[ B = [a_i \mid a_i > 0] \; \| \; [a_j \mid a_j < 0], \] where \(\|\) denotes concatenation, and the order of elements in each subarray is the same as in the original array.

Read the input from standard input (stdin) and output the rearranged array to standard output (stdout) as a sequence of integers separated by a single space.

inputFormat

The first line of input contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\).

If \(n=0\), the array is empty.

outputFormat

Output a single line containing the aggregated array. The positive numbers should appear first in their original order, followed by the negative numbers in their original order. Numbers should be separated by a single space. If there are no numbers to output, print an empty line.

## sample
8
3 -2 2 -1 -7 10 1 -3
3 2 10 1 -2 -1 -7 -3