void MergeSort(__int64* a,int first,int last,__int64* temp){
if (first < last){
int mid = (first + last)/2;
MergeSort(a,first,mid,temp);
MergeSort(a,mid+1,last,temp);
Merge(a,first,mid,last,temp);
}
}
void Merge(__int64* a,int first,int mid,int last,__int64* temp){
int i = first,j = mid + 1,k = 0;
int m = mid, n = last;
while (i <= m && j <= n){
if (a[i] <= a[j])
temp[k++] = a[i++];
else
temp[k++] = a[j++];
}
while (i <= m)
temp[k++] = a[i++];
while (j <= n)
temp[k++] = a[j++];
for (i = 0;i < k;i++)
a[first+i] = temp[i];
}