#K59282. Move Zeros to End

    ID: 30830 Type: Default 1000ms 256MiB

Move Zeros to End

Move Zeros to End

Given an array of integers, your task is to move all the zeros to the end of the array while maintaining the relative order of the non-zero elements.

In other words, if the input array is \( a = [a_1, a_2, \dots, a_n] \), you need to rearrange it such that all non-zero elements retain their original order and all zeros are moved to the end. Formally, if \( b \) is the resulting array, then:

\[ \text{If } a_i \neq 0 \text{, then } b_j = a_i \text{ for some } j \text{ preserving the order, and all zeros in } a \text{ appear after all non-zeros in } b. \]

You are required to read the input from standard input and write the output to standard output.

inputFormat

The first line of input contains a single integer \( n \) which denotes the number of elements in the array. The second line contains \( n \) space-separated integers representing the array elements.

outputFormat

Print the modified array in a single line. The numbers should be space-separated and arranged such that all non-zero elements appear first (in their original order) followed by all zeros.

## sample
7
0 1 0 3 12 0 2
1 3 12 2 0 0 0