import java.util.Scanner;
public class Main{
public static void move0(int[] a) {
int start = 0;//标记当前为零的数组下标
int end = 0;//用于交换之后找到的第一个零元素的下标
int cur = 0;//保存当前数组元素值,用于交换数组非零元素与零元素
int i = 0;
//找到数组中第一个零元素位置
while (i < a.length) {
cur = a[i];
if (a[i] == 0) {
start = i;
break;
}
}
i = start + 1;
end = start + 1;
while (i < a.length) {
cur = a[i];
if (a[i] != 0) {
a[start] = cur;
a[i] = 0;
//找出start之后第一个零元素位置
while (a[end] != 0) {
end++;
}
//更新start和end
start = end;
end = end + 1;
}
i++;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = in.nextInt();
}
move0(a);
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}
public class Main{
public static void move0(int[] a) {
int start = 0;//标记当前为零的数组下标
int end = 0;//用于交换之后找到的第一个零元素的下标
int cur = 0;//保存当前数组元素值,用于交换数组非零元素与零元素
int i = 0;
//找到数组中第一个零元素位置
while (i < a.length) {
cur = a[i];
if (a[i] == 0) {
start = i;
break;
}
}
i = start + 1;
end = start + 1;
while (i < a.length) {
cur = a[i];
if (a[i] != 0) {
a[start] = cur;
a[i] = 0;
//找出start之后第一个零元素位置
while (a[end] != 0) {
end++;
}
//更新start和end
start = end;
end = end + 1;
}
i++;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = in.nextInt();
}
move0(a);
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}