#include <iostream>
#include <vector>
#include <limits.h>
void fixup(std::vector<int> &h){
int j, k, v, n;
bool heap;
n = h.size() - 1;
for(int i = n/2; i >= 1; i--){
k = i;
v = h[k];
heap = false;
while(!heap && 2*k <= n){
j = 2*k;
if(j < n)
if(h[j] < h[j + 1])
j++;
if(v >= h[j])
heap = true;
else{
h[k] = h[j];
k = j;
}
}
h[k] = v;
}
}
int main(){
int size = 7;
int in;
std::vector<int> v(size);
v[0] = INT_MAX;
for(int i = 1; i <= size; i++){
std::cin >> v[i];
}
for(int i = 1; i < size; i++){
std::cout << v[i] << " ";
}
fixup(v);
std::cout << std::endl;
for(int i = 1; i < size; i++){
std::cout << v[i] << " ";
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bGltaXRzLmg+Cgp2b2lkIGZpeHVwKHN0ZDo6dmVjdG9yPGludD4gJmgpewoJaW50IGosIGssIHYsIG47Cglib29sIGhlYXA7CgoJbiA9IGguc2l6ZSgpIC0gMTsKCWZvcihpbnQgaSA9IG4vMjsgaSA+PSAxOyBpLS0pewoJCWsgPSBpOwoJCXYgPSBoW2tdOwoJCWhlYXAgPSBmYWxzZTsKCQl3aGlsZSghaGVhcCAmJiAyKmsgPD0gbil7CgkJCWogPSAyKms7CgkJCWlmKGogPCBuKQoJCQkJaWYoaFtqXSA8IGhbaiArIDFdKQoJCQkJCWorKzsKCQkJaWYodiA+PSBoW2pdKQoJCQkJaGVhcCA9IHRydWU7CgkJCWVsc2V7CgkJCQloW2tdID0gaFtqXTsKCQkJCWsgPSBqOwoJCQl9CgkJfQoJCWhba10gPSB2OwoJfQp9CgppbnQgbWFpbigpewoJaW50IHNpemUgPSA3OwoJaW50IGluOwoJc3RkOjp2ZWN0b3I8aW50PiB2KHNpemUpOwoJCgl2WzBdID0gSU5UX01BWDsKCWZvcihpbnQgaSA9IDE7IGkgPD0gc2l6ZTsgaSsrKXsKCQlzdGQ6OmNpbiA+PiB2W2ldOwoJfQoKCWZvcihpbnQgaSA9IDE7IGkgPCBzaXplOyBpKyspewoJCXN0ZDo6Y291dCA8PCB2W2ldIDw8ICIgIjsKCX0KCQoJZml4dXAodik7CgkKCXN0ZDo6Y291dCA8PCBzdGQ6OmVuZGw7Cglmb3IoaW50IGkgPSAxOyBpIDwgc2l6ZTsgaSsrKXsKCQlzdGQ6OmNvdXQgPDwgdltpXSA8PCAiICI7Cgl9Cn0=