You are given a 0-indexed integer array nums. A pair of indices (i, j) is a bad pair if i &lt; j and j - i != nums[j] - nums[i].

Return the total number of bad pairs in nums.

&nbsp;
Example 1:

Input: nums = [4,1,3,3]
Output: 5
Explanation: The pair (0, 1) is a bad pair since 1 - 0 != 1 - 4.
The pair (0, 2) is a bad pair since 2 - 0 != 3 - 4, 2 != -1.
The pair (0, 3) is a bad pair since 3 - 0 != 3 - 4, 3 != -1.
The pair (1, 2) is a bad pair since 2 - 1 != 3 - 1, 1 != 2.
The pair (2, 3) is a bad pair since 3 - 2 != 3 - 3, 1 != 0.
There are a total of 5 bad pairs, so we return 5.


Example 2:

Input: nums = [1,2,3,4,5]
Output: 0
Explanation: There are no bad pairs.


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 105
	1 &lt;= nums[i] &lt;= 109


class Solution:
    def countBadPairs(self, nums: List[int]) -> int:
        nums_len = len(nums)
        count_dict = dict()
        for i in range(nums_len):
            nums[i] -= i
            if nums[i] not in count_dict:
                count_dict[nums[i]] = 0
            count_dict[nums[i]] += 1
        
        count = 0
        for key in count_dict:
            count += math.comb(count_dict[key], 2)
        return math.comb(nums_len, 2) - count
class Solution {
    public long countBadPairs(int[] nums) {
        HashMap<Integer, Integer> seen = new HashMap<>();
        long count = 0;
        for(int i = 0; i < nums.length; i++){
            int diff = i - nums[i];
            if(seen.containsKey(diff)){
                count += (i - seen.get(diff));
            }else{
                count += i;
            }
            seen.put(diff, seen.getOrDefault(diff, 0) + 1);
        }
        return count;
    }
}
class Solution {
public:
    long long countBadPairs(vector<int>& nums) {
        
        //j - i != nums[j] - nums[i] means  nums[i]-i != nums[j]-j
        map<long long,long long >mp;
        for(int i=0;i<nums.size();i++)
        {
            nums[i] = nums[i]-i;
            
            mp[nums[i]]++;
        }
        long long  n = nums.size();
        long long totalPair = n*(n-1)/2;
        
        for(auto& it:mp)
        {
            if(it.second>1)
            {
                totalPair -= (it.second)*(it.second-1)/2;
            } 
        }
        
        
        
        return totalPair;
    }
};
/**
 * @param {number[]} nums
 * @return {number}
 */
var countBadPairs = function(nums) {
    let map={},goodPair=0;
    for(let i=0;i<nums.length;i++){
        let value = nums[i]-i;
        if(map[value]!==undefined){
            goodPair += map[value];
            map[value]++;
        }else{
            map[value]=1;
        }
    }
    let n =  nums.length; 
    let totalPairs = n*(n-1)/2;
    return totalPairs-goodPair;
};
Count Number of Bad Pairs