def _merge(arr, temp, left, mid, right):
 i = k = left
 j = mid
 inv_count = 0
 while ((i < mid) and (j <= right)):
  if (arr[i] < arr[j]):
   temp[k] = arr[i]
   k += 1
   i += 1
  else:
   temp[k] = arr[j]
   k += 1
   j += 1
   inv_count += (mid - i)
 while (i < mid):
  temp[k] = arr[i]
  k += 1
  i += 1
 if (j <= right):
  k += ((right - j) + 1)
  j += ((right - j) + 1)
  arr[left:(k + 1)] = temp[left:(k + 1)]
 else:
  arr[left:(right + 1)] = temp[left:(right + 1)]
 return inv_count

def _merge ( arr , temp , left , mid , right ) : i = k = left j = mid inv_count = 0 while ( ( i < mid ) and ( j <= right ) ) : if ( arr [ i ] < arr [ j ] ) : temp [ k ] = arr [ i ] k += 1 i += 1 else : temp [ k ] = arr [ j ] k += 1 j += 1 inv_count += ( mid - i ) while ( i < mid ) : temp [ k ] = arr [ i ] k += 1 i += 1 if ( j <= right ) : k += ( ( right - j ) + 1 ) j += ( ( right - j ) + 1 ) arr [ left : ( k + 1 ) ] = temp [ left : ( k + 1 ) ] else : arr [ left : ( right + 1 ) ] = temp [ left : ( right + 1 ) ] return inv_count
merges two sorted arrays and calculates the inversion count .