Short and simple
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 mod = 1e9+7;\n        int increase = 0;\n        int n = nums.size();\n        for(int i=1; i<nums.size();i++)\n        {\n            if(nums[i] - nums[i-1] > 0)\n                increase += nums[i]-nums[i-1];\n        }\n\n        int r = nums.back()-increase;\n        if (r < 0)\n            return 0;\n\n        long long fact[3001], inv[3001], invfact[3001];\n        fact[0] = fact[1] = 1;\n        inv[0] = inv[1] = 1;\n        invfact[0] = invfact[1] = 1;\n\n        for(int i=2; i<3001; i++)\n        {\n            fact[i] = (fact[i-1]*i) % mod;\n            inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;\n            invfact[i] = (invfact[i - 1] * inv[i]) % mod;\n        }\n\n        return int ((fact[n+r] * (invfact[r]*invfact[n]%mod))%mod);\n    }\n};\n```
['C++']