Solved inversions problem