The Gini coefficient is often used in economics to calculate inequality.
According to this website, the formula for calculating Gini coefficient is
$G = \frac{\sum_{i=1}^{n} \sum_{j=1}^{n} |x_i - x_j|}{2n^2\bar{x}}$
However, if all values are arranged in ascending order, computation is quicker:
$G = \frac{2}{n^2\bar{x}} \sum_{i=1}^{n}i(x_i-\bar{x})$
Why does the last formula work?
The first formula has no $i=j$ contributions and is a sum of $i\leftrightarrow j$-symmetric terms, so can be rewritten as $\frac{1}{n^2\bar{x}}\sum_{i>j}(x_i-x_j)$ if we adopt the convention $i>j\to x_i>x_j$. It suffices to prove $\sum_{i>j}(x_i-x_j)=2\sum_i (ix_i -i\bar{x})$. The term $x_i$ appears on the left-hand side $i-1-(n-i)=2i-1-n$ times, and on the right-hand side $2(i-\sum_i \frac{i}{n})=2i-\frac{2T_n}{n}$ times where $T_n:=\sum_{k=1}^n k=\frac{n(n+1)}{2}$ is the $n$th triangle number. You can verify these coefficients agree.