Java Solution
Code\n\nclass Solution {\n\n    int MOD = 1_000_000_007;\n\n    public int countOfPairs(int[] nums) {\n        int n = nums.length;\n\n        long[] dp = new l
# Code\n```\nclass Solution {\n\n    int MOD = 1_000_000_007;\n\n    public int countOfPairs(int[] nums) {\n        int n = nums.length;\n\n        long[] dp = new long[1001];\n        for (int i = 0; i <= nums[0]; i++) {\n            dp[i]++;\n        }\n\n\n        for (int i = 1; i < n; i++) {\n            int p = Math.max(0, nums[i] - nums[i - 1]);\n            for (int j = 1; j <= 1000; j++) {\n                dp[j] += dp[j - 1];\n                dp[j] %= MOD;\n            }\n            for (int j = 1000; j >= p; j--) {\n                dp[j] = dp[j - p];\n            }\n            for (int j = p - 1; j >= 0; j--) {\n                dp[j] = 0;\n            }\n            for (int j = nums[i] + 1; j <= 1000; j++) {\n                dp[j] = 0;\n            }\n        }\n\n        long ans = 0;\n        for (long v : dp)\n            ans += v;\n        return (int) (ans % MOD);\n    }\n}\n```
['Java']