[Javascript] O(n) with three pointers, easy to understand code
\nvar waysToSplit = function (A) {\n  const N = A.length;\n  const mod = 1e9 + 7;\n  const pre = [...A];\n  for (let i = 1; i < N; i++) pre[i] += pre[i - 1];\n 
```\nvar waysToSplit = function (A) {\n  const N = A.length;\n  const mod = 1e9 + 7;\n  const pre = [...A];\n  for (let i = 1; i < N; i++) pre[i] += pre[i - 1];\n  let res = 0;\n  // j is the smallest ending idx of mid arr j > i, j < N - 1\n  // k is the largest ending idx of mid arr k >= j, k < N - 1\n  for (let i = 0, j = 1, k = 1; i < N - 2; i++) {\n    j = Math.max(j, i + 1);\n    k = Math.max(k, j);\n    const left = pre[i];\n    if (left > pre[N - 1] / 3) break;\n\n    // while left > mid, we need to increase j\n    while (left > pre[j] - pre[i] && j < N - 1) j++;\n    if (j >= N - 1) break;\n\n    /// while mid <= right, we still have room to increase k\n    while (pre[k] - pre[i] <= pre[N - 1] - pre[k] && k < N - 1) k++;\n    k--; // Shift back one position\n    if (k < j || k >= N - 1) continue;\n\n    res += (k - j + 1) % mod;\n  }\n  return res % mod;\n};\n```
['Two Pointers', 'JavaScript']