#K12371. Duplicate Zeros

    ID: 23676 Type: Default 1000ms 256MiB

Duplicate Zeros

Duplicate Zeros

Given an array of integers, duplicate each occurrence of zero, shifting the remaining elements to the right. Note that elements beyond the length of the original array are not written, meaning the array's size remains unchanged. This operation should be performed as if done in-place.

Example: If the input array is [1, 0, 2, 3, 0, 4, 5, 0], after duplicating zeros the resulting array will be [1, 0, 0, 2, 3, 0, 0, 4].

Note: Even though a zero is duplicated, if the duplicated zero would exceed the original array length it is not inserted.

inputFormat

The first line of input contains an integer n (n ≥ 0), representing the number of elements in the array. The second line contains n space-separated integers defining the array.

outputFormat

Output the modified array in one line, with elements separated by a single space. If the array is empty, output nothing.

## sample
8
1 0 2 3 0 4 5 0
1 0 0 2 3 0 0 4