Python DP
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:O(n *m)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n*m)\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        MOD = 10**9+7\n        n = len(nums)\n        m = 1000\n        #dp solution. Focusing on arr1, for each num in nums, checking all m+1 possible values.\n        dp = [[0]*(m+1) for _ in range(n)]\n        for j in range(nums[0]+1):\n            dp[0][j] = 1\n\n        #loop each num one by one\n        for i in range(1,n):\n            #check all possible values for arr1\n            pre_sum = 0\n            p = 0\n            for j in range(nums[i]+1):\n                # problem II\n                # #constraints:\n                # #1. each valid arr1[i] should be larger or equal than prior(arr1[i-1]): p<=j\n                # #2. each valid arr2[i] should be less or equal than prior(arr2[i-1]): nums[i-1]-p<=nums[i]-j -> p<= j-(nums[i]-nums[i-1])\n                # thus p<=min(j, j-(nums[i]-nums[i-1])\n                if p <= min(j, j-(nums[i]-nums[i-1])):\n                    pre_sum = (pre_sum + dp[i-1][p])%MOD\n                    p += 1\n                dp[i][j] = dp[i][j]+pre_sum\n\n        return sum(dp[-1])%MOD\n```
['Python3']