calculate number of reverse pair