#include<stdio.h>

void mH(int A[],int i,int n){
  int l,r,temp,large;
  l=2*i;
  r=2*i+1;

  if(l<=n&&A[l]>A[i]) large=l;
  else large=i;
  if(r<=n&&A[r]>A[large]) large=r;

  if(large!=i){
    temp=A[i];
    A[i]=A[large];
    A[large]=temp;
    mH(A,large,n);
  }

  return;
}

void bMH(int A[],int H){
  int i;

  for(i=H/2;i>=1;i--)
    mH(A,i,H);

  return;
}

int main(){
  int n,i;
  int A[500001];
  for(i=1;i<500001;i++)
    A[i]=-2000000001;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);

  bMH(A,n);

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

  return 0;
}

