    scanf("%d",&key[i]);
  }

  buildMaxHeap(H,key);

  for(i=0;i<H;i++) printf(" %d",key[i]);
  printf("\n");

  free(key);
			       

  return 0;
}


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

  l=2*(i+1)-1;
  r=2*(i+1);

  if(l<=H && key[l]>key[i]){
    large=l;
  } 
  else large=i;

  if(r<=H && key[r]>key[large]){
    large=r;
  } 
  if(large!=i){
    tmp=key[i];
    key[i]=key[large];
    key[large]=tmp;
    maxHeapify(large,H,key);
  }
}

void buildMaxHeap(int H,int *key){
  int i;

  for(i=H/2-1;i>=0;i--){
    maxHeapify(i,H,key);
  }
}