1Use `mid = left + (right - left) / 2` (integer division) to avoid integer overflow.
2Template for finding leftmost position: `while left < right`, move `right = mid` when condition is true.
3Template for finding rightmost position: move `left = mid + 1` when condition is false.
4Binary search on the answer: define the range [lo, hi] as the minimum and maximum possible answers, then binary search within it.