Intuition
Checking every pair is O(n²). Merge sort already compares the left half against the right half while sorting — piggyback on it. When both halves are sorted, for each left element the right-half values that violate the condition form a prefix, so a two-pointer sweep counts all cross pairs in linear time per level.
Approach
Divide
Split the array in half; count pairs entirely inside each half recursively. What's left is pairs that cross the middle.
Count cross pairs on sorted halves
With both halves sorted, walk a pointer j over the right half for each left i: advance j while nums[i] > 2*nums[j]. j never moves backward, so the count for the whole level is O(n).
Merge as usual
After counting, restore sorted order so the parent call sees a sorted range. The code delegates this to Python's sorted(): because the two halves are already sorted, Timsort detects the runs and merges them in linear time, so the level stays O(n) — an explicit two-pointer merge would be equivalent. Sorting doesn't lose pairs, since counting happened before the order changed across the boundary.
Solution & live demo
Edge cases
2*nums[j] handles signs fine; comparisons stay valid on sorted halves.
2× a large int needs 64 bits; Python is safe.