#include<stdio.h>
#define max 200000;
int n,A[max+1],change;
void maxheapfiy(int i){
  int r,l,largest;
  l=2*i;
  r=2*i+1;
  if(l<=n && A[l]>A[i])largest=l;
  else largest =i;
  if(largest!=i){
    change = A[i];
    A[i]=A[largest];
    A[largest]= change;
    maxheapfiy(largest);
  }
}
    int main(){
      scaanf("%d",&n);
      for(i=1,i<=n;i++){
        scanf("%d",&A[i]);
      }
      for(i=n/2;i>=1;i--)maxheapfiy(i);
      for(i=1;i<=n;i++){
        printf(" %d",A[i]);
      }
      printf("\n");
      return 0;
    }

