[C++] Simple C++ Code
\n# If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.\n\nclass Solution {\n    i
\n# **If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.**\n```\nclass Solution {\n    int binarysearch(int i, int j, vector<int> &prfsm, int w1)\n    {\n        int r = -1, n = prfsm.size();\n        while(i <= j)\n        {\n            int mid = i + (j-i)/2;\n            if(mid == n-1)\n                break;\n            if(prfsm[n-1]-prfsm[mid] >= prfsm[mid] - prfsm[w1])\n            {\n                r = mid;\n                i = mid+1;\n            }\n            else\n            {\n                j = mid-1;\n            }\n        }\n        return r;\n    }\npublic:\n    int waysToSplit(vector<int>& nums) {\n        vector<int> prefixsm;\n        int sum = 0, mod = 1e9 + 7, ans = 0, n = nums.size();\n        for(int &num : nums)\n        {\n            sum += num;\n            prefixsm.push_back(sum);\n        }\n        for(int i = 0; i < n-2; i++)\n        {\n            int fst = prefixsm[i];\n            auto snditr = lower_bound(prefixsm.begin(), prefixsm.end(), 2*fst);\n            if(snditr == prefixsm.end())\n                return ans;\n            int snd = snditr-prefixsm.begin();\n            if(snd <= i)\n                snd = i + 1;\n            int trd = binarysearch(snd, n-1, prefixsm, i);\n            if(trd == -1)\n                continue;\n            ans = (ans % mod + (trd-snd+1)%mod)%mod;\n        }\n        return ans;\n    }\n};\n```
['Binary Search', 'Binary Tree', 'Prefix Sum']