Easy, Double binary Search, straightforward solution
I liked this question, Used double binary search for first time !!!!\n\n\nclass Solution {\npublic:\n    int waysToSplit(vector<int>& nums) {\n        long n=nu
I liked this question, Used double binary search for first time !!!!\n\n```\nclass Solution {\npublic:\n    int waysToSplit(vector<int>& nums) {\n        long n=nums.size(), M=1000000007;\n        vector<long> pref(n);\n        pref[0]=nums[0];\n        \n        for(long i=1; i<n; ++i) pref[i]=pref[i-1]+nums[i];\n        \n        long res=0;\n        \n        for(long i=0; i<n-2; ++i){\n\t\t\t//lsum is sum of left segment\n            long lsum=pref[i];\n\t\t\t//mr is end point of middle segment\n            long mr= lower_bound(pref.begin(), pref.end(), 2*lsum)-pref.begin();\n            mr=max(mr, i+1);\n            if(mr>=n-1) continue;\n            \n\t\t\t//Binary search for possible values of mr such that Sum(mid)<=Sum(right)\n            long l=mr, r=n-2, ans=0;\n            while(l<=r){\n                long mid=(l+r)/2;\n                long Sm= pref[mid]-lsum;\n                long Sr= pref[n-1]-pref[mid];\n                \n                if(Sm<=Sr) { ans=max(ans, mid); l=mid+1; }\n                else r=mid-1;\n            }\n            // cout<<lsum<<" "<<mr<<" "<<ans<<endl;\n            if(ans>=mr) res+=ans-mr+1;\n            res%=M;\n        }\n        return res;\n    }\n};\n```\n\nCode is self explanatory, I guess.\nAnyways, You can always raise your doubts in comments.
['Binary Tree']