Stores the count of swaps
long int swaps = 0 ; int i = left , j = mid , k = left ; while ( i < mid && j <= right ) { if ( A [ i ] <= A [ j ] ) { temp [ k ] = A [ i ] ; k ++ , i ++ ; } else { temp [ k ] = A [ j ] ; k ++ , j ++ ; swaps += mid - i ; } } while ( i < mid ) { temp [ k ] = A [ i ] ; k ++ , i ++ ; } while ( j <= right ) { temp [ k ] = A [ j ] ; k ++ , j ++ ; } while ( left <= right ) { A [ left ] = temp [ left ] ; left ++ ; } return swaps ; }