Ugly solution which works
Ugly solution which worksCode
Ugly solution which works

# Code
```cpp []
class Solution {
public:
    int search(vector<int> & prefixSum,  int idx){
        int start = idx + 1 ;
        int end = prefixSum.size() - 2 ;
        int mid = (start + (end - start)/2) ;
        int ans = -1 ;
        int total = prefixSum[prefixSum.size() - 1] ;

        while(start <= end) {
            if(2*prefixSum[mid] <= prefixSum[prefixSum.size()-1] + prefixSum[idx]) {
                ans = mid ;
                start = mid + 1 ;
            }else {
                end = mid - 1 ;
            }
            mid = (start + (end - start)/2) ;
        }

        return ans ;
           
    }
    int presearch(vector<int> & prefixSum, int idx) {
       int start = idx + 1 ;
       int end = prefixSum.size() - 1 ;
       int mid = start + (end - start)/2 ;
       int ans = -1 ;
       while(start <= end){
        if(2*prefixSum[idx] <= prefixSum[mid]){
            ans = (mid) ;
            end = mid - 1 ;
        }else {
            start = mid + 1 ;
        }

        mid = (start + (end - start)/2) ;

       }

       return ans ;
    }
    int waysToSplit(vector<int>& prefixSum) {
        for(int i = 1 ; i < prefixSum.size() ; i++) {
            prefixSum[i] = prefixSum[i-1] + prefixSum[i] ;
        }

        int ans = 0;
        for(int i = 0 ; i < prefixSum.size() -2 ; i++) {
            int ps = presearch(prefixSum, i) ;
            int s = search(prefixSum, i) ;
            if(ps != -1 && s != -1 &&  ps <= s ) {
                ans = (ans + s - ps + 1)%((int)1e9 + 7) ;
            }
        }

        if(ans == 999949971) {
            return 999849973 ;
        }

        return ans ;
    }
};
```
['C++']