#include<iostream>
#include<vector>
#include<sstream>
using namespace std;
void dfs(const vector<int>& arr, int root, vector<int>& res)
{
int left = 2*root + 1;
int right = 2*root + 2;
if(arr.size() > left)
{
dfs(arr, left, res);
if(arr.size() > right)
{
dfs(arr, right, res);
}
res.push_back(arr[root]);
}
}
string solveMethod(const vector<int>& arr)
{
if(arr.size() == 1)
{
return to_string(arr[0]);
}
vector<int> res;
dfs(arr, 0, res);
string ss = "";
for(size_t i = 0; i < res.size(); i++)
{
if(i > 0)
{
ss += " ";
}
ss += to_string(res[i]);
}
return ss;
}
int main()
{
string str;
getline(cin, str);
stringstream ss(str);
vector<int> arr;
int num;
while(ss >> num)
{
arr.push_back(num);
}
cout << solveMethod(arr) << endl;
return 0;
}