Clean binary search solution in C++
\n  int waysToSplit(vector<int>& nums) {\n    int ans = 0, m = 1e9+7, leftsum, totalsum;\n    vector<int> sums(nums.size()); // prefix sums\n    partial_sum(num
```\n  int waysToSplit(vector<int>& nums) {\n    int ans = 0, m = 1e9+7, leftsum, totalsum;\n    vector<int> sums(nums.size()); // prefix sums\n    partial_sum(nums.begin(), nums.end(), sums.begin());\n    totalsum = *sums.rbegin();\n    \n    // i: iterator to the last element of left\n    // j: iterator to the left-most last element of mid\n    // k: iterator to the right-most last element of mid\n    for (auto i = sums.begin(); i < sums.end() - 2; i++) {\n      leftsum = *i;\n      int midsum_max = (totalsum - leftsum) / 2;\n      if (leftsum > midsum_max) break;\n      auto j = lower_bound(i+1, sums.end()-1, 2*leftsum);\n      auto k = upper_bound(i+1, sums.end()-1, leftsum + midsum_max);\n      ans = (ans + k - j) % m;\n    }\n    return ans;\n  }\n  ```
['C', 'Binary Tree']