C++ O(n) time and O(1) space
\nclass Solution {\npublic:\n    int waysToSplit(vector<int>& nums) {\n        int s = 0;\n        for (int x : nums) {\n            s += x;\n        }\n       
```\nclass Solution {\npublic:\n    int waysToSplit(vector<int>& nums) {\n        int s = 0;\n        for (int x : nums) {\n            s += x;\n        }\n        const int n = nums.size();\n        long long r  = 0;\n        for (int i = 0, s1 = 0, s2 = 0, s3 = s, num2 = 0, num3 = n; i < n; ++i) {\n            s1 += nums[i];\n            for (; num2 < n && (num2 <= i + 1 || s2 - s1 < s1); s2 += nums[num2++])\n            ;\n            if (num2 <= i + 1 || s2 - s1 < s1) break;\n            for (; num3 > 1 && s - s1 - s3 + nums[n - num3] <= s3 - nums[n - num3]; s3 -= nums[n - num3--])\n            ;\n            if (num3 >= n - i - 1) break;\n            // x >= num2 - 1\n            // x  <= n - num3 - 2\n            r += max(n - num3 - num2 + 1, 0);\n        }\n        return r % 1000000007;\n    }\n};\n```
[]