1D dp with prefix sum [the most optimized solution ever!]
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def countOfPairs(self, nums: List[int]) -> int:\n        dp = [0] * 1001\n        prefix_sum = [0] * 1001\n        mod = 10 ** 9 + 7\n        for j in range(nums[0]+1):\n            dp[j] += 1\n            prefix_sum[j] = prefix_sum[j-1] + dp[j]\n        for i in range(1, len(nums)):\n            new_prefix_sum = [0] * 1001\n            curr_num = nums[i]\n            dp = [0] * 1001\n            for j in range(curr_num+1):\n                dp[j] += prefix_sum[min(j, nums[i-1]-(curr_num-j))] % mod\n                new_prefix_sum[j] = new_prefix_sum[j-1] + dp[j]\n            prefix_sum = new_prefix_sum\n        return sum(dp) % mod\n```
['Python3']