Question
The Librarian's Empty Shelf Slots

A librarian is organizing a single shelf that holds n slots in a row. Each slot either holds a book (represented by its non-zero catalog ID) or is empty (represented by 0).

Rearrange the shelf in-place so that every empty slot moves to the end, while every book keeps its original relative order among the other books.

You must do this using only constant extra space.

Input

The first line contains a single integer KaTeX can only parse string typed expression — the number of slots.

The second line contains KaTeX can only parse string typed expression integers (this line may be empty if KaTeX can only parse string typed expression).

Output

Print the rearranged shelf as KaTeX can only parse string typed expression space-separated integers.

Example
Example 1:
Input
5

0 1 0 3 12
Output
1 3 12 0 0
Explanation
The books with catalog IDs 1, 3, and 12 keep their original relative order, and both empty slots move to the end.

Example 2:
Input
4

0 0 0 0
Output
0 0 0 0
Explanation
The entire shelf is already empty, so it stays unchanged.

Online