module mdl contains recursive subroutine qsort(a,s,t) integer*8::a(:),i,j,s,t,m if(t-s<=1)return i=s j=t-1 m=a((s+t)/2) do do while(a(i)m) j=j-1 end do if(i>=j)exit a(i)=xor(a(i),a(j)) a(j)=xor(a(i),a(j)) a(i)=xor(a(i),a(j)) i=i+1 j=j-1 end do call qsort(a,s,i) call qsort(a,j+1,t) end subroutine function calc(c,trg) integer*8::calc,c(:),trg calc=0 do i=1,size(c) calc=calc+abs(c(i)-trg) end do end function end module program main use mdl implicit none integer*8::b,n,tot=0,i,j,k,s,t,ans integer*8,allocatable::c(:) read*,b read*,n allocate(c(n)) do i=1,n read*,c(i) end do call qsort(c,int(1,8),int(size(c),8)) print*,calc(c,c((n+1)/2)) end program