C++ || Binary Search
\nclass Solution {\npublic:\n    int waysToSplit(vector<int>& nums) {\n        int n=nums.size();\n        int M=1e9+7;\n        vector<long long>pre(n,0);\n   
```\nclass Solution {\npublic:\n    int waysToSplit(vector<int>& nums) {\n        int n=nums.size();\n        int M=1e9+7;\n        vector<long long>pre(n,0);\n        pre[0]=nums[0];\n        for(int i=1;i<n;i++){\n            pre[i]=pre[i-1]+nums[i];\n        }\n        long long ans=0;\n        for(int i=0;i<=n-3;i++){\n            long long leftSum=pre[i];\n            int l=i+1;\n            int r=n-2;\n            int p1=-1,p2=-1;\n            //finding end point of range i.e. p2\n            while(l<=r){\n                int m=l+(r-l)/2;\n                \n                long long midSum=pre[m]-leftSum;\n                long long rightSum=pre[n-1]-pre[m];\n                if(midSum<=rightSum)\n                    p2=m,l=m+1;\n                else\n                    r=m-1;\n            }\n            \n            //finding start point of range i.e. p1\n            l=i+1;\n            r=p2;\n            while(l<=r){\n                int m=l+(r-l)/2;\n                \n                long long midSum=pre[m]-leftSum;\n                if(leftSum<=midSum)\n                    p1=m,r=m-1;\n                else\n                    l=m+1;\n            }\n            \n            if(p1!=-1 && p2!=-1 && p1<=p2)\n                ans+=(p2-p1+1);\n            ans=ans%M;\n        }\n        return ans;\n        \n    }\n};\n\n// <---------------><-----------------><------------------->\n//    leftSum        p1                p2        rightSum\n```
[]