Easy C++ || 1D DP || PrefixSum
\nclass Solution {\n    const int mod=1e9+7;\n    public:\n    int countOfPairs(vector<int>& nums) {\n        int n=nums.size();\n        vector<long long> pres
```\nclass Solution {\n    const int mod=1e9+7;\n    public:\n    int countOfPairs(vector<int>& nums) {\n        int n=nums.size();\n        vector<long long> presum;\n        for(int i=0;i<=nums.back();i++){\n            presum.push_back((1+(i>0 ? presum.back() : 0))%mod);\n        }\n        int min_=nums.back();\n        for(int i=n-2;i>=0;i--){\n            vector<long long> pre; //long long sum=0;\n            min_=min(min_,nums[i]);\n            for(int j=0;j<=min_;j++){\n                int k=max(j,nums[i+1]-(nums[i]-j));\n                if(k>=presum.size()) break;\n                long long currentSum = (presum.back() - (k > 0 ? presum[k-1] : 0) + mod) % mod;\n                pre.push_back((currentSum+(j>0 ? pre.back() : 0))%mod);\n            }\n            presum=pre;\n        }\n        return presum.size() ? presum.back()%mod : 0;\n    }\n};\n```
['Dynamic Programming', 'C', 'Prefix Sum']