#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> arr;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
if (x != 0)
arr.push_back(x);
}
int res = n - arr.size();
for (int i = 0; i < res; i++)
arr.push_back(0);
for (int i = 0; i < n; i++)
{
cout << arr[i] << " ";
}
return 0;
}