Triplets with a sum in a range
Counting sums between L and R directly is awkward, but counting sums below a limit is the smaller-sum problem. So count the triplets with a sum below R + 1 (at most R) and take away those with a sum below L: what's left lies in L..R.