#include <stdio.h>

#define N 500000

int main(){
  int i,n,a[N],temp,flag, count, childLarge;
  scanf("%d",&n);
  for(i = 1; i <= n; i++ ){
    scanf("%d",&a[i]);
  }

  count = 1;
  while(count>0){
    count = 0;
    for(i = n/2; i > 0; i--){
      if(a[i*2+1]>a[i*2]){
        childLarge = i*2+1;
      }else{
        childLarge = i*2;
      }

      if(a[i]<a[childLarge]){
        temp = a[i];
        a[i] = a[childLarge];
        a[childLarge] = temp;
        count++;
      }
    }
  }

    for(i = 1; i <= n; i++ ){
      printf(" %d",a[i]);
    }
    printf("\n");

  return 0;
}