Positive and negative - MarisaOJ: Marisa Online Judge

Positive and negative

Time limit: 1000 ms
Memory limit: 256 MB
Given an array $A$ with $n$ integer elements, arrange the array by interleaving the negative and positive elements. The relative order of elements with the same sign should not be changed. ### Input - The first line contains an integer $n$. - The second line contains $n$ integers $A_i$. ### Output - Print the array $A$ after rearranging the elements in an interleaved manner. ### Constraints - $1 \le n \le 1000$. - $-1000 \le A_i \le 1000$. - $A_i \neq 0$. ### Example Input: ``` 6 1 5 -3 6 2 -5 ``` Output: ``` -3 1 -5 5 6 2 ``` In this example, the elements are arranged by interleaving negative and positive elements. When there are no more negative elements, continue using the remaining positive elements.