Simple DP
Approach\nSimple dynamics + accumulation\n\n# Complexity\n- Time complexity:\nO(\sum \text{nums}_i)\n\n- Space complexity:\nO(\max(\text{nums}_i))\n\n# Code\n\n
# Approach\nSimple dynamics + accumulation\n\n# Complexity\n- Time complexity:\n$$O(\\sum \\text{nums}_i)$$\n\n- Space complexity:\n$$O(\\max(\\text{nums}_i))$$\n\n# Code\n```\n#include <ranges>\n\nclass Solution {\npublic:\n    int countOfPairs(vector<int>& nums) {\n        const int M = 1e9 + 7;\n        for (int i = 0; i < nums.size(); ++i) ++nums[i];\n        int n = nums[0];\n        vector<int> cnt(n, 1);\n        for (int n2: ranges::drop_view{nums, 1}) {\n            vector<int> cnt2(n2, 0);\n            int acc = 0;\n            for (int i = 0, j = max(0, n2 - n); i < min(n, n2); ++i, ++j) {\n                cnt2[j] = acc = (acc + cnt[i]) % M;\n            }\n            n = n2;\n            cnt = move(cnt2);\n        }\n        int acc = 0;\n        for (int c: cnt) acc = (acc + c) % M;\n        return acc;\n    }\n};\n```
['C++']