[Java] prefix sum + binary search for left/right cutpoint
\nclass Solution {\n    public int waysToSplit(int[] A) {\n        long res=0;\n        int mod=1000000007;\n        int sum=0;\n        int pre[]=new int[A.len
```\nclass Solution {\n    public int waysToSplit(int[] A) {\n        long res=0;\n        int mod=1000000007;\n        int sum=0;\n        int pre[]=new int[A.length];\n        \n        for(int i=0;i<A.length;i++){\n            sum+=A[i];\n            pre[i]=sum;\n        }\n        \n        \n        for(int i=0;i<A.length;i++){\n            int left=pre[i];\n            int l=i+1,r=A.length-2;//ensure the right have at least 1 element\n            int leftbound=-1;\n            int rightbound=-1;\n            while(l<=r){\n                int m=l+(r-l)/2;\n                int mid=pre[m]-left;\n                if(mid>=left){\n                    leftbound=m;\n                    r=m-1;\n                }\n                else{\n                    l=m+1;\n                }\n            }\n            \n            l=i+1;r=A.length-2;\n            while(l<=r){\n                int m=l+(r-l)/2;\n                int mid=pre[m]-left;\n                int right=sum-mid-left;\n                if(right>=mid){\n                    rightbound=m;\n                    l=m+1;\n                }\n                else{\n                    r=m-1;\n                }\n            }\n\t\t\t\n            if(rightbound==-1||leftbound==-1||leftbound>rightbound)continue;\n            int dif=rightbound-leftbound+1;//as we have the bound, we can cut at anyplace within this bound\n            res+=dif;\n            res%=mod;\n            \n        }\n        return (int)(res);\n    }\n}\n```
[]