An inversion in an array is a pair of elements `(arr[i], arr[j])` such that `i < j` and `arr[i] > arr[j]`. Write a Python function `count_inversions` that takes a list of integers as input and returns the number of inversions in the array.
#### Example Usage
```python [main.nopy]
print(count_inversions([1, 20, 6, 4, 5])) # Output: 5
print(count_inversions([1, 2, 1])) # Output: 1
print(count_inversions([1, 2, 5, 6, 1])) # Output: 3
```
#### Constraints
- The input list will contain integers.
- The list can be empty, in which case the function should return `0`.