Function to merge two partitions such that the merged array is sorted
def merge ( v , left , mid , right , inversions ) : NEW_LINE INDENT temp = [ 0 for i in range ( right - left + 1 ) ] NEW_LINE i = left NEW_LINE j = mid + 1 NEW_LINE k = 0 NEW_LINE cnt = 0 NEW_LINE while ( i <= mid and j <= right ) : NEW_LINE INDENT if ( v [ i ] <= v [ j ] ) : NEW_LINE INDENT temp [ k ] = v [ i ] NEW_LINE k += 1 NEW_LINE i += 1 NEW_LINE DEDENT else : NEW_LINE DEDENT DEDENT