#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int arr[n];
for ( int i = 0 ; i < n ; i ++ )
{
cin >> arr[i];
}
int x = n - 1;
for ( int b = 0 ; b < n ; b ++ )
{
if ( arr[b] == 0 )
{
swap ( arr[b] , arr[x] );
x --;
}
}
for ( int i = 0 ; i < n ; i ++ )
{
cout << arr[i] <<" ";
}
return 0;
}