Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/massiv-nollarni-oxiriga

Zeros to the end

Easy 1000 ms 64 MB 31%
Share

An array of $n$ integers is given. Move all zeros to the end of the array; the relative order of the non-zero elements must not change. Print the resulting array.

The array: non-zero elements move to the left, zeros gather at the right end

Input

The first line contains a positive integer $n$.
The second line contains $n$ integers — the elements of the array.

Output

$n$ integers separated by spaces.

Note

$1 \le n \le 1000$
the elements are from $-10^{6}$ to $10^{6}$

Examples

Input #1
7
0 3 0 -1 5 0 2
Output #1
3 -1 5 2 0 0 0
Input #2
3
0 0 0
Output #2
0 0 0

Sign in to submit a solution

Signing up is free and takes a minute.