void swap(int* a,int i,int j){
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
void head(int* a,int current,int n){
if(current>=n) return;
int left = 2*current;
int right = left+1;
int max_index;
if(left>=n) return;
if(right>=n) max_index=left;
else max_index = (a[left]>a[right])?left:right;
if(a[current]<a[max_index]) {
swap(a[current],a[max_index]);
heap(a,max_index,n);
}
}
void sortheap(int *a,int n){
for(int i=N/2;i>=0;i--)
heap(a,i,n);
for(int i=n-1;i>=0;i--){
heap(a,0,i);
swap(a,0,i);
}
}