Easy Prefix Sum and iterative dp solution
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 {\npublic:\n    int countOfPairs(vector<int>& nums) {\n        int n = nums.size();\n        vector<vector<long long> > dp(n, vector<long long> (1001, 0));\n        vector<vector<long long> > pref(n, vector<long long> (1001, 0));\n\n        pref[0][0] = 1;\n        for(int i = 0; i <= 1000; i++) dp[0][i] = 1;\n        for(int i = 1; i <= 1000; i++) pref[0][i] = pref[0][i-1] + dp[0][i];\n\n        for(int i = 1; i < n; i++){\n            for(int j = 0; j <= nums[i]; j++){\n                if(nums[i-1]-nums[i]+j < 0) continue;\n                dp[i][j] += pref[i-1][min(j, nums[i-1]-nums[i]+j)];\n                dp[i][j] %= 1000000007;\n            }\n            pref[i][0] = dp[i][0];\n            for(int j = 1; j <= 1000; j++) pref[i][j] = pref[i][j-1] + dp[i][j];\n        }\n\n        long long ans = 0;\n        for(int i = 0; i <= nums[n-1]; i++) ans += dp[n-1][i], ans %= 1000000007;\n\n        return ans;\n\n\n    }\n};\n```
['C++']