C++ Implementation using Binary Search + Prefix Sum+Handling one edge case of all zeros
\n\n# Code\n\nclass Solution {\npublic:\nconst int mod=1e9+7;\n    int waysToSplit(vector<int>& nums) {\n        long long cnt=count(nums.begin(),nums.end(),0);
\n\n# Code\n```\nclass Solution {\npublic:\nconst int mod=1e9+7;\n    int waysToSplit(vector<int>& nums) {\n        long long cnt=count(nums.begin(),nums.end(),0);\n        if(cnt==nums.size()){\n            return ((cnt-1)*(cnt-2)/2)%mod;\n        }\n        vector<long long>pref;\n        pref.push_back(nums[0]);\n        for(int i=1;i<nums.size();i++){\n            pref.push_back(pref.back()+nums[i]);\n\n        }\n        int ans=0;\n       auto check=[&](int mid,int i){\n            return pref[i]<=pref[mid]-pref[i] && pref[mid]-pref[i]<=pref[pref.size()-1]-pref[mid];\n        };\n        for(int i=0;i<nums.size();i++){\n            int j=lower_bound(pref.begin(),pref.end(),2*pref[i])-pref.begin();\n            int low=j;\n            int high=nums.size()-1;\n            int ind=j-1;\n            while(low<=high){\n                int mid=(low+high)/2;\n                if(check(mid,i)){\n                    ind=mid;\n                    low=mid+1;\n                }\n                else{\n                    high=mid-1;\n                }\n\n            }\n            \n            ans+=max((ind-max(i+1,j)+1),0);\n            ans%=mod;\n        }\n        return ans;\n    }\n};\n```
['Binary Search', 'Prefix Sum', 'C++']