#include<stdio.h>
#define N 2000000

int v,data[N+1];

void maxHeapify(int i)
{
  int l,r,large;
  int tmp;

  l = 2*i;
  r = 2*i+1;

  if(l<=v && data[l]>data[i])
    large = l;
  else
    large = i;

  if(r<=v && data[r]>data[large])
    large = r;

  if(large != i){
    tmp = data[i];
    data[i] = data[large];
    data[large] = tmp;

    maxHeapify(large);
  }
}

int main()
{
  int i;

  scanf("%d",&v);
  for(i=1; i<=v; i++)
    scanf("%d",&data[i]);

  for(i=v/2; i>=1; i--)
    maxHeapify(i);

  for(i=1; i<=v; i++)
    printf("%d",data[i]);

  printf("\n");

  return 0;
}
