public static void quick_sort(int[] q,int l,int r){
if(l>=r) return;
int x=q[l],i=l-1,j=r+1;
while(i<j){
do i++; while(q[i]<x);
do j--; while(q[j]>x);
if(i<j){
int tmp=q[i];
q[i]=q[j];
q[j]=tmp;
}
}
quick_sort(q,l,j);
quick_sort(q,j+1,r);
}
int quick_sort(int l,int r,int k){
if(l==r) return q[l];
int x=q[l],i=l-1,j=r+1;
while(i<j){
while(q[++i]<x);
while(q[--j]>x);
if(i<j) swap(q[i],q[j]);
}
int sl=j-l+1;
if(k<=sl) return quick_sort(l,j,k);
return quick_sort(j+1,r,k-sl);
}
void merge_sort(int q[],int l,int r){
if(l>=r) return;
int mid=(l+r)>>1;
merge_sort(q,l,mid),merge_sort(q,mid+1,r);
int k=0,i=l,j=mid+1;
while(i<=mid&&j<=r){
if(q[i]<=q[j]) tmp[k++]=q[i++];
else tmp[k++]=q[j++];
}
while(i<=mid) tmp[k++]=q[i++];
while(j<=r) tmp[k++]=q[j++];
for(int i=l,j=0;i<=r;i++,j++){
q[i]=tmp[j];
}
}
long long merge_sort(int q[],int l,int r){
if(l==r) return 0;
int mid = l + r>>1;
long long res=merge_sort(q,l,mid)+merge_sort(q,mid+1,r);
int k=0,i=l,j=mid+1;
while(i<=mid&&j<=r){
if(q[i]<=q[j]) tmp[k++] = q[i++];
else{
tmp[k++]=q[j++];
res+=mid-i+1;
}
}
while(i<=mid) tmp[k++]=q[i++];
while(j<=r) tmp[k++]=q[j++];
for(int i=l,j=0;i<=r;i++,j++){
q[i]=tmp[j];
}
return res;
}
int bsearch_1(int l,int r){
while(l<r){
int mid=l+r+1>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
}
int bsearch_2(int l,int r){
while(l<r){
int mid=l+r>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
}