Javascript Combinatorics 445ms
\nfunction Combinatorics(N, mod) {\n    let fact = Array(N), ifact = Array(N), inv = Array(N);\n    comb_init();\n    return { comb }\n    function comb_init() 
```\nfunction Combinatorics(N, mod) {\n    let fact = Array(N), ifact = Array(N), inv = Array(N);\n    comb_init();\n    return { comb }\n    function comb_init() {\n        fact[0] = ifact[0] = inv[1] = 1n;\n        for (let i = 2; i < N; i++) inv[i] = (mod - mod / ll(i)) * inv[mod % ll(i)] % mod;\n        for (let i = 1; i < N; i++) {\n            fact[i] = fact[i - 1] * ll(i) % mod;\n            ifact[i] = ifact[i - 1] * inv[i] % mod;\n        }\n    }\n    function comb(n, k) {\n        if (n < k || k < 0) return 0n;\n        return fact[n] * ifact[k] % mod * ifact[n - k] % mod;\n    }\n}\n\nconst ll = BigInt, mod = 1e9 + 7, bmod = ll(1e9 + 7)\nfunction countOfPairs(a) {\n    let C = new Combinatorics(3005, bmod), n = a.length;\n    let x = 0, y = a[0], A = [x], B = [y];\n    for (let i = 1; i < n; i++) {\n        x = Math.max(x, a[i] - y)\n        y = a[i] - x;\n        A.push(x);\n        B.push(y);\n    }\n    let minB = Math.min(...B);\n    return C.comb(minB + B.length, B.length);\n};\n```
['Dynamic Programming', 'Combinatorics', 'JavaScript']