Modified Counting Inversions problem using divide and conquer Given an array $A$, find the number of pairs $(i, j)$, such that $ i &gt; j$ and $A[i] \ge A[j]$.


This is a modified version of the famous problem of Counting Inversions, only in this version it allows the elements to be equal as well. I have an algorithm for the classical counting inversions problem implemented, so i´d like to know if it can be adapted to solve this version. Thanks ahead.

Link to the algorithm (written in C++):

https://repl.it/@MateusBuarque/CountingInversion
Hint:


   Can you count the number of pairs $(i,j)$ such that $A[i]=A[j]$?