Python DP + suffix sum, O(N * MAX(nums))
Intuition\nOptimized from a more naive approach:\n\nIn this approach, DP[i][n][m] means how many subarrays there are that satisify arr1[i] + arr2[i] == nums[i] 
# Intuition\nOptimized from a more naive approach:\n\nIn this approach, DP[i][n][m] means how many subarrays there are that satisify arr1[i] + arr2[i] == nums[i] and arr1[i + 1] >= arr1[i] = n and arr2[i + 1] <= arr2[i] = m\n```\n    def countOfPairs1(self, nums: List[int]) -> int:\n        if not nums: return 0\n        max_nums = max(nums)\n        dp = [[0 for _ in range(max_nums + 1)] for _ in range(max_nums + 1)]\n\n        for i in range(len(nums) - 1, -1, -1):\n            new_dp = [[0 for _ in range(max_nums + 1)] for _ in range(max_nums + 1)]\n            for j in range(nums[i], -1, -1):\n                if i == len(nums) - 1:\n                    new_dp[j][nums[i] - j] += 1\n                    continue\n                # nums[i + 1] - sub_j <= nums[i] - j\n                for sub_j in range(max(j, nums[i + 1] - nums[i] + j), nums[i + 1] + 1):\n                    new_dp[j][nums[i] - j] += dp[sub_j][nums[i + 1] - sub_j]\n            dp = new_dp\n\n        total = 0\n        for j in range(nums[0] + 1):\n            total += dp[j][nums[0] - j]\n        return total % (10 ** 9 + 7)\n```\n\n# Code\n```python3 []\nclass Solution:\n    def countOfPairs(self, nums: List[int]) -> int:\n        if not nums: return 0\n        max_nums = max(nums)\n        dp = [0 for _ in range(max_nums + 1)]\n\n        for i in range(len(nums) - 1, -1, -1):\n            new_dp = [0 for _ in range(max_nums + 1)]\n            suffix_sum = [0] * (max_nums + 2)\n            if i + 1 < len(nums):\n                for j in range(nums[i + 1], -1, -1):\n                    suffix_sum[j] = dp[j] + suffix_sum[j + 1]\n\n            for j in range(nums[i], -1, -1):\n                if i == len(nums) - 1:\n                    new_dp[j] += 1\n                    continue\n                new_dp[j] += suffix_sum[max(j, nums[i + 1] - nums[i] + j)]\n            dp = new_dp\n\n        total = 0\n        for j in range(nums[0] + 1):\n            total += dp[j]\n        return total % (10 ** 9 + 7)\n```
['Python3']