#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[10]={0,},i;
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=9;i>=0;i--)
{
//printf("=1=\n");
int child = i;
do{
//printf("=2=\n");
int parent = (child-1)/2;
if(a[parent]<a[child])
swap(a[parent],a[child]);
child = parent;
}while(child != 0);
}
for(i=0;i<10;i++)
printf("= %d ",a[i]);
int k=9;
while(k!=0)
{
printf("==k= %d\n",k);
if(a[0] <= a[k]) break;
swap(a[0],a[k--]);
int parent=0;
int child;
do{
//printf("=2=\n");
int child1 = parent*2+1;
int child2 = parent*2+2;
child = child1;
if(child <= k-1 && a[child2]>a[child1])
child = child2;
if(child <= k-1 && a[parent]<a[child])
swap(a[parent],a[child]);
parent = child;
}while(parent<=k);
for(i=0;i<10;i++)
printf("%d ",a[i]);
printf("\n");
}
for(i=0;i<10;i++)
printf("%d ",a[i]);
return 0;
}