#include<bits/stdc++.h>
using namespace std;
int a[1000001],b,c,d;
int main(){
cin>>b;
for(int i=1;i<=b;i++){
cin>>a[i];
if(a[i]==0){
c=i;//记录0所在的位置(变)
d=i;//记录0所在的位置(不变,跳过)
}
}
for(int i=1;i<=b;i++){
if(i==d){
continue;
}
a[c]=a[i];
c=i;
a[i]=0;
}
for(int i=1;i<=b;i++){
cout<<a[i]<<" ";
}
}